add class progress and fix endpoints
This commit is contained in:
@@ -1,203 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\ClassPrep;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassPrepControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_sticker_counts_returns_payload(): void
|
||||
{
|
||||
$this->seedStickerData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/class-prep/sticker-counts?school_year=2025-2026&semester=Fall');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
||||
'ok' => true,
|
||||
'data' => [
|
||||
'totals' => [
|
||||
'primary' => 6,
|
||||
'secondary' => 1,
|
||||
'students' => 2,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_students_by_class_returns_roster(): void
|
||||
{
|
||||
$this->seedStickerData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/class-prep/classes/101/students?school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertCount(1, $response->json('students'));
|
||||
$this->assertSame('1-A', $response->json('students.0.registration_grade'));
|
||||
}
|
||||
|
||||
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' => 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,
|
||||
'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',
|
||||
],
|
||||
[
|
||||
'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',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\ClassProgress;
|
||||
|
||||
use App\Models\ClassProgressAttachment;
|
||||
use App\Models\ClassProgressReport;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassProgressControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_meta_returns_sections(): void
|
||||
{
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/class-progress/meta');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('status', true);
|
||||
$this->assertNotEmpty($response->json('data.subject_sections'));
|
||||
}
|
||||
|
||||
public function test_index_returns_paginated_reports(): void
|
||||
{
|
||||
$user = $this->createUser();
|
||||
$this->seedClassSection();
|
||||
ClassProgressReport::factory()->count(2)->create([
|
||||
'teacher_id' => $user->id,
|
||||
'class_section_id' => 101,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/class-progress');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('status', true);
|
||||
$this->assertCount(2, $response->json('data.items'));
|
||||
}
|
||||
|
||||
public function test_store_creates_reports(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
$user = $this->createUser();
|
||||
$this->seedClassSection();
|
||||
$this->assignTeacher($user->id, 101);
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$payload = [
|
||||
'class_section_id' => 101,
|
||||
'week_start' => '2025-09-07',
|
||||
'week_end' => '2025-09-13',
|
||||
'covered_islamic' => 'Lesson A',
|
||||
'covered_quran' => 'Lesson B',
|
||||
'homework_islamic' => 'HW A',
|
||||
'homework_quran' => 'HW B',
|
||||
'flags' => ['needs_support'],
|
||||
];
|
||||
|
||||
$response = $this->postJson('/api/v1/class-progress', $payload);
|
||||
|
||||
$response->assertStatus(201);
|
||||
$response->assertJsonPath('status', true);
|
||||
$this->assertDatabaseCount('class_progress_reports', 2);
|
||||
}
|
||||
|
||||
public function test_show_returns_weekly_reports(): void
|
||||
{
|
||||
$user = $this->createUser();
|
||||
$this->seedClassSection();
|
||||
$report = ClassProgressReport::factory()->create([
|
||||
'teacher_id' => $user->id,
|
||||
'class_section_id' => 101,
|
||||
'week_start' => '2025-09-07',
|
||||
'week_end' => '2025-09-13',
|
||||
'subject' => 'Islamic Studies',
|
||||
]);
|
||||
ClassProgressReport::factory()->create([
|
||||
'teacher_id' => $user->id,
|
||||
'class_section_id' => 101,
|
||||
'week_start' => '2025-09-07',
|
||||
'week_end' => '2025-09-13',
|
||||
'subject' => 'Quran/Arabic',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/class-progress/' . $report->id);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('status', true);
|
||||
$this->assertCount(2, $response->json('data.weekly_reports'));
|
||||
}
|
||||
|
||||
public function test_update_modifies_report(): void
|
||||
{
|
||||
$user = $this->createUser();
|
||||
$this->seedClassSection();
|
||||
$report = ClassProgressReport::factory()->create([
|
||||
'teacher_id' => $user->id,
|
||||
'class_section_id' => 101,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->patchJson('/api/v1/class-progress/' . $report->id, [
|
||||
'status' => 'behind',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertDatabaseHas('class_progress_reports', [
|
||||
'id' => $report->id,
|
||||
'status' => 'behind',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_destroy_deletes_report(): void
|
||||
{
|
||||
$user = $this->createUser();
|
||||
$this->seedClassSection();
|
||||
$report = ClassProgressReport::factory()->create([
|
||||
'teacher_id' => $user->id,
|
||||
'class_section_id' => 101,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->deleteJson('/api/v1/class-progress/' . $report->id);
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertDatabaseMissing('class_progress_reports', [
|
||||
'id' => $report->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_authorization_blocks_other_teachers(): void
|
||||
{
|
||||
$owner = $this->createUser('teacher1@example.com');
|
||||
$other = $this->createUser('teacher2@example.com');
|
||||
$this->seedClassSection();
|
||||
$report = ClassProgressReport::factory()->create([
|
||||
'teacher_id' => $owner->id,
|
||||
'class_section_id' => 101,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($other);
|
||||
|
||||
$response = $this->getJson('/api/v1/class-progress/' . $report->id);
|
||||
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_validation_rejects_invalid_payload(): void
|
||||
{
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson('/api/v1/class-progress', [
|
||||
'class_section_id' => 'invalid',
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
}
|
||||
|
||||
public function test_attachment_download_returns_file(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
Storage::disk('public')->put('class_material/sample.pdf', 'content');
|
||||
|
||||
$user = $this->createUser();
|
||||
$this->seedClassSection();
|
||||
$report = ClassProgressReport::factory()->create([
|
||||
'teacher_id' => $user->id,
|
||||
'class_section_id' => 101,
|
||||
]);
|
||||
$attachment = ClassProgressAttachment::factory()->create([
|
||||
'report_id' => $report->id,
|
||||
'file_path' => 'storage/class_material/sample.pdf',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->get('/api/v1/class-progress/attachments/' . $attachment->id);
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
private function seedClassSection(): void
|
||||
{
|
||||
DB::table('classSection')->insert([
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '1-A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
}
|
||||
|
||||
private function assignTeacher(int $teacherId, int $classSectionId): void
|
||||
{
|
||||
DB::table('teacher_class')->insert([
|
||||
'class_section_id' => $classSectionId,
|
||||
'teacher_id' => $teacherId,
|
||||
'position' => 'main',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function createUser(string $email = 'teacher@example.com'): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => $email,
|
||||
'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()->where('email', $email)->firstOrFail();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Resources\ClassProgress;
|
||||
|
||||
use App\Http\Resources\ClassProgress\ClassProgressReportResource;
|
||||
use App\Models\ClassProgressReport;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassProgressReportResourceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_resource_has_expected_keys(): void
|
||||
{
|
||||
$report = ClassProgressReport::factory()->create();
|
||||
|
||||
$resource = (new ClassProgressReportResource($report))->toArray(request());
|
||||
|
||||
$this->assertArrayHasKey('id', $resource);
|
||||
$this->assertArrayHasKey('subject', $resource);
|
||||
$this->assertArrayHasKey('status', $resource);
|
||||
$this->assertArrayHasKey('attachments', $resource);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\ClassProgress;
|
||||
|
||||
use App\Models\ClassProgressReport;
|
||||
use App\Services\ClassProgress\ClassProgressAttachmentService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassProgressAttachmentServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_store_attachments_persists_records(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
|
||||
$report = ClassProgressReport::factory()->create();
|
||||
$service = new ClassProgressAttachmentService();
|
||||
|
||||
$files = [UploadedFile::fake()->create('sample.pdf', 12)];
|
||||
$stored = $service->storeAttachments($report->id, $files);
|
||||
|
||||
$this->assertCount(1, $stored);
|
||||
$this->assertDatabaseHas('class_progress_attachments', [
|
||||
'report_id' => $report->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\ClassProgress;
|
||||
|
||||
use App\Services\ClassProgress\ClassProgressMetaService;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassProgressMetaServiceTest extends TestCase
|
||||
{
|
||||
public function test_subject_sections_return_configured_values(): void
|
||||
{
|
||||
$service = new ClassProgressMetaService();
|
||||
|
||||
$sections = $service->subjectSections();
|
||||
|
||||
$this->assertArrayHasKey('islamic', $sections);
|
||||
$this->assertArrayHasKey('quran', $sections);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\ClassProgress;
|
||||
|
||||
use App\Models\ClassProgressReport;
|
||||
use App\Models\User;
|
||||
use App\Services\ClassProgress\ClassProgressAttachmentService;
|
||||
use App\Services\ClassProgress\ClassProgressMutationService;
|
||||
use App\Services\ClassProgress\ClassProgressRuleService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassProgressMutationServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_create_reports_persists_multiple_subjects(): void
|
||||
{
|
||||
$user = $this->createUser();
|
||||
$this->seedClassSection();
|
||||
$this->assignTeacher($user->id, 101);
|
||||
|
||||
$service = new ClassProgressMutationService(
|
||||
new ClassProgressRuleService(),
|
||||
new ClassProgressAttachmentService()
|
||||
);
|
||||
|
||||
$payload = [
|
||||
'class_section_id' => 101,
|
||||
'week_start' => '2025-09-07',
|
||||
'week_end' => '2025-09-13',
|
||||
'covered_islamic' => 'Lesson A',
|
||||
'covered_quran' => 'Lesson B',
|
||||
];
|
||||
|
||||
$reports = $service->createReports($user, $payload, []);
|
||||
|
||||
$this->assertCount(2, $reports);
|
||||
$this->assertDatabaseCount('class_progress_reports', 2);
|
||||
}
|
||||
|
||||
public function test_update_report_changes_status(): void
|
||||
{
|
||||
$report = ClassProgressReport::factory()->create([
|
||||
'status' => 'on_track',
|
||||
]);
|
||||
|
||||
$service = new ClassProgressMutationService(
|
||||
new ClassProgressRuleService(),
|
||||
new ClassProgressAttachmentService()
|
||||
);
|
||||
|
||||
$updated = $service->updateReport($report, ['status' => 'behind'], []);
|
||||
|
||||
$this->assertSame('behind', $updated->status);
|
||||
}
|
||||
|
||||
public function test_delete_report_removes_record(): void
|
||||
{
|
||||
$report = ClassProgressReport::factory()->create();
|
||||
$service = new ClassProgressMutationService(
|
||||
new ClassProgressRuleService(),
|
||||
new ClassProgressAttachmentService()
|
||||
);
|
||||
|
||||
$service->deleteReport($report);
|
||||
|
||||
$this->assertDatabaseMissing('class_progress_reports', ['id' => $report->id]);
|
||||
}
|
||||
|
||||
private function seedClassSection(): void
|
||||
{
|
||||
DB::table('classSection')->insert([
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '1-A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
}
|
||||
|
||||
private function assignTeacher(int $teacherId, int $classSectionId): void
|
||||
{
|
||||
DB::table('teacher_class')->insert([
|
||||
'class_section_id' => $classSectionId,
|
||||
'teacher_id' => $teacherId,
|
||||
'position' => 'main',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function createUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@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()->where('email', 'teacher@example.com')->firstOrFail();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\ClassProgress;
|
||||
|
||||
use App\Models\ClassProgressReport;
|
||||
use App\Models\User;
|
||||
use App\Services\ClassProgress\ClassProgressQueryService;
|
||||
use App\Services\ClassProgress\ClassProgressRuleService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassProgressQueryServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_list_reports_filters_by_class_section(): void
|
||||
{
|
||||
$user = $this->createUser();
|
||||
ClassProgressReport::factory()->create([
|
||||
'teacher_id' => $user->id,
|
||||
'class_section_id' => 101,
|
||||
]);
|
||||
ClassProgressReport::factory()->create([
|
||||
'teacher_id' => $user->id,
|
||||
'class_section_id' => 202,
|
||||
]);
|
||||
|
||||
$service = new ClassProgressQueryService(new ClassProgressRuleService());
|
||||
$results = $service->listReports($user, ['class_section_id' => 101]);
|
||||
|
||||
$this->assertSame(1, $results->total());
|
||||
}
|
||||
|
||||
private function createUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@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()->where('email', 'teacher@example.com')->firstOrFail();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\ClassProgress;
|
||||
|
||||
use App\Services\ClassProgress\ClassProgressRuleService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ClassProgressRuleServiceTest extends TestCase
|
||||
{
|
||||
public function test_build_unit_chapter_summary_limits_length(): void
|
||||
{
|
||||
$service = new ClassProgressRuleService();
|
||||
|
||||
$summary = $service->buildUnitChapterSummary(['Unit 1'], ['Chapter A']);
|
||||
|
||||
$this->assertSame('Unit 1 / Chapter A', $summary);
|
||||
}
|
||||
|
||||
public function test_ensure_week_end_defaults_to_six_days(): void
|
||||
{
|
||||
$service = new ClassProgressRuleService();
|
||||
|
||||
$weekEnd = $service->ensureWeekEnd('2025-09-07', null);
|
||||
|
||||
$this->assertSame('2025-09-13', $weekEnd);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user