false]); App::setLocale('ko'); DB::table('boards_report_logs')->delete(); DB::table('boards_reports')->delete(); DB::table('users')->where('is_super', false)->delete(); $this->admin = User::factory()->create(); $viewPermission = Permission::firstOrCreate( ['identifier' => 'sirsoft-board.reports.view'], ['name' => ['ko' => '신고 조회', 'en' => 'View Reports'], 'type' => 'admin'] ); $managePermission = Permission::firstOrCreate( ['identifier' => 'sirsoft-board.reports.manage'], ['name' => ['ko' => '신고 관리', 'en' => 'Manage Reports'], 'type' => 'admin'] ); $adminRole = Role::where('identifier', 'admin')->first(); $adminRole->permissions()->syncWithoutDetaching([$viewPermission->id, $managePermission->id]); $this->admin->roles()->attach($adminRole->id); $this->board = Board::updateOrCreate( ['slug' => 'report-request-validation-board'], [ 'name' => ['ko' => '신고 검증 테스트 게시판', 'en' => 'Report Validation Test Board'], 'slug' => 'report-request-validation-board', 'type' => 'list', 'per_page' => 20, 'per_page_mobile' => 10, 'order_by' => 'created_at', 'order_direction' => 'DESC', 'secret_mode' => 'disabled', 'use_comment' => true, 'use_reply' => false, 'use_file_upload' => false, 'use_report' => true, 'blocked_keywords' => [], 'notify_admin_on_post' => false, 'notify_author_on_comment' => false, ] ); DB::table('boards_report_logs')->delete(); DB::table('boards_reports')->delete(); } /** * status-counts 요청에 ids 가 비어 있으면 422 로 거부됨을 검증합니다. * (기존 컨트롤러 인라인 empty($ids) 검사 → StatusCountsRequest 이관) */ public function test_status_counts_with_empty_ids_is_rejected_with_422(): void { $response = $this->actingAs($this->admin) ->postJson('/api/modules/sirsoft-board/admin/reports/status-counts', [ 'ids' => [], ]); $response->assertStatus(422); } /** * status-counts 요청에 ids 키 자체가 없어도 422 로 거부됨을 검증합니다. */ public function test_status_counts_without_ids_is_rejected_with_422(): void { $response = $this->actingAs($this->admin) ->postJson('/api/modules/sirsoft-board/admin/reports/status-counts', []); $response->assertStatus(422); } /** * status-counts 요청의 target_status 가 허용되지 않은 값이면 422 로 거부됨을 검증합니다. */ public function test_status_counts_with_invalid_target_status_is_rejected_with_422(): void { $report = Report::factory()->create([ 'board_id' => $this->board->id, 'status' => ReportStatus::Pending, ]); $response = $this->actingAs($this->admin) ->postJson('/api/modules/sirsoft-board/admin/reports/status-counts', [ 'ids' => [$report->id], 'target_status' => 'not-a-real-status', ]); $response->assertStatus(422); } /** * 유효한 ids 로 status-counts 를 요청하면 200 으로 상태별 집계가 반환됨을 검증합니다. * (전용 FormRequest 전환이 정상 경로를 깨지 않음) */ public function test_status_counts_with_valid_ids_succeeds(): void { $report = Report::factory()->create([ 'board_id' => $this->board->id, 'status' => ReportStatus::Pending, ]); $response = $this->actingAs($this->admin) ->postJson('/api/modules/sirsoft-board/admin/reports/status-counts', [ 'ids' => [$report->id], 'target_status' => 'review', ]); $response->assertStatus(200) ->assertJson(['success' => true]); } /** * 전용 FormRequest 전환 후에도 신고 목록 조회(index)가 정상 200 임을 검증합니다. */ public function test_index_still_succeeds_after_request_refactor(): void { Report::factory()->create([ 'board_id' => $this->board->id, 'status' => ReportStatus::Pending, ]); $response = $this->actingAs($this->admin) ->getJson('/api/modules/sirsoft-board/admin/reports'); $response->assertStatus(200) ->assertJson(['success' => true]); } /** * 전용 FormRequest 전환 후에도 신고자 목록 조회(reporters)가 정상 200 임을 검증합니다. */ public function test_reporters_still_succeeds_after_request_refactor(): void { $report = Report::factory()->create([ 'board_id' => $this->board->id, 'status' => ReportStatus::Pending, ]); $response = $this->actingAs($this->admin) ->getJson("/api/modules/sirsoft-board/admin/reports/{$report->id}/reporters"); $response->assertStatus(200) ->assertJson(['success' => true]); } /** * 신고자 목록의 per_page 가 상·하한 밖 값을 거부하는지 검증합니다. * * 상한이 없으면 한 요청으로 신고자 전량을 끌어올 수 있어 페이지네이션이 무의미해진다. */ public function test_reporters_per_page_is_bounded(): void { $report = Report::factory()->create([ 'board_id' => $this->board->id, 'status' => ReportStatus::Pending, ]); $url = "/api/modules/sirsoft-board/admin/reports/{$report->id}/reporters"; foreach ([0, -3, 101, 100000] as $perPage) { $this->actingAs($this->admin) ->getJson("{$url}?per_page={$perPage}") ->assertStatus(422); } // 경계 안쪽 값은 그대로 통과해야 한다 foreach ([1, 100] as $perPage) { $this->actingAs($this->admin) ->getJson("{$url}?per_page={$perPage}") ->assertStatus(200); } } }