seedPrepData(); $user = $this->createUser(); Sanctum::actingAs($user); $response = $this->getJson('/api/v1/class-prep?school_year=2025-2026&semester=Fall'); $response->assertOk(); $response->assertJson([ 'status' => true, 'message' => 'Success', 'data' => [ 'schoolYear' => '2025-2026', 'semester' => 'Fall', ], ]); $this->assertNotEmpty($response->json('data.results')); } public function test_mark_printed_creates_snapshots(): void { $this->seedPrepData(); $user = $this->createUser(); Sanctum::actingAs($user); $response = $this->postJson('/api/v1/class-prep/mark-printed', [ 'school_year' => '2025-2026', 'semester' => 'Fall', 'class_section_ids' => ['101'], ]); $response->assertOk(); $response->assertJson([ 'status' => true, ]); $this->assertDatabaseHas('class_preparation_log', [ 'class_section_id' => 101, 'school_year' => '2025-2026', ]); } public function test_mark_printed_rejects_invalid_payload(): void { $user = $this->createUser(); Sanctum::actingAs($user); $response = $this->postJson('/api/v1/class-prep/mark-printed', [ 'class_section_ids' => [], ]); $response->assertStatus(422); $response->assertJsonStructure(['message', 'errors']); } public function test_save_adjustments_updates_rows(): void { $this->seedPrepData(); $user = $this->createUser(); Sanctum::actingAs($user); $response = $this->postJson('/api/v1/class-prep/adjustments', [ 'class_section_id' => '101', 'school_year' => '2025-2026', 'adjustments' => [ 'Small Table' => 2, ], ]); $response->assertOk(); $response->assertJson([ 'status' => true, ]); $this->assertDatabaseHas('class_prep_adjustments', [ 'class_section_id' => '101', 'school_year' => '2025-2026', 'item_name' => 'Small Table', 'adjustment' => 2, ]); } public function test_print_logs_prep_items(): void { $this->seedPrepData(); $user = $this->createUser(); Sanctum::actingAs($user); $response = $this->postJson('/api/v1/class-prep/print/101/2025-2026'); $response->assertOk(); $response->assertJsonPath('status', true); $response->assertJsonPath('data.print.class_section_id', '101'); $this->assertDatabaseHas('class_preparation_log', [ 'class_section_id' => 101, 'school_year' => '2025-2026', ]); } private function seedPrepData(): void { DB::table('configuration')->insert([ ['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'], ['id' => 2, '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([ '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('inventory_categories')->insert([ 'type' => 'classroom', 'name' => 'Small Table', ]); DB::table('inventory_items')->insert([ 'type' => 'classroom', 'category_id' => 1, 'name' => 'Small Table', 'quantity' => 10, 'good_qty' => 10, 'school_year' => '2025-2026', 'semester' => 'Fall', ]); } private function createUser(): User { DB::table('users')->insert([ 'school_id' => 1, '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', ]); return User::query()->findOrFail(1); } }