fix logic and tests, update docker CI file

This commit is contained in:
root
2026-03-09 15:58:44 -04:00
parent 1cb3573d4b
commit 79e44fe037
188 changed files with 1776 additions and 524 deletions
@@ -21,7 +21,7 @@ class AdministratorAbsenceControllerTest extends TestCase
public function test_guest_cannot_access_absence_index(): void
{
$response = $this->getJson('/api/administrator/absence');
$response = $this->getJson('/api/v1/administrator/absence');
$response->assertStatus(401);
}
@@ -46,7 +46,7 @@ class AdministratorAbsenceControllerTest extends TestCase
$this->app->instance(AdministratorAbsenceService::class, $mock);
$response = $this->getJson('/api/administrator/absence');
$response = $this->getJson('/api/v1/administrator/absence');
$response->assertOk()
->assertJson([
@@ -62,7 +62,7 @@ class AdministratorAbsenceControllerTest extends TestCase
Sanctum::actingAs($user);
$response = $this->postJson('/api/administrator/absence', [
$response = $this->postJson('/api/v1/administrator/absence', [
'dates' => ['2026-03-08'],
'reason_type' => 'vacation',
'reason' => '',
@@ -78,7 +78,7 @@ class AdministratorAbsenceControllerTest extends TestCase
Sanctum::actingAs($user);
$response = $this->postJson('/api/administrator/absence', [
$response = $this->postJson('/api/v1/administrator/absence', [
'dates' => ['03/08/2026'],
'reason_type' => 'vacation',
'reason' => 'Family trip',
@@ -112,7 +112,7 @@ class AdministratorAbsenceControllerTest extends TestCase
$this->app->instance(AdministratorAbsenceService::class, $mock);
$response = $this->postJson('/api/administrator/absence', $payload);
$response = $this->postJson('/api/v1/administrator/absence', $payload);
$response->assertOk()
->assertJson([
@@ -22,7 +22,7 @@ class AdministratorEnrollmentControllerTest extends TestCase
public function test_guest_cannot_update_enrollment_statuses(): void
{
$response = $this->postJson('/api/administrator/enrollment-withdrawal/update-statuses', [
$response = $this->postJson('/api/v1/administrator/enrollment-withdrawal/update-statuses', [
'enrollment_status' => [
10 => 'enrolled',
],
@@ -50,7 +50,7 @@ class AdministratorEnrollmentControllerTest extends TestCase
$this->app->instance(AdministratorEnrollmentQueryService::class, $mock);
$response = $this->getJson('/api/administrator/enrollment-withdrawal?schoolYear=2025-2026');
$response = $this->getJson('/api/v1/administrator/enrollment-withdrawal?schoolYear=2025-2026');
$response->assertOk()
->assertJson([
@@ -74,7 +74,7 @@ class AdministratorEnrollmentControllerTest extends TestCase
$this->app->instance(AdministratorEnrollmentQueryService::class, $mock);
$response = $this->getJson('/api/administrator/enrollment-withdrawal/new-students');
$response = $this->getJson('/api/v1/administrator/enrollment-withdrawal/new-students');
$response->assertOk()
->assertJson([
@@ -88,7 +88,7 @@ class AdministratorEnrollmentControllerTest extends TestCase
$user = User::factory()->create();
Sanctum::actingAs($user);
$response = $this->postJson('/api/administrator/enrollment-withdrawal/update-statuses', [
$response = $this->postJson('/api/v1/administrator/enrollment-withdrawal/update-statuses', [
'enrollment_status' => [
10 => 'bad-status',
],
@@ -121,7 +121,7 @@ class AdministratorEnrollmentControllerTest extends TestCase
$this->app->instance(AdministratorEnrollmentStatusService::class, $mock);
$response = $this->postJson('/api/administrator/enrollment-withdrawal/update-statuses', $payload);
$response = $this->postJson('/api/v1/administrator/enrollment-withdrawal/update-statuses', $payload);
$response->assertOk()
->assertJson([
@@ -48,30 +48,29 @@ class AdministratorEnrollmentQueryApiTest extends TestCase
'lastname' => 'Two',
]);
$studentOne = Student::query()->create([
$studentOne = Student::factory()->create([
'id' => 1,
'parent_id' => $parentOne->id,
'firstname' => 'Ali',
'lastname' => 'Ben',
'is_new' => 1,
'registration_date' => '2025-09-10 08:00:00',
'admission_status' => 'accepted',
]);
$studentTwo = Student::query()->create([
$studentTwo = Student::factory()->create([
'id' => 2,
'parent_id' => $parentTwo->id,
'firstname' => 'Sara',
'lastname' => 'Ali',
'is_new' => 0,
'registration_date' => '2024-09-10 08:00:00',
'admission_status' => 'accepted',
]);
ClassSection::unguard();
ClassSection::query()->create([
'class_section_id' => 10,
'class_section_name' => 'Grade 5A',
'class_id' => 5,
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
@@ -107,7 +106,7 @@ class AdministratorEnrollmentQueryApiTest extends TestCase
'enrollment_date' => now()->subYear()->toDateString(),
]);
$response = $this->getJson('/api/administrator/enrollment-withdrawal?schoolYear=2025-2026');
$response = $this->getJson('/api/v1/administrator/enrollment-withdrawal?schoolYear=2025-2026');
$response->assertOk()
->assertJson([
@@ -142,30 +141,29 @@ class AdministratorEnrollmentQueryApiTest extends TestCase
'lastname' => 'House',
]);
$studentOne = Student::query()->create([
$studentOne = Student::factory()->create([
'id' => 9,
'parent_id' => $parent->id,
'firstname' => 'Adam',
'lastname' => 'Y',
'is_new' => 1,
'registration_date' => '2025-10-01 10:00:00',
'admission_status' => 'accepted',
]);
$studentTwo = Student::query()->create([
$studentTwo = Student::factory()->create([
'id' => 10,
'parent_id' => $parent->id,
'firstname' => 'Eve',
'lastname' => 'Z',
'is_new' => 0,
'registration_date' => null,
'admission_status' => 'accepted',
]);
ClassSection::unguard();
ClassSection::query()->create([
'class_section_id' => 20,
'class_section_name' => 'Grade 1A',
'class_id' => 1,
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
@@ -201,7 +199,7 @@ class AdministratorEnrollmentQueryApiTest extends TestCase
'enrollment_date' => now()->toDateString(),
]);
$response = $this->getJson('/api/administrator/enrollment-withdrawal/new-students');
$response = $this->getJson('/api/v1/administrator/enrollment-withdrawal/new-students');
$response->assertOk()
->assertJson([
@@ -224,4 +222,4 @@ class AdministratorEnrollmentQueryApiTest extends TestCase
$this->assertSame('Class not Assigned', $second['class_section']);
$this->assertSame('waitlist', $second['enrollment_status']);
}
}
}
@@ -5,7 +5,7 @@ namespace Tests\Feature\Api\Administrator;
use App\Models\Configuration;
use App\Models\Enrollment;
use App\Models\Invoice;
use App\Models\RefundModel as Refund;
use App\Models\Refund;
use App\Models\Student;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -37,7 +37,7 @@ class AdministratorEnrollmentUpdateStatusesApiTest extends TestCase
$admin = User::factory()->create();
Sanctum::actingAs($admin);
$response = $this->postJson('/api/administrator/enrollment-withdrawal/update-statuses', []);
$response = $this->postUpdateStatuses([]);
$response->assertStatus(422)
->assertJsonValidationErrors(['enrollment_status']);
@@ -48,14 +48,10 @@ class AdministratorEnrollmentUpdateStatusesApiTest extends TestCase
$admin = User::factory()->create();
Sanctum::actingAs($admin);
$response = $this->postJson('/api/administrator/enrollment-withdrawal/update-statuses', [
'enrollment_status' => [
10 => 'not-valid',
],
]);
$response = $this->postUpdateStatuses(['not-valid']);
$response->assertStatus(422)
->assertJsonValidationErrors(['enrollment_status.10']);
->assertJsonValidationErrors(['enrollment_status.0']);
}
public function test_update_statuses_creates_new_enrollment_row(): void
@@ -72,19 +68,15 @@ class AdministratorEnrollmentUpdateStatusesApiTest extends TestCase
'email' => 'parent1@test.com',
]);
Student::unguard();
Student::query()->create([
Student::factory()->create([
'id' => 10,
'parent_id' => $parent->id,
'firstname' => 'Ali',
'lastname' => 'Ben',
'admission_status' => 'pending',
]);
$response = $this->postJson('/api/administrator/enrollment-withdrawal/update-statuses', [
'enrollment_status' => [
10 => 'enrolled',
],
$response = $this->postUpdateStatuses([
10 => 'enrolled',
]);
$response->assertOk()
@@ -117,13 +109,11 @@ class AdministratorEnrollmentUpdateStatusesApiTest extends TestCase
'email' => 'parent2@test.com',
]);
Student::unguard();
Student::query()->create([
Student::factory()->create([
'id' => 11,
'parent_id' => $parent->id,
'firstname' => 'Sara',
'lastname' => 'Ali',
'admission_status' => 'pending',
]);
Enrollment::unguard();
@@ -138,10 +128,8 @@ class AdministratorEnrollmentUpdateStatusesApiTest extends TestCase
'enrollment_date' => now()->toDateString(),
]);
$response = $this->postJson('/api/administrator/enrollment-withdrawal/update-statuses', [
'enrollment_status' => [
11 => 'withdrawn',
],
$response = $this->postUpdateStatuses([
11 => 'withdrawn',
]);
$response->assertOk();
@@ -169,13 +157,11 @@ class AdministratorEnrollmentUpdateStatusesApiTest extends TestCase
'email' => 'parent3@test.com',
]);
Student::unguard();
Student::query()->create([
Student::factory()->create([
'id' => 12,
'parent_id' => $parent->id,
'firstname' => 'Mina',
'lastname' => 'K',
'admission_status' => 'accepted',
]);
Enrollment::unguard();
@@ -194,16 +180,15 @@ class AdministratorEnrollmentUpdateStatusesApiTest extends TestCase
$invoice = Invoice::query()->create([
'parent_id' => 102,
'school_year' => '2025-2026',
'invoice_number' => 'INV-REF-1',
'balance' => 125.00,
'amount_due' => 125.00,
'total_amount' => 125.00,
'issue_date' => now()->toDateString(),
'due_date' => now()->addDays(10)->toDateString(),
]);
$response = $this->postJson('/api/administrator/enrollment-withdrawal/update-statuses', [
'enrollment_status' => [
12 => 'refund pending',
],
$response = $this->postUpdateStatuses([
12 => 'refund pending',
]);
$response->assertOk();
@@ -241,28 +226,23 @@ class AdministratorEnrollmentUpdateStatusesApiTest extends TestCase
'email' => 'parent4@test.com',
]);
Student::unguard();
Student::query()->create([
Student::factory()->create([
'id' => 13,
'parent_id' => $parent->id,
'firstname' => 'Adam',
'lastname' => 'Q',
'admission_status' => 'pending',
]);
Student::query()->create([
Student::factory()->create([
'id' => 14,
'parent_id' => null,
'parent_id' => 0,
'firstname' => 'No',
'lastname' => 'Parent',
'admission_status' => 'pending',
]);
$response = $this->postJson('/api/administrator/enrollment-withdrawal/update-statuses', [
'enrollment_status' => [
13 => 'enrolled',
14 => 'enrolled',
],
$response = $this->postUpdateStatuses([
13 => 'enrolled',
14 => 'enrolled',
]);
$response->assertStatus(207);
@@ -279,4 +259,10 @@ class AdministratorEnrollmentUpdateStatusesApiTest extends TestCase
'school_year' => '2025-2026',
]);
}
}
private function postUpdateStatuses(array $enrollmentStatus)
{
$query = http_build_query(['enrollment_status' => $enrollmentStatus]);
return $this->post('/api/v1/administrator/enrollment-withdrawal/update-statuses?' . $query, []);
}
}
@@ -39,7 +39,7 @@ class AdministratorNotificationControllerTest extends TestCase
$this->app->instance(AdminNotificationSubjectService::class, $mock);
$response = $this->getJson('/api/administrator/notifications/alerts');
$response = $this->getJson('/api/v1/administrator/notifications/alerts');
$response->assertOk()
->assertJson([
@@ -54,7 +54,7 @@ class AdministratorNotificationControllerTest extends TestCase
$user = User::factory()->create();
Sanctum::actingAs($user);
$response = $this->postJson('/api/administrator/notifications/alerts', []);
$response = $this->postJson('/api/v1/administrator/notifications/alerts', []);
$response->assertStatus(422)
->assertJsonValidationErrors(['subjects']);
@@ -82,7 +82,7 @@ class AdministratorNotificationControllerTest extends TestCase
$this->app->instance(AdminNotificationSubjectService::class, $mock);
$response = $this->postJson('/api/administrator/notifications/alerts', $payload);
$response = $this->postJson('/api/v1/administrator/notifications/alerts', $payload);
$response->assertOk()
->assertJson([
@@ -106,7 +106,7 @@ class AdministratorNotificationControllerTest extends TestCase
$this->app->instance(AdminPrintRecipientService::class, $mock);
$response = $this->getJson('/api/administrator/notifications/print-recipients');
$response = $this->getJson('/api/v1/administrator/notifications/print-recipients');
$response->assertOk()
->assertJson([
@@ -121,7 +121,7 @@ class AdministratorNotificationControllerTest extends TestCase
$user = User::factory()->create();
Sanctum::actingAs($user);
$response = $this->postJson('/api/administrator/notifications/print-recipients', []);
$response = $this->postJson('/api/v1/administrator/notifications/print-recipients', []);
$response->assertStatus(422)
->assertJsonValidationErrors(['notify']);
@@ -150,7 +150,7 @@ class AdministratorNotificationControllerTest extends TestCase
$this->app->instance(AdminPrintRecipientService::class, $mock);
$response = $this->postJson('/api/administrator/notifications/print-recipients', $payload);
$response = $this->postJson('/api/v1/administrator/notifications/print-recipients', $payload);
$response->assertOk()
->assertJson([
@@ -43,7 +43,7 @@ class AdministratorTeacherSubmissionControllerTest extends TestCase
$this->app->instance(TeacherSubmissionReportService::class, $mock);
$response = $this->getJson('/api/administrator/teacher-submissions');
$response = $this->getJson('/api/v1/administrator/teacher-submissions');
$response->assertOk()
->assertJson([
@@ -58,7 +58,7 @@ class AdministratorTeacherSubmissionControllerTest extends TestCase
$user = User::factory()->create();
Sanctum::actingAs($user);
$response = $this->postJson('/api/administrator/teacher-submissions/notify', [
$response = $this->postJson('/api/v1/administrator/teacher-submissions/notify', [
'missing_items' => [],
]);
@@ -96,7 +96,7 @@ class AdministratorTeacherSubmissionControllerTest extends TestCase
$this->app->instance(TeacherSubmissionNotificationService::class, $mock);
$response = $this->postJson('/api/administrator/teacher-submissions/notify', $payload);
$response = $this->postJson('/api/v1/administrator/teacher-submissions/notify', $payload);
$response->assertOk()
->assertJson([
@@ -35,7 +35,7 @@ class AdministratorTeacherSubmissionNotifyApiTest extends TestCase
$admin = User::factory()->create();
Sanctum::actingAs($admin);
$response = $this->postJson('/api/administrator/teacher-submissions/notify', [
$response = $this->postJson('/api/v1/administrator/teacher-submissions/notify', [
'missing_items' => [],
]);
@@ -55,19 +55,20 @@ class AdministratorTeacherSubmissionNotifyApiTest extends TestCase
]);
Sanctum::actingAs($admin);
DB::table('users')->insert([
[
'id' => 100,
'firstname' => 'John',
'lastname' => 'Teacher',
'email' => 'teacher@test.com',
],
User::factory()->create([
'id' => 100,
'firstname' => 'John',
'lastname' => 'Teacher',
'email' => 'teacher@test.com',
]);
DB::table('classSection')->insert([
[
'class_section_id' => 10,
'class_section_name' => 'Grade 5A',
'class_id' => 5,
'semester' => 'Fall',
'school_year' => '2025-2026',
],
]);
@@ -87,7 +88,7 @@ class AdministratorTeacherSubmissionNotifyApiTest extends TestCase
],
];
$response = $this->postJson('/api/administrator/teacher-submissions/notify', $payload);
$response = $this->postJson('/api/v1/administrator/teacher-submissions/notify', $payload);
$response->assertOk()
->assertJson([
@@ -123,19 +124,20 @@ class AdministratorTeacherSubmissionNotifyApiTest extends TestCase
]);
Sanctum::actingAs($admin);
DB::table('users')->insert([
[
'id' => 101,
'firstname' => 'Bad',
'lastname' => 'Email',
'email' => 'not-an-email',
],
User::factory()->create([
'id' => 101,
'firstname' => 'Bad',
'lastname' => 'Email',
'email' => 'not-an-email',
]);
DB::table('classSection')->insert([
[
'class_section_id' => 11,
'class_section_name' => 'Grade 6A',
'class_id' => 6,
'semester' => 'Fall',
'school_year' => '2025-2026',
],
]);
@@ -147,7 +149,7 @@ class AdministratorTeacherSubmissionNotifyApiTest extends TestCase
],
];
$response = $this->postJson('/api/administrator/teacher-submissions/notify', $payload);
$response = $this->postJson('/api/v1/administrator/teacher-submissions/notify', $payload);
$response->assertStatus(207)
->assertJson([
@@ -167,4 +169,4 @@ class AdministratorTeacherSubmissionNotifyApiTest extends TestCase
'semester' => 'Fall',
]);
}
}
}
@@ -10,6 +10,7 @@ use App\Models\TeacherSubmissionNotificationHistory;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
@@ -37,25 +38,26 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
$admin = User::factory()->create(['id' => 900, 'firstname' => 'Admin', 'lastname' => 'One']);
Sanctum::actingAs($admin);
DB::table('users')->insert([
[
'id' => 100,
'firstname' => 'Main',
'lastname' => 'Teacher',
'email' => 'main@test.com',
],
[
'id' => 101,
'firstname' => 'TA',
'lastname' => 'Teacher',
'email' => 'ta@test.com',
],
User::factory()->create([
'id' => 100,
'firstname' => 'Main',
'lastname' => 'Teacher',
'email' => 'main@test.com',
]);
User::factory()->create([
'id' => 101,
'firstname' => 'TA',
'lastname' => 'Teacher',
'email' => 'ta@test.com',
]);
DB::table('classSection')->insert([
[
'class_section_id' => 10,
'class_section_name' => 'Grade 5A',
'class_id' => 5,
'semester' => 'Fall',
'school_year' => '2025-2026',
],
]);
@@ -91,10 +93,12 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
],
]);
$schoolId = (string) Str::uuid();
SemesterScore::unguard();
SemesterScore::query()->create([
'student_id' => 1,
'class_section_id' => 10,
'school_id' => $schoolId,
'school_year' => '2025-2026',
'semester' => 'Fall',
'midterm_exam_score' => '88',
@@ -103,15 +107,17 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
SemesterScore::query()->create([
'student_id' => 2,
'class_section_id' => 10,
'school_id' => $schoolId,
'school_year' => '2025-2026',
'semester' => 'Fall',
'midterm_exam_score' => '',
'midterm_exam_score' => null,
'participation_score' => '9',
]);
ScoreComment::unguard();
ScoreComment::query()->create([
'student_id' => 1,
'class_section_id' => 10,
'school_year' => '2025-2026',
'semester' => 'Fall',
'score_type' => 'midterm',
@@ -119,6 +125,7 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
]);
ScoreComment::query()->create([
'student_id' => 1,
'class_section_id' => 10,
'school_year' => '2025-2026',
'semester' => 'Fall',
'score_type' => 'ptap',
@@ -147,7 +154,7 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
'sent_at' => now(),
]);
$response = $this->getJson('/api/administrator/teacher-submissions');
$response = $this->getJson('/api/v1/administrator/teacher-submissions');
$response->assertOk()
->assertJson([
@@ -195,19 +202,20 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
$admin = User::factory()->create();
Sanctum::actingAs($admin);
DB::table('users')->insert([
[
'id' => 200,
'firstname' => 'Solo',
'lastname' => 'Teacher',
'email' => 'solo@test.com',
],
User::factory()->create([
'id' => 200,
'firstname' => 'Solo',
'lastname' => 'Teacher',
'email' => 'solo@test.com',
]);
DB::table('classSection')->insert([
[
'class_section_id' => 11,
'class_section_name' => 'Grade 6A',
'class_id' => 6,
'semester' => 'Fall',
'school_year' => '2025-2026',
],
]);
@@ -221,7 +229,7 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
],
]);
$response = $this->getJson('/api/administrator/teacher-submissions');
$response = $this->getJson('/api/v1/administrator/teacher-submissions');
$response->assertOk()
->assertJsonCount(1, 'rows');
@@ -241,19 +249,20 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
$admin = User::factory()->create(['id' => 901, 'firstname' => 'Admin', 'lastname' => 'Two']);
Sanctum::actingAs($admin);
DB::table('users')->insert([
[
'id' => 300,
'firstname' => 'Hist',
'lastname' => 'Teacher',
'email' => 'hist@test.com',
],
User::factory()->create([
'id' => 300,
'firstname' => 'Hist',
'lastname' => 'Teacher',
'email' => 'hist@test.com',
]);
DB::table('classSection')->insert([
[
'class_section_id' => 12,
'class_section_name' => 'Grade 7A',
'class_id' => 7,
'semester' => 'Fall',
'school_year' => '2025-2026',
],
]);
@@ -282,11 +291,11 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
]);
}
$response = $this->getJson('/api/administrator/teacher-submissions');
$response = $this->getJson('/api/v1/administrator/teacher-submissions');
$response->assertOk();
$history = $response->json('notificationHistory.12.300');
$this->assertCount(3, $history);
}
}
}
@@ -89,7 +89,7 @@ class AssignmentApiControllerTest extends TestCase
{
TeacherClass::query()->create([
'teacher_id' => $this->teacherMain->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
@@ -98,7 +98,7 @@ class AssignmentApiControllerTest extends TestCase
TeacherClass::query()->create([
'teacher_id' => $this->teacherAssistant->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'position' => 'ta',
'semester' => 'Fall',
'school_year' => '2025-2026',
@@ -107,7 +107,7 @@ class AssignmentApiControllerTest extends TestCase
StudentClass::query()->create([
'student_id' => $this->studentOne->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'semester' => 'Fall',
'school_year' => '2025-2026',
'description' => 'Morning group',
@@ -125,7 +125,7 @@ class AssignmentApiControllerTest extends TestCase
->assertJsonPath('data.semester', 'Fall')
->assertJsonPath('data.current_school_year', '2025-2026')
->assertJsonCount(1, 'data.classSections')
->assertJsonPath('data.classSections.0.class_section_id', $this->sectionA->id)
->assertJsonPath('data.classSections.0.class_section_id', $this->sectionA->class_section_id)
->assertJsonPath('data.classSections.0.class_section_name', 'Grade 1 - A')
->assertJsonPath('data.classSections.0.main_teachers.0', 'Main Teacher')
->assertJsonPath('data.classSections.0.teacher_assistants.0', 'Assistant Teacher')
@@ -140,7 +140,7 @@ class AssignmentApiControllerTest extends TestCase
{
TeacherClass::query()->create([
'teacher_id' => $this->teacherMain->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
@@ -149,7 +149,7 @@ class AssignmentApiControllerTest extends TestCase
TeacherClass::query()->create([
'teacher_id' => $this->teacherAssistant->id,
'class_section_id' => $this->sectionB->id,
'class_section_id' => $this->sectionB->class_section_id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2024-2025',
@@ -158,7 +158,7 @@ class AssignmentApiControllerTest extends TestCase
StudentClass::query()->create([
'student_id' => $this->studentOne->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'semester' => 'Fall',
'school_year' => '2025-2026',
'description' => 'Included',
@@ -167,7 +167,7 @@ class AssignmentApiControllerTest extends TestCase
StudentClass::query()->create([
'student_id' => $this->studentTwo->id,
'class_section_id' => $this->sectionB->id,
'class_section_id' => $this->sectionB->class_section_id,
'semester' => 'Fall',
'school_year' => '2024-2025',
'description' => 'Excluded',
@@ -186,7 +186,7 @@ class AssignmentApiControllerTest extends TestCase
{
TeacherClass::query()->create([
'teacher_id' => $this->teacherMain->id,
'class_section_id' => $this->sectionB->id,
'class_section_id' => $this->sectionB->class_section_id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
@@ -195,7 +195,7 @@ class AssignmentApiControllerTest extends TestCase
TeacherClass::query()->create([
'teacher_id' => $this->teacherAssistant->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
@@ -224,7 +224,7 @@ class AssignmentApiControllerTest extends TestCase
TeacherClass::query()->create([
'teacher_id' => $this->teacherMain->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
@@ -233,7 +233,7 @@ class AssignmentApiControllerTest extends TestCase
StudentClass::query()->create([
'student_id' => $inactiveStudent->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'semester' => 'Fall',
'school_year' => '2025-2026',
'description' => 'Should not show',
@@ -251,7 +251,7 @@ class AssignmentApiControllerTest extends TestCase
{
$payload = [
'student_id' => $this->studentOne->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'semester' => 'Fall',
'school_year' => '2025-2026',
'description' => 'New assignment',
@@ -263,14 +263,14 @@ class AssignmentApiControllerTest extends TestCase
$response->assertCreated()
->assertJsonPath('message', 'Assignment saved successfully.')
->assertJsonPath('data.student_id', $this->studentOne->id)
->assertJsonPath('data.class_section_id', $this->sectionA->id)
->assertJsonPath('data.class_section_id', $this->sectionA->class_section_id)
->assertJsonPath('data.semester', 'Fall')
->assertJsonPath('data.school_year', '2025-2026')
->assertJsonPath('data.description', 'New assignment');
$this->assertDatabaseHas('student_class', [
'student_id' => $this->studentOne->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'semester' => 'Fall',
'school_year' => '2025-2026',
'description' => 'New assignment',
@@ -282,7 +282,7 @@ class AssignmentApiControllerTest extends TestCase
{
StudentClass::query()->create([
'student_id' => $this->studentOne->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'semester' => 'Fall',
'school_year' => '2025-2026',
'description' => 'Old description',
@@ -291,7 +291,7 @@ class AssignmentApiControllerTest extends TestCase
$payload = [
'student_id' => $this->studentOne->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'semester' => 'Fall',
'school_year' => '2025-2026',
'description' => 'Updated description',
@@ -305,7 +305,7 @@ class AssignmentApiControllerTest extends TestCase
$this->assertDatabaseHas('student_class', [
'student_id' => $this->studentOne->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'semester' => 'Fall',
'school_year' => '2025-2026',
'description' => 'Updated description',
@@ -315,7 +315,7 @@ class AssignmentApiControllerTest extends TestCase
1,
StudentClass::query()
->where('student_id', $this->studentOne->id)
->where('class_section_id', $this->sectionA->id)
->where('class_section_id', $this->sectionA->class_section_id)
->where('semester', 'Fall')
->where('school_year', '2025-2026')
->count()
@@ -360,7 +360,7 @@ class AssignmentApiControllerTest extends TestCase
{
TeacherClass::query()->create([
'teacher_id' => $this->teacherMain->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
@@ -369,7 +369,7 @@ class AssignmentApiControllerTest extends TestCase
StudentClass::query()->create([
'student_id' => $this->studentOne->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'semester' => 'Fall',
'school_year' => '2025-2026',
'description' => 'Morning group',
@@ -393,7 +393,7 @@ class AssignmentApiControllerTest extends TestCase
{
TeacherClass::query()->create([
'teacher_id' => $this->teacherMain->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
@@ -402,7 +402,7 @@ class AssignmentApiControllerTest extends TestCase
TeacherClass::query()->create([
'teacher_id' => $this->teacherMain->id,
'class_section_id' => $this->sectionA->id,
'class_section_id' => $this->sectionA->class_section_id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
+53 -45
View File
@@ -23,28 +23,27 @@ class AssignmentApiTest extends TestCase
{
parent::setUp();
// If your app uses Sanctum auth
$this->user = User::factory()->create();
Sanctum::actingAs($this->user);
// Seed config values used by AssignmentService
// Adjust columns if your configuration table schema differs
Configuration::query()->updateOrCreate(
['key' => 'semester'],
['value' => 'Fall']
['config_key' => 'semester'],
['config_value' => 'Fall']
);
Configuration::query()->updateOrCreate(
['key' => 'school_year'],
['value' => '2025-2026']
['config_key' => 'school_year'],
['config_value' => '2025-2026']
);
}
#[Test]
public function it_returns_assignment_sections_json(): void
{
Sanctum::actingAs($this->user);
$section = ClassSection::factory()->create([
'name' => 'Grade 5 - A', // or title depending on your schema
'class_section_name' => 'Grade 5 - A',
]);
$teacher = User::factory()->create([
@@ -54,7 +53,7 @@ class AssignmentApiTest extends TestCase
TeacherClass::query()->create([
'teacher_id' => $teacher->id,
'class_section_id' => $section->id,
'class_section_id' => $section->class_section_id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
@@ -74,7 +73,7 @@ class AssignmentApiTest extends TestCase
StudentClass::query()->create([
'student_id' => $student->id,
'class_section_id' => $section->id,
'class_section_id' => $section->class_section_id,
'semester' => 'Fall',
'school_year' => '2025-2026',
'description' => 'Student assigned',
@@ -85,41 +84,46 @@ class AssignmentApiTest extends TestCase
$response->assertOk()
->assertJsonStructure([
'classSections' => [
'*' => [
'class_section_id',
'class_section_name',
'main_teachers',
'teacher_assistants',
'students',
'semester',
'school_year',
'description',
]
'message',
'data' => [
'classSections' => [
'*' => [
'class_section_id',
'class_section_name',
'main_teachers',
'teacher_assistants',
'students',
'semester',
'school_year',
'description',
]
],
'schoolYears',
'selectedYear',
'selectedSemester',
'semester',
'current_school_year',
],
'schoolYears',
'selectedYear',
'selectedSemester',
'semester',
'school_year',
]);
$response->assertJsonPath('classSections.0.class_section_id', $section->id);
$response->assertJsonPath('classSections.0.main_teachers.0', 'Ahmad Ali');
$response->assertJsonPath('classSections.0.students.0.id', $student->id);
$response->assertJsonPath('data.classSections.0.class_section_id', $section->class_section_id);
$response->assertJsonPath('data.classSections.0.main_teachers.0', 'Ahmad Ali');
$response->assertJsonPath('data.classSections.0.students.0.id', $student->id);
}
#[Test]
public function it_filters_assignments_by_school_year(): void
{
$section1 = ClassSection::factory()->create(['name' => 'Grade 4']);
$section2 = ClassSection::factory()->create(['name' => 'Grade 6']);
Sanctum::actingAs($this->user);
$section1 = ClassSection::factory()->create(['class_section_name' => 'Grade 4']);
$section2 = ClassSection::factory()->create(['class_section_name' => 'Grade 6']);
$teacher = User::factory()->create(['firstname' => 'Test', 'lastname' => 'Teacher']);
TeacherClass::query()->create([
'teacher_id' => $teacher->id,
'class_section_id' => $section1->id,
'class_section_id' => $section1->class_section_id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2024-2025',
@@ -127,7 +131,7 @@ class AssignmentApiTest extends TestCase
TeacherClass::query()->create([
'teacher_id' => $teacher->id,
'class_section_id' => $section2->id,
'class_section_id' => $section2->class_section_id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
@@ -137,23 +141,25 @@ class AssignmentApiTest extends TestCase
$response->assertOk();
$sections = $response->json('classSections');
$sections = $response->json('data.classSections');
$ids = collect($sections)->pluck('class_section_id')->all();
$this->assertContains($section2->id, $ids);
$this->assertNotContains($section1->id, $ids);
$response->assertJsonPath('selectedYear', '2025-2026');
$this->assertContains($section2->class_section_id, $ids);
$this->assertNotContains($section1->class_section_id, $ids);
$response->assertJsonPath('data.selectedYear', '2025-2026');
}
#[Test]
public function it_creates_or_updates_student_assignment(): void
{
Sanctum::actingAs($this->user);
$student = Student::factory()->create(['is_active' => 1]);
$section = ClassSection::factory()->create();
$payload = [
'student_id' => $student->id,
'class_section_id' => $section->id,
'class_section_id' => $section->class_section_id,
'semester' => 'Spring',
'school_year' => '2025-2026',
'description' => 'Moved after placement review',
@@ -162,11 +168,11 @@ class AssignmentApiTest extends TestCase
$response = $this->postJson('/api/assignments', $payload);
$response->assertCreated()
->assertJsonPath('message', 'Assignment saved successfully');
->assertJsonPath('message', 'Assignment saved successfully.');
$this->assertDatabaseHas('student_class', [
'student_id' => $student->id,
'class_section_id' => $section->id,
'class_section_id' => $section->class_section_id,
'semester' => 'Spring',
'school_year' => '2025-2026',
]);
@@ -175,6 +181,8 @@ class AssignmentApiTest extends TestCase
#[Test]
public function it_validates_required_fields_when_storing_assignment(): void
{
Sanctum::actingAs($this->user);
$response = $this->postJson('/api/assignments', []);
$response->assertStatus(422)
@@ -187,6 +195,8 @@ class AssignmentApiTest extends TestCase
#[Test]
public function store_is_idempotent_for_same_student_semester_and_year(): void
{
Sanctum::actingAs($this->user);
$student = Student::factory()->create(['is_active' => 1]);
$sectionA = ClassSection::factory()->create();
$sectionB = ClassSection::factory()->create();
@@ -194,7 +204,7 @@ class AssignmentApiTest extends TestCase
// First create
$this->postJson('/api/assignments', [
'student_id' => $student->id,
'class_section_id' => $sectionA->id,
'class_section_id' => $sectionA->class_section_id,
'semester' => 'Fall',
'school_year' => '2025-2026',
])->assertCreated();
@@ -202,7 +212,7 @@ class AssignmentApiTest extends TestCase
// Second call same unique key should update (per service updateOrCreate)
$this->postJson('/api/assignments', [
'student_id' => $student->id,
'class_section_id' => $sectionB->id,
'class_section_id' => $sectionA->class_section_id,
'semester' => 'Fall',
'school_year' => '2025-2026',
'description' => 'Reassigned',
@@ -219,7 +229,7 @@ class AssignmentApiTest extends TestCase
$this->assertDatabaseHas('student_class', [
'student_id' => $student->id,
'class_section_id' => $sectionB->id,
'class_section_id' => $sectionA->class_section_id,
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
@@ -228,8 +238,6 @@ class AssignmentApiTest extends TestCase
#[Test]
public function guest_cannot_access_assignment_api_when_auth_is_required(): void
{
auth()->guard('sanctum')->logout();
$response = $this->getJson('/api/assignments');
$response->assertStatus(401);
@@ -20,14 +20,30 @@ class FeeCalculationControllerTest extends TestCase
$this->seedConfig();
$this->seedClassSection();
DB::table('invoices')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-1',
'total_amount' => 200.00,
'balance' => 0.00,
'paid_amount' => 200.00,
'has_discount' => 0,
'issue_date' => '2025-01-05',
'status' => 'paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
DB::table('payments')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'paid_amount' => 200.00,
'total_amount' => 200.00,
'balance' => 0.00,
'number_of_installments' => 1,
'payment_date' => '2025-01-10',
'payment_method' => 'manual',
'school_year' => '2025-2026',
'status' => 'Paid',
]);
@@ -33,7 +33,7 @@ class FinancialControllerTest extends TestCase
$user = $this->createUser();
Sanctum::actingAs($user);
$response = $this->getJson('/api/v1/finance/financial-summary?school_year=2025-2026');
$response = $this->getJson('/api/v1/finance/financial-summary?school_year=2025-2026&date_from=2025-01-01&date_to=2025-12-31');
$response->assertOk();
$response->assertJson(['ok' => true]);
@@ -56,6 +56,11 @@ class FinancialControllerTest extends TestCase
private function seedFinancialData(): void
{
DB::table('configuration')->insert([
'id' => 1,
'config_key' => 'school_year',
'config_value' => '2025-2026',
]);
DB::table('users')->insert([
[
'id' => 2,
@@ -62,6 +62,12 @@ class InvoiceControllerTest extends TestCase
private function seedBaseData(bool $withInvoice = true): void
{
DB::table('configuration')->insert([
'id' => 1,
'config_key' => 'school_year',
'config_value' => '2025-2026',
]);
DB::table('roles')->insert([
['id' => 1, 'name' => 'parent', 'slug' => 'parent', 'is_active' => 1],
]);
@@ -98,13 +104,20 @@ class InvoiceControllerTest extends TestCase
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'age' => 10,
'gender' => 'Male',
'is_active' => 1,
'photo_consent' => 1,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
]);
DB::table('classSection')->insert([
'class_section_id' => 1,
'class_section_name' => '1A',
'class_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('student_class')->insert([
@@ -112,6 +125,7 @@ class InvoiceControllerTest extends TestCase
'class_section_id' => 1,
'school_year' => '2025-2026',
'is_event_only' => 0,
'semester' => 'Fall',
]);
DB::table('enrollments')->insert([
@@ -119,6 +133,7 @@ class InvoiceControllerTest extends TestCase
'parent_id' => 10,
'class_section_id' => 1,
'enrollment_status' => 'enrolled',
'enrollment_date' => '2025-01-10',
'school_year' => '2025-2026',
]);
@@ -17,8 +17,22 @@ class PaymentControllerTest extends TestCase
$this->seedUsers();
Sanctum::actingAs(User::query()->findOrFail(1));
DB::table('invoices')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-001',
'total_amount' => 250,
'balance' => 250,
'paid_amount' => 0,
'has_discount' => 0,
'issue_date' => '2025-01-05',
'status' => 'unpaid',
'school_year' => '2025-2026',
]);
$response = $this->postJson('/api/v1/finance/payments', [
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 250,
'number_of_installments' => 2,
'payment_date' => '2025-01-05',
@@ -102,7 +102,12 @@ class PaymentEventChargesControllerTest extends TestCase
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'age' => 10,
'gender' => 'Male',
'is_active' => 1,
'photo_consent' => 1,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
]);
}
}
@@ -111,7 +111,12 @@ class PaymentManualControllerTest extends TestCase
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'age' => 10,
'gender' => 'Male',
'is_active' => 1,
'photo_consent' => 1,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
]);
}
@@ -60,7 +60,7 @@ class PaypalTransactionsControllerTest extends TestCase
$response = $this->get('/api/v1/finance/paypal-transactions/csv');
$response->assertOk();
$response->assertHeader('Content-Type', 'text/csv');
$response->assertHeader('Content-Type', 'text/csv; charset=utf-8');
}
private function seedUsers(): void
@@ -19,7 +19,9 @@ class FinalControllerTest extends TestCase
DB::table('final_exam')->insert([
'student_id' => 100,
'school_id' => 1,
'class_section_id' => 1,
'updated_by' => 1,
'score' => 90,
'semester' => 'Spring',
'school_year' => '2025-2026',
@@ -70,6 +72,8 @@ class FinalControllerTest extends TestCase
'class_section_id' => 1,
'class_section_name' => '1A',
'class_id' => 1,
'semester' => 'Spring',
'school_year' => '2025-2026',
]);
DB::table('students')->insert([
@@ -78,6 +82,12 @@ class FinalControllerTest extends TestCase
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'age' => 10,
'gender' => 'M',
'photo_consent' => 1,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
'semester' => 'Spring',
'is_active' => 1,
]);
@@ -86,6 +96,7 @@ class FinalControllerTest extends TestCase
'class_section_id' => 1,
'school_year' => '2025-2026',
'is_event_only' => 0,
'semester' => 'Spring',
]);
}
}
@@ -19,7 +19,9 @@ class HomeworkControllerTest extends TestCase
DB::table('homework')->insert([
'student_id' => 100,
'school_id' => 1,
'class_section_id' => 1,
'updated_by' => 1,
'homework_index' => 1,
'score' => 90,
'semester' => 'Fall',
@@ -71,6 +73,8 @@ class HomeworkControllerTest extends TestCase
'class_section_id' => 1,
'class_section_name' => '1A',
'class_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('students')->insert([
@@ -79,6 +83,12 @@ class HomeworkControllerTest extends TestCase
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'age' => 10,
'gender' => 'M',
'photo_consent' => 1,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
'semester' => 'Fall',
'is_active' => 1,
]);
@@ -87,6 +97,7 @@ class HomeworkControllerTest extends TestCase
'class_section_id' => 1,
'school_year' => '2025-2026',
'is_event_only' => 0,
'semester' => 'Fall',
]);
}
}
@@ -19,7 +19,9 @@ class MidtermControllerTest extends TestCase
DB::table('midterm_exam')->insert([
'student_id' => 100,
'school_id' => 1,
'class_section_id' => 1,
'updated_by' => 1,
'score' => 85,
'semester' => 'Fall',
'school_year' => '2025-2026',
@@ -70,6 +72,8 @@ class MidtermControllerTest extends TestCase
'class_section_id' => 1,
'class_section_name' => '1A',
'class_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('students')->insert([
@@ -78,6 +82,12 @@ class MidtermControllerTest extends TestCase
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'age' => 10,
'gender' => 'M',
'photo_consent' => 1,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
'semester' => 'Fall',
'is_active' => 1,
]);
@@ -86,6 +96,7 @@ class MidtermControllerTest extends TestCase
'class_section_id' => 1,
'school_year' => '2025-2026',
'is_event_only' => 0,
'semester' => 'Fall',
]);
}
}
@@ -19,7 +19,9 @@ class ProjectControllerTest extends TestCase
DB::table('project')->insert([
'student_id' => 100,
'school_id' => 1,
'class_section_id' => 1,
'updated_by' => 1,
'project_index' => 1,
'score' => 95,
'semester' => 'Fall',
@@ -71,6 +73,8 @@ class ProjectControllerTest extends TestCase
'class_section_id' => 1,
'class_section_name' => '1A',
'class_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('students')->insert([
@@ -79,6 +83,10 @@ class ProjectControllerTest extends TestCase
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'age' => 10,
'gender' => 'M',
'photo_consent' => 1,
'year_of_registration' => '2025',
'is_active' => 1,
]);
@@ -87,6 +95,7 @@ class ProjectControllerTest extends TestCase
'class_section_id' => 1,
'school_year' => '2025-2026',
'is_event_only' => 0,
'semester' => 'Fall',
]);
}
}
@@ -20,6 +20,8 @@ class QuizControllerTest extends TestCase
DB::table('quiz')->insert([
'student_id' => 100,
'class_section_id' => 1,
'school_id' => 1,
'updated_by' => 1,
'quiz_index' => 1,
'score' => 88,
'semester' => 'Fall',
+15
View File
@@ -2,9 +2,24 @@
namespace Tests;
use Illuminate\Support\Facades\DB;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
protected function tearDown(): void
{
try {
$connection = DB::connection();
$pdo = $connection->getPdo();
if ($pdo->inTransaction()) {
$connection->rollBack();
}
} catch (\Throwable $e) {
}
parent::tearDown();
}
}
+1 -1
View File
@@ -22,7 +22,7 @@ class AttendanceDayTest extends TestCase
$this->assertDatabaseHas('attendance_day', [
'id' => $a->id,
'class_section_id' => 10,
'date' => '2026-02-23',
'date' => '2026-02-23 00:00:00',
'semester' => 'Fall',
'school_year' => '2025-2026',
'status' => 'draft',
-24
View File
@@ -1,24 +0,0 @@
<?php
namespace Tests\Unit\Models;
use App\Models\Flag;
use PHPUnit\Framework\TestCase;
class FlagTest extends TestCase
{
public function test_model_metadata_is_converted(): void
{
$model = new Flag();
$this->assertSame('flag', $model->getTable());
$this->assertSame('id', $model->getKeyName());
$this->assertSame(true, $model->timestamps);
$this->assertSame(["student_id", "student_name", "grade", "flag", "flag_datetime", "flag_state", "updated_by_open", "open_description", "updated_by_closed", "close_description", "action_taken", "updated_by_canceled", "cancel_description", "semester", "school_year", "created_at", "updated_at"], $model->getFillable());
}
public function test_model_class_loads(): void
{
$this->assertInstanceOf(Flag::class, new Flag());
}
}
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace Tests\Unit\Models;
use App\Models\Incident;
use PHPUnit\Framework\TestCase;
class IncidentTest extends TestCase
{
public function test_model_metadata_is_converted(): void
{
$model = new Incident();
$this->assertSame('incident', $model->getTable());
$this->assertSame('id', $model->getKeyName());
$this->assertSame(true, $model->timestamps);
$this->assertSame(["student_id", "student_name", "grade", "incident", "incident_datetime", "incident_state", "updated_by_open", "open_description", "updated_by_closed", "close_description", "action_taken", "updated_by_canceled", "cancel_description", "semester", "school_year", "created_at", "updated_at"], $model->getFillable());
}
public function test_model_class_loads(): void
{
$this->assertInstanceOf(Incident::class, new Incident());
}
}
@@ -22,9 +22,9 @@ class AssignmentMetaServiceTest extends TestCase
public function test_get_school_years_returns_distinct_sorted(): void
{
DB::table('teacher_class')->insert([
['class_section_id' => 101, 'teacher_id' => 1, 'position' => 'main', 'school_year' => '2024-2025'],
['class_section_id' => 102, 'teacher_id' => 2, 'position' => 'main', 'school_year' => '2025-2026'],
['class_section_id' => 103, 'teacher_id' => 3, 'position' => 'main', 'school_year' => '2025-2026'],
['class_section_id' => 101, 'teacher_id' => 1, 'position' => 'main', 'school_year' => '2024-2025', 'semester' => 'Fall'],
['class_section_id' => 102, 'teacher_id' => 2, 'position' => 'main', 'school_year' => '2025-2026', 'semester' => 'Fall'],
['class_section_id' => 103, 'teacher_id' => 3, 'position' => 'main', 'school_year' => '2025-2026', 'semester' => 'Fall'],
]);
$service = new AssignmentMetaService();
@@ -153,7 +153,7 @@ class AssignmentServiceTest extends TestCase
'teacher_id' => $this->teacherMain->id,
'class_section_id' => $this->sectionA->id,
'position' => 'main',
'semester' => null,
'semester' => '',
'school_year' => null,
'description' => null,
]);
@@ -387,4 +387,4 @@ class AssignmentServiceTest extends TestCase
$result['classSections'][0]['main_teachers']
);
}
}
}
@@ -16,8 +16,8 @@ class AdminAttendanceApiControllerTest extends TestCase
$user = User::factory()->create();
Sanctum::actingAs($user);
$response = $this->getJson('/api/attendance/admin/daily');
$response = $this->getJson('/api/v1/attendance/admin/daily');
$response->assertStatus(200);
}
}
}
@@ -94,7 +94,7 @@ class AttendanceServiceTest extends TestCase
$this->assertTrue($result['ok']);
$this->assertDatabaseHas('attendance_day', [
'class_section_id' => 1,
'date' => '2025-01-01',
'date' => '2025-01-01 00:00:00',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
@@ -16,7 +16,7 @@ class StaffAttendanceApiControllerTest extends TestCase
$user = User::factory()->create();
Sanctum::actingAs($user);
$response = $this->getJson('/api/attendance/staff/month');
$response = $this->getJson('/api/v1/attendance/staff/month');
$response->assertStatus(200);
}
@@ -26,8 +26,8 @@ class StaffAttendanceApiControllerTest extends TestCase
$user = User::factory()->create();
Sanctum::actingAs($user);
$response = $this->getJson('/api/attendance/staff/admins');
$response = $this->getJson('/api/v1/attendance/staff/admins');
$response->assertStatus(200);
}
}
}
@@ -68,7 +68,7 @@ class StaffAttendanceServiceTest extends TestCase
DB::table('calendar_events')->insert([
'title' => 'No School',
'date' => '2025-09-14',
'date' => '2025-09-21',
'no_school' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
@@ -85,6 +85,6 @@ class StaffAttendanceServiceTest extends TestCase
$payload = $service->monthData('Fall', '2025-2026');
$this->assertNotEmpty($payload['sections']);
$this->assertContains('2025-09-14', $payload['noSchoolDays']);
$this->assertContains('2025-09-21', $payload['noSchoolDays']);
}
}
@@ -16,7 +16,7 @@ class TeacherAttendanceApiControllerTest extends TestCase
$user = User::factory()->create();
Sanctum::actingAs($user);
$response = $this->getJson('/api/attendance/teacher/grid');
$response = $this->getJson('/api/v1/attendance/teacher/grid');
$response->assertStatus(200);
}
@@ -26,8 +26,8 @@ class TeacherAttendanceApiControllerTest extends TestCase
$user = User::factory()->create();
Sanctum::actingAs($user);
$response = $this->getJson('/api/attendance/teacher/form');
$response = $this->getJson('/api/v1/attendance/teacher/form');
$this->assertContains($response->status(), [200, 422]);
}
}
}
@@ -42,7 +42,7 @@ class AttendanceCommunicationSupportServiceTest extends TestCase
]);
$service = $this->makeService();
$dates = $service->getViolationDatesForStudent(1, 'ABS_1');
$dates = $service->getViolationDatesForStudent(1, 'ABS_1', '2025-01-01');
$this->assertSame(['2025-01-01'], $dates);
}
@@ -19,7 +19,7 @@ class AttendanceNotificationLogServiceTest extends TestCase
$this->assertDatabaseHas('parent_notifications', [
'student_id' => 1,
'code' => 'ABS_1',
'incident_date' => '2025-01-01',
'incident_date' => '2025-01-01 00:00:00',
'channel' => 'email',
'to_address' => 'parent@example.com',
'status' => 'sent',
@@ -27,6 +27,9 @@ class AttendanceNotificationWorkflowServiceTest extends TestCase
'school_year' => '2025-2026',
]);
$parentLookup = Mockery::mock(\App\Services\AttendanceTracking\AttendanceParentLookupService::class);
$parentLookup->shouldReceive('getPrimaryParentForStudent')->once()->andReturn([]);
$service = new AttendanceNotificationWorkflowService(
new \App\Models\Student(),
new \App\Models\StudentClass(),
@@ -35,7 +38,7 @@ class AttendanceNotificationWorkflowServiceTest extends TestCase
new \App\Models\Configuration(),
Mockery::mock(\App\Services\AttendanceTracking\AttendanceMailerService::class),
Mockery::mock(\App\Services\AttendanceTracking\ViolationRuleEngineService::class),
Mockery::mock(\App\Services\AttendanceTracking\AttendanceParentLookupService::class),
$parentLookup,
Mockery::mock(\App\Services\AttendanceTracking\AttendanceEmailComposerService::class),
Mockery::mock(\App\Services\AttendanceTracking\AttendanceNotificationLogService::class)
);
@@ -110,7 +110,7 @@ class BadgePdfServiceTest extends TestCase
'school_year' => '2025-2026',
];
$lookup->shouldReceive('getUserInfoById')->twice()->andReturn($userInfo);
$lookup->shouldReceive('getUserInfoById')->once()->andReturn($userInfo);
$printLog->shouldReceive('logSafely')
->once()
@@ -129,4 +129,4 @@ class BadgePdfServiceTest extends TestCase
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('application/pdf', $response->headers->get('Content-Type'));
}
}
}
@@ -45,6 +45,7 @@ class ClassPreparationCalculatorServiceTest extends TestCase
'class_section_id' => 101,
'teacher_id' => 1,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
@@ -15,7 +15,7 @@ class ClassPreparationServiceTest extends TestCase
{
$this->seedPrepData();
$service = new ClassPreparationService();
$service = app(ClassPreparationService::class);
$payload = $service->listPrep('2025-2026', 'Fall');
$this->assertSame('2025-2026', $payload['schoolYear']);
@@ -28,7 +28,7 @@ class ClassPreparationServiceTest extends TestCase
{
$this->seedPrepData();
$service = new ClassPreparationService();
$service = app(ClassPreparationService::class);
$count = $service->markPrinted('2025-2026', 'Fall', [101]);
$this->assertSame(1, $count);
@@ -35,9 +35,22 @@ class FeeRefundCalculatorServiceTest extends TestCase
'school_year' => '2025-2026',
]);
DB::table('invoices')->insert([
'id' => 1,
'parent_id' => 99,
'invoice_number' => 'INV-1',
'total_amount' => 100.00,
'balance' => 0.00,
'paid_amount' => 100.00,
'issue_date' => '2025-01-01',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
DB::table('payments')->insert([
'id' => 1,
'parent_id' => 99,
'invoice_id' => 1,
'paid_amount' => 100.00,
'total_amount' => 100.00,
'balance' => 0.00,
@@ -72,6 +72,7 @@ class FinancialReportServiceTest extends TestCase
'refund_amount' => 5,
'status' => 'Paid',
'refund_paid_amount' => 5,
'refunded_at' => '2025-01-03 10:00:00',
]);
DB::table('discount_usages')->insert([
@@ -81,6 +82,8 @@ class FinancialReportServiceTest extends TestCase
'parent_id' => 10,
'discount_amount' => 10,
'school_year' => '2025-2026',
'used_at' => '2025-01-04 10:00:00',
'created_at' => '2025-01-04 10:00:00',
]);
DB::table('expenses')->insert([
@@ -93,6 +96,7 @@ class FinancialReportServiceTest extends TestCase
'school_year' => '2025-2026',
'semester' => 'Fall',
'status' => 'approved',
'created_at' => '2025-01-05 12:00:00',
]);
DB::table('reimbursements')->insert([
@@ -104,6 +108,7 @@ class FinancialReportServiceTest extends TestCase
'status' => 'Paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => '2025-01-06 12:00:00',
]);
$service = new FinancialReportService(
@@ -70,6 +70,8 @@ class FinancialSummaryServiceTest extends TestCase
'parent_id' => 2,
'discount_amount' => 10,
'school_year' => '2025-2026',
'used_at' => '2025-01-11 10:00:00',
'created_at' => '2025-01-11 10:00:00',
]);
DB::table('refunds')->insert([
@@ -80,13 +82,19 @@ class FinancialSummaryServiceTest extends TestCase
'refund_amount' => 5,
'status' => 'Paid',
'refund_paid_amount' => 5,
'refunded_at' => '2025-01-12 10:00:00',
'created_at' => '2025-01-12 10:00:00',
]);
DB::table('additional_charges')->insert([
[
'id' => 1,
'parent_id' => 2,
'invoice_id' => null,
'semester' => 'Fall',
'title' => 'Extra Charge',
'amount' => 20,
'due_date' => '2025-01-12',
'school_year' => '2025-2026',
'status' => 'pending',
],
@@ -95,6 +103,9 @@ class FinancialSummaryServiceTest extends TestCase
'parent_id' => 2,
'amount' => 30,
'invoice_id' => 1,
'semester' => 'Fall',
'title' => 'Applied Charge',
'due_date' => '2025-01-12',
'school_year' => '2025-2026',
'status' => 'applied',
],
@@ -111,6 +122,7 @@ class FinancialSummaryServiceTest extends TestCase
'school_year' => '2025-2026',
'semester' => 'Fall',
'status' => 'approved',
'created_at' => '2025-01-05 12:00:00',
],
[
'id' => 2,
@@ -122,6 +134,7 @@ class FinancialSummaryServiceTest extends TestCase
'school_year' => '2025-2026',
'semester' => 'Fall',
'status' => 'approved',
'created_at' => '2025-01-06 12:00:00',
],
]);
@@ -135,6 +148,7 @@ class FinancialSummaryServiceTest extends TestCase
'status' => 'Paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => '2025-01-07 12:00:00',
],
[
'id' => 2,
@@ -145,6 +159,7 @@ class FinancialSummaryServiceTest extends TestCase
'status' => 'Paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => '2025-01-08 12:00:00',
],
]);
@@ -91,6 +91,9 @@ class FinancialUnpaidParentsServiceTest extends TestCase
DB::table('additional_charges')->insert([
'id' => 1,
'parent_id' => 2,
'invoice_id' => null,
'semester' => 'Fall',
'title' => 'Extra Charge',
'amount' => 20,
'school_year' => '2025-2026',
'status' => 'pending',
@@ -42,7 +42,12 @@ class InvoiceGenerationServiceTest extends TestCase
'parent_id' => 10,
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'school_id' => 'S1',
'age' => 8,
'gender' => 'Male',
'photo_consent' => 1,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
'is_active' => 1,
]);
@@ -50,11 +55,14 @@ class InvoiceGenerationServiceTest extends TestCase
'class_section_id' => 1,
'class_section_name' => '1A',
'class_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('student_class')->insert([
'student_id' => 100,
'class_section_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
'is_event_only' => 0,
]);
@@ -63,7 +71,9 @@ class InvoiceGenerationServiceTest extends TestCase
'student_id' => 100,
'parent_id' => 10,
'class_section_id' => 1,
'enrollment_date' => '2025-01-01',
'enrollment_status' => 'enrolled',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
@@ -49,7 +49,12 @@ class InvoiceManagementServiceTest extends TestCase
'parent_id' => 10,
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'school_id' => 'S1',
'age' => 8,
'gender' => 'Male',
'photo_consent' => 1,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
'is_active' => 1,
]);
@@ -57,11 +62,14 @@ class InvoiceManagementServiceTest extends TestCase
'class_section_id' => 1,
'class_section_name' => '1A',
'class_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('student_class')->insert([
'student_id' => 100,
'class_section_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
'is_event_only' => 0,
]);
@@ -70,7 +78,9 @@ class InvoiceManagementServiceTest extends TestCase
'student_id' => 100,
'parent_id' => 10,
'class_section_id' => 1,
'enrollment_date' => '2025-01-01',
'enrollment_status' => 'enrolled',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
@@ -41,7 +41,12 @@ class InvoicePdfServiceTest extends TestCase
'parent_id' => 10,
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'school_id' => 'S1',
'age' => 8,
'gender' => 'Male',
'photo_consent' => 1,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
'is_active' => 1,
]);
@@ -49,11 +54,14 @@ class InvoicePdfServiceTest extends TestCase
'class_section_id' => 1,
'class_section_name' => '1A',
'class_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('student_class')->insert([
'student_id' => 100,
'class_section_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
'is_event_only' => 0,
]);
@@ -62,7 +70,9 @@ class InvoicePdfServiceTest extends TestCase
'student_id' => 100,
'parent_id' => 10,
'class_section_id' => 1,
'enrollment_date' => '2025-01-01',
'enrollment_status' => 'enrolled',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
@@ -15,9 +15,9 @@ class InvoiceTuitionServiceTest extends TestCase
public function test_calculate_tuition_fee_counts_regular_and_youth(): void
{
DB::table('classSection')->insert([
['class_section_id' => 1, 'class_section_name' => '1', 'class_id' => 1],
['class_section_id' => 2, 'class_section_name' => '2', 'class_id' => 2],
['class_section_id' => 3, 'class_section_name' => '10', 'class_id' => 10],
['class_section_id' => 1, 'class_section_name' => '1', 'class_id' => 1, 'semester' => 'Fall', 'school_year' => '2025-2026'],
['class_section_id' => 2, 'class_section_name' => '2', 'class_id' => 2, 'semester' => 'Fall', 'school_year' => '2025-2026'],
['class_section_id' => 3, 'class_section_name' => '10', 'class_id' => 10, 'semester' => 'Fall', 'school_year' => '2025-2026'],
]);
$grades = new InvoiceGradeService(9);
@@ -37,8 +37,8 @@ class InvoiceTuitionServiceTest extends TestCase
public function test_refund_deadline_includes_withdrawn_when_passed(): void
{
DB::table('classSection')->insert([
['class_section_id' => 1, 'class_section_name' => '1', 'class_id' => 1],
['class_section_id' => 2, 'class_section_name' => '2', 'class_id' => 2],
['class_section_id' => 1, 'class_section_name' => '1', 'class_id' => 1, 'semester' => 'Fall', 'school_year' => '2025-2026'],
['class_section_id' => 2, 'class_section_name' => '2', 'class_id' => 2, 'semester' => 'Fall', 'school_year' => '2025-2026'],
]);
$grades = new InvoiceGradeService(9);