seedCompetitionData(); Sanctum::actingAs($this->createAdministrator()); $response = $this->getJson('/api/v1/competition-winners'); $response->assertOk(); $response->assertJson([ 'ok' => true, 'competitions' => [ [ 'id' => 1, 'title' => 'Competition One', 'class_section_id' => null, 'is_locked' => false, 'is_published' => false, ], ], ]); $this->assertSame('1-A', $response->json('sectionMap.101')); } public function test_lock_and_unlock_toggle_competition(): void { $this->seedCompetitionData(); Sanctum::actingAs($this->createAdministrator()); $this->postJson('/api/v1/competition-winners/1/lock') ->assertOk() ->assertJson(['ok' => true]); $this->assertDatabaseHas('competitions', [ 'id' => 1, 'is_locked' => 1, ]); $this->postJson('/api/v1/competition-winners/1/unlock') ->assertOk() ->assertJson(['ok' => true]); $this->assertDatabaseHas('competitions', [ 'id' => 1, 'is_locked' => 0, ]); } public function test_export_quiz_creates_quiz_rows(): void { $this->seedCompetitionData(); Sanctum::actingAs($this->createAdministrator()); $response = $this->postJson('/api/v1/competition-winners/1/export-quiz', [ 'class_section_id' => 101, ]); $response->assertOk(); $response->assertJson([ 'ok' => true, 'message' => 'Exported.', ]); $this->assertDatabaseHas('quiz', [ 'student_id' => 1, 'class_section_id' => 101, 'semester' => 'Fall', 'school_year' => '2025-2026', 'score' => 50.0, ]); } private function seedCompetitionData(): void { DB::table('configuration')->updateOrInsert( ['config_key' => 'school_year'], ['config_value' => '2025-2026'] ); DB::table('configuration')->updateOrInsert( ['config_key' => 'semester'], ['config_value' => 'Fall'] ); DB::table('classSection')->insert([ 'id' => 1, 'class_id' => 1, 'class_section_id' => 101, 'class_section_name' => '1-A', 'semester' => 'Fall', 'school_year' => '2025-2026', ]); DB::table('students')->insert([ 'id' => 1, 'school_id' => 'S-1', 'firstname' => 'Student', 'lastname' => 'One', 'age' => 8, 'gender' => 'Male', 'photo_consent' => 1, 'parent_id' => 1, 'year_of_registration' => '2025', 'school_year' => '2025-2026', 'semester' => 'Fall', 'is_active' => 1, ]); DB::table('student_class')->insert([ 'student_id' => 1, 'class_section_id' => 101, 'semester' => 'Fall', 'school_year' => '2025-2026', ]); DB::table('competitions')->insert([ 'id' => 1, 'title' => 'Competition One', 'semester' => 'Fall', 'school_year' => '2025-2026', 'class_section_id' => null, 'is_locked' => 0, 'is_published' => 0, ]); DB::table('competition_class_winners')->insert([ 'competition_id' => 1, 'class_section_id' => 101, 'question_count' => 20, ]); DB::table('competition_scores')->insert([ 'competition_id' => 1, 'student_id' => 1, 'class_section_id' => 101, 'score' => 10, ]); } private function createAdministrator(): User { DB::table('users')->insert([ 'id' => 1, 'school_id' => 777, 'firstname' => 'Admin', 'lastname' => 'User', 'cellphone' => '5555555555', 'email' => 'admin@example.com', 'address_street' => '123 Main', 'city' => 'City', 'state' => 'ST', 'zip' => '12345', 'accept_school_policy' => 1, 'is_verified' => 1, 'status' => 'Active', 'is_suspended' => 0, 'failed_attempts' => 0, 'password' => bcrypt('secret'), 'semester' => 'Fall', 'school_year' => '2025-2026', ]); DB::table('roles')->insert([ 'id' => 1, 'name' => 'administrator', 'slug' => 'administrator', 'dashboard_route' => 'administrator/administratordashboard', 'priority' => 1, 'is_active' => 1, ]); DB::table('user_roles')->insert([ 'user_id' => 1, 'role_id' => 1, ]); return User::query()->findOrFail(1); } }