add class progress and fix endpoints
This commit is contained in:
@@ -12,161 +12,167 @@ class ClassPreparationControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_prep_payload(): void
|
||||
public function test_sticker_counts_returns_payload(): void
|
||||
{
|
||||
$this->seedPrepData();
|
||||
$this->seedStickerData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/class-prep?school_year=2025-2026&semester=Fall');
|
||||
$response = $this->getJson('/api/v1/class-prep/sticker-counts?school_year=2025-2026&semester=Fall');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
||||
'status' => true,
|
||||
'message' => 'Success',
|
||||
'ok' => true,
|
||||
'data' => [
|
||||
'schoolYear' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'totals' => [
|
||||
'primary' => 6,
|
||||
'secondary' => 1,
|
||||
'students' => 2,
|
||||
],
|
||||
],
|
||||
]);
|
||||
$this->assertNotEmpty($response->json('data.results'));
|
||||
}
|
||||
|
||||
public function test_mark_printed_creates_snapshots(): void
|
||||
public function test_students_by_class_returns_roster(): void
|
||||
{
|
||||
$this->seedPrepData();
|
||||
$this->seedStickerData();
|
||||
|
||||
$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 = $this->getJson('/api/v1/class-prep/classes/101/students?school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
||||
'status' => true,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('class_preparation_log', [
|
||||
'class_section_id' => 101,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
$this->assertCount(1, $response->json('students'));
|
||||
$this->assertSame('1-A', $response->json('students.0.registration_grade'));
|
||||
}
|
||||
|
||||
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
|
||||
private function seedStickerData(): 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('classes')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'class_name' => 'Class 1',
|
||||
'schedule' => 'Sun',
|
||||
'capacity' => 20,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'class_name' => 'Class 2',
|
||||
'schedule' => 'Sun',
|
||||
'capacity' => 20,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'class_name' => 'Class 3',
|
||||
'schedule' => 'Sun',
|
||||
'capacity' => 20,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '1-A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
[
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '1-A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'class_id' => 2,
|
||||
'class_section_id' => 102,
|
||||
'class_section_name' => '5-B',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'class_id' => 3,
|
||||
'class_section_id' => 103,
|
||||
'class_section_name' => 'Youth-1',
|
||||
'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,
|
||||
[
|
||||
'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,
|
||||
'is_new' => 0,
|
||||
],
|
||||
[
|
||||
'school_id' => 'S-2',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'Two',
|
||||
'age' => 10,
|
||||
'gender' => 'Female',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 1,
|
||||
'is_new' => 0,
|
||||
],
|
||||
[
|
||||
'school_id' => 'S-3',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'Three',
|
||||
'age' => 12,
|
||||
'gender' => 'Female',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 1,
|
||||
'is_new' => 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',
|
||||
[
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'student_id' => 2,
|
||||
'class_section_id' => 102,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'student_id' => 3,
|
||||
'class_section_id' => 103,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user