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',