fix parent pages and teachers and admin
API CI/CD / Validate (composer + pint) (push) Successful in 3m8s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Test (PHPUnit) (push) Failing after 6m5s
API CI/CD / Security audit (push) Failing after 52s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped

This commit is contained in:
root
2026-07-09 13:56:22 -04:00
parent 21c9322127
commit 02ba2fe6b6
34 changed files with 2306 additions and 99 deletions
@@ -9,7 +9,9 @@ use App\Models\TeacherSubmissionNotificationHistory;
use App\Models\User;
use App\Services\Administrator\AdministratorSharedService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
@@ -290,6 +292,57 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
$this->assertSame('Main: Legacy Teacher', $response->json('rows.0.teachers.0.label'));
}
public function test_teacher_submission_report_handles_student_class_without_semester_column(): void
{
Schema::table('student_class', function (Blueprint $table) {
$table->dropColumn('semester');
});
$admin = $this->seedAdminUser('admin.report.student-class-legacy@test.com');
Sanctum::actingAs($admin, [], 'api');
User::factory()->create([
'id' => 220,
'firstname' => 'StudentClass',
'lastname' => 'Legacy',
'email' => 'student.class.legacy.teacher@test.com',
]);
DB::table('classSection')->insert([
[
'class_section_id' => 22,
'class_section_name' => 'Grade 9A',
'class_id' => 9,
'semester' => 'Fall',
'school_year' => '2025-2026',
],
]);
DB::table('teacher_class')->insert([
[
'class_section_id' => 22,
'teacher_id' => 220,
'position' => 'main',
'school_year' => '2025-2026',
'semester' => 'Fall',
],
]);
DB::table('student_class')->insert([
'student_id' => 1,
'class_section_id' => 22,
'school_year' => '2025-2026',
]);
$response = $this->getJson('/api/v1/administrator/teacher-submissions?school_year=2025-2026');
$response->assertOk()
->assertJsonCount(1, 'rows');
$this->assertSame('Grade 9A', $response->json('rows.0.class_section'));
$this->assertSame(1, $response->json('rows.0.student_count'));
}
public function test_teacher_submission_report_limits_history_to_three_entries(): void
{
$admin = $this->seedAdminUser('admin.report.two@test.com', 901, 'Admin', 'Two');
@@ -73,6 +73,23 @@ class ClassProgressControllerTest extends TestCase
'created_at' => now(),
'updated_at' => now(),
]);
DB::table('classSection')->insert([
'id' => 8,
'class_id' => 8,
'class_section_id' => 808,
'class_section_name' => '8-A',
'semester' => 'Fall',
'school_year' => '2024-2025',
]);
DB::table('teacher_class')->insert([
'class_section_id' => 808,
'teacher_id' => $user->id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2024-2025',
'created_at' => now(),
'updated_at' => now(),
]);
DB::table('subject_curriculum_items')->insert([
'class_id' => 9,
'school_year' => null,
@@ -83,6 +100,16 @@ class ClassProgressControllerTest extends TestCase
'created_at' => now(),
'updated_at' => now(),
]);
DB::table('subject_curriculum_items')->insert([
'class_id' => 9,
'school_year' => null,
'subject' => 'Quran/Arabic',
'unit_number' => 2,
'unit_title' => 'Surah Review',
'chapter_name' => 'Al-Fatiha',
'created_at' => now(),
'updated_at' => now(),
]);
Sanctum::actingAs($user);
@@ -93,8 +120,12 @@ class ClassProgressControllerTest extends TestCase
$response->assertJsonPath('data.defaults.school_year', '2025-2026');
$response->assertJsonPath('data.defaults.semester', 'Fall');
$response->assertJsonPath('data.defaults.class_section_id', 909);
$this->assertCount(1, $response->json('data.classes'));
$response->assertJsonPath('data.classes.0.class_section_id', 909);
$response->assertJsonPath('data.curriculum.islamic.0.chapter_name', 'Intro');
$response->assertJsonPath('data.unit_options.islamic.0.label', 'Unit 1 - Faith');
$response->assertJsonPath('data.curriculum.quran.0.chapter_name', 'Al-Fatiha');
$response->assertJsonPath('data.unit_options.quran.0.label', 'Unit 2 - Surah Review');
}
public function test_index_returns_paginated_reports(): void
@@ -115,10 +146,184 @@ class ClassProgressControllerTest extends TestCase
$this->assertCount(2, $response->json('data.items'));
}
public function test_teacher_history_is_scoped_to_assigned_class_sections(): void
{
$teacher = $this->createUser();
$otherTeacher = $this->createUser('other-history-teacher@example.com');
$this->assignRole($teacher->id, 'teacher');
$this->seedClassSection();
DB::table('classSection')->insert([
'id' => 2,
'class_id' => 2,
'class_section_id' => 202,
'class_section_name' => '2-A',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
$this->assignTeacher($teacher->id, 1);
$this->assignTeacher($teacher->id, 202);
$assignedOwnReport = ClassProgressReport::factory()->create([
'teacher_id' => $teacher->id,
'class_section_id' => 101,
'school_year' => '2025-2026',
'week_start' => '2025-09-07',
]);
$assignedSectionReport = ClassProgressReport::factory()->create([
'teacher_id' => $otherTeacher->id,
'class_section_id' => 101,
'school_year' => '2025-2026',
'week_start' => '2025-09-14',
]);
$otherSectionReport = ClassProgressReport::factory()->create([
'teacher_id' => $teacher->id,
'class_section_id' => 202,
'school_year' => '2025-2026',
'week_start' => '2025-09-21',
]);
Sanctum::actingAs($teacher);
$response = $this->getJson('/api/v1/teacher/class-progress-history?school_year=2025-2026&class_section_id=1');
$response->assertOk();
$ids = collect($response->json('data.items'))->pluck('id')->all();
$this->assertContains($assignedOwnReport->id, $ids);
$this->assertContains($assignedSectionReport->id, $ids);
$this->assertNotContains($otherSectionReport->id, $ids);
$detailResponse = $this->getJson('/api/v1/class-progress/'.$assignedSectionReport->id);
$detailResponse->assertOk();
$detailResponse->assertJsonPath('data.report.id', $assignedSectionReport->id);
$unfilteredResponse = $this
->withSession(['class_section_id' => 202])
->getJson('/api/v1/teacher/class-progress-history?school_year=2025-2026');
$unfilteredResponse->assertOk();
$unfilteredIds = collect($unfilteredResponse->json('data.items'))->pluck('id')->all();
$this->assertNotContains($assignedOwnReport->id, $unfilteredIds);
$this->assertNotContains($assignedSectionReport->id, $unfilteredIds);
$this->assertContains($otherSectionReport->id, $unfilteredIds);
}
public function test_teacher_history_accepts_legacy_progress_rows_saved_with_section_pk(): void
{
$teacher = $this->createUser();
$otherTeacher = $this->createUser('legacy-pk-history-teacher@example.com');
$this->assignRole($teacher->id, 'teacher_assistant');
$this->seedClassSection();
$this->assignTeacher($teacher->id, 101);
$legacyPkReport = ClassProgressReport::factory()->create([
'teacher_id' => $otherTeacher->id,
'class_section_id' => 1,
'school_year' => '2025-2026',
'week_start' => '2025-09-28',
]);
Sanctum::actingAs($teacher);
$response = $this->getJson('/api/v1/teacher/class-progress-history?school_year=2025-2026&class_section_id=101');
$response->assertOk();
$ids = collect($response->json('data.items'))->pluck('id')->all();
$this->assertContains($legacyPkReport->id, $ids);
}
public function test_teacher_history_without_section_uses_logged_in_teacher_assignment(): void
{
$teacher = $this->createUser();
$otherTeacher = $this->createUser('assignment-history-teacher@example.com');
$this->assignRole($teacher->id, 'teacher');
$this->seedClassSection();
DB::table('classSection')->insert([
'id' => 2,
'class_id' => 2,
'class_section_id' => 202,
'class_section_name' => '2-A',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
$this->assignTeacher($teacher->id, 1);
$sameSectionReport = ClassProgressReport::factory()->create([
'teacher_id' => $otherTeacher->id,
'class_section_id' => 101,
'school_year' => '2025-2026',
'week_start' => '2025-10-05',
]);
$wrongSectionReport = ClassProgressReport::factory()->create([
'teacher_id' => $otherTeacher->id,
'class_section_id' => 202,
'school_year' => '2025-2026',
'week_start' => '2025-10-12',
]);
Sanctum::actingAs($teacher);
$response = $this->getJson('/api/v1/teacher/class-progress-history?school_year=2025-2026');
$response->assertOk();
$ids = collect($response->json('data.items'))->pluck('id')->all();
$this->assertContains($sameSectionReport->id, $ids);
$this->assertNotContains($wrongSectionReport->id, $ids);
}
public function test_teacher_history_without_section_does_not_422_for_multiple_assignments(): void
{
$teacher = $this->createUser();
$otherTeacher = $this->createUser('multi-assignment-history-teacher@example.com');
$this->assignRole($teacher->id, 'teacher');
$this->seedClassSection();
DB::table('classSection')->insert([
'id' => 2,
'class_id' => 2,
'class_section_id' => 202,
'class_section_name' => '2-A',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
$this->assignTeacher($teacher->id, 1);
$this->assignTeacher($teacher->id, 202);
$primarySectionReport = ClassProgressReport::factory()->create([
'teacher_id' => $otherTeacher->id,
'class_section_id' => 101,
'school_year' => '2025-2026',
'week_start' => '2025-10-19',
]);
$otherSectionReport = ClassProgressReport::factory()->create([
'teacher_id' => $otherTeacher->id,
'class_section_id' => 202,
'school_year' => '2025-2026',
'week_start' => '2025-10-26',
]);
Sanctum::actingAs($teacher);
$response = $this->getJson('/api/v1/teacher/class-progress-history?school_year=2025-2026&per_page=100&sort_by=week_start&sort_dir=desc');
$response->assertOk();
$ids = collect($response->json('data.items'))->pluck('id')->all();
$this->assertContains($primarySectionReport->id, $ids);
$this->assertNotContains($otherSectionReport->id, $ids);
}
public function test_admin_grouped_index_uses_school_year_name_and_includes_legacy_rows(): void
{
$admin = $this->createUser('admin@example.com');
$this->assignRole($admin->id, 'administrator');
DB::table('configuration')->updateOrInsert(
['config_key' => 'semester'],
['config_value' => 'Fall']
);
$this->seedClassSection();
DB::table('classSection')->where('class_section_id', 101)->update([
'semester' => '',
@@ -286,6 +491,74 @@ class ClassProgressControllerTest extends TestCase
$this->assertDatabaseCount('class_progress_reports', 2);
}
public function test_teacher_store_uses_logged_in_teacher_assignment_for_section(): void
{
Storage::fake('public');
$user = $this->createUser();
$this->assignRole($user->id, 'teacher');
$this->seedClassSection();
DB::table('classSection')->insert([
'id' => 2,
'class_id' => 2,
'class_section_id' => 202,
'class_section_name' => '2-A',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
$this->assignTeacher($user->id, 101);
Sanctum::actingAs($user);
$payload = [
'class_section_id' => 202,
'week_start' => '2025-09-07',
'week_end' => '2025-09-13',
'covered_islamic' => 'Lesson A',
'covered_quran' => 'Lesson B',
'unit_islamic' => ['Unit 1'],
'chapter_islamic' => ['Chapter A'],
'school_year' => '2025-2026',
];
$response = $this->postJson('/api/v1/teacher/class-progress-submit', $payload);
$response->assertStatus(201);
$this->assertDatabaseHas('class_progress_reports', [
'teacher_id' => $user->id,
'class_section_id' => 101,
'subject' => 'Islamic Studies',
]);
$this->assertDatabaseMissing('class_progress_reports', [
'teacher_id' => $user->id,
'class_section_id' => 202,
]);
}
public function test_teacher_store_without_section_uses_logged_in_teacher_assignment(): void
{
Storage::fake('public');
$user = $this->createUser();
$this->assignRole($user->id, 'teacher');
$this->seedClassSection();
$this->assignTeacher($user->id, 101);
Sanctum::actingAs($user);
$response = $this->postJson('/api/v1/teacher/class-progress-submit', [
'week_start' => '2025-09-07',
'week_end' => '2025-09-13',
'covered_islamic' => 'Lesson A',
'unit_islamic' => ['Unit 1'],
'chapter_islamic' => ['Chapter A'],
'school_year' => '2025-2026',
]);
$response->assertStatus(201);
$this->assertDatabaseHas('class_progress_reports', [
'teacher_id' => $user->id,
'class_section_id' => 101,
'subject' => 'Islamic Studies',
]);
}
public function test_show_returns_weekly_reports(): void
{
$user = $this->createUser();
@@ -45,6 +45,21 @@ class CompetitionScoresControllerTest extends TestCase
$this->assertSame(20, $response->json('questionCount'));
}
public function test_teacher_edit_alias_returns_students_and_scores(): void
{
$this->seedCompetitionData();
$user = $this->createUser();
Sanctum::actingAs($user);
$response = $this->getJson('/api/v1/teacher/competition-scores/1?school_year=2025-2026');
$response->assertOk();
$this->assertNotEmpty($response->json('students'));
$this->assertSame(5, $response->json('scoreMap.1'));
$this->assertSame(20, $response->json('questionCount'));
}
public function test_save_updates_scores(): void
{
$this->seedCompetitionData();
@@ -72,6 +87,33 @@ class CompetitionScoresControllerTest extends TestCase
]);
}
public function test_teacher_save_alias_updates_scores(): void
{
$this->seedCompetitionData();
$user = $this->createUser();
Sanctum::actingAs($user);
$response = $this->postJson('/api/v1/teacher/competition-scores/1', [
'class_section_id' => 101,
'scores' => [
1 => 12,
],
]);
$response->assertOk();
$response->assertJson([
'ok' => true,
]);
$this->assertDatabaseHas('competition_scores', [
'competition_id' => 1,
'student_id' => 1,
'class_section_id' => 101,
'score' => 12,
]);
}
private function seedCompetitionData(): void
{
DB::table('configuration')->updateOrInsert(
@@ -27,6 +27,112 @@ class PaymentManualControllerTest extends TestCase
$this->assertSame(10, $response->json('parent.id'));
}
public function test_search_returns_parent_data_by_selected_name(): void
{
$this->seedUsers();
$this->seedConfig();
$this->seedStudent();
$this->seedInvoice();
Sanctum::actingAs(User::query()->findOrFail(1));
$response = $this->getJson('/api/v1/finance/manual-pay/search?search_term=Parent+User&school_year=2025-2026');
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertSame(10, $response->json('parent.id'));
$this->assertNotEmpty($response->json('students'));
$this->assertNotEmpty($response->json('invoices'));
}
public function test_search_lists_multiple_parent_matches_alphabetically(): void
{
$this->seedUsers();
$this->seedConfig();
Sanctum::actingAs(User::query()->findOrFail(1));
DB::table('users')->insert([
[
'id' => 11,
'school_id' => 1,
'firstname' => 'Zara',
'lastname' => 'Akter',
'cellphone' => '5555555556',
'email' => 'zara.akter@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
],
[
'id' => 12,
'school_id' => 1,
'firstname' => 'Mousumi',
'lastname' => 'Akter',
'cellphone' => '5555555557',
'email' => 'mousumi.akter@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
],
[
'id' => 13,
'school_id' => 1,
'firstname' => 'Aisha',
'lastname' => 'Akter',
'cellphone' => '5555555558',
'email' => 'aisha.akter@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
],
]);
DB::table('user_roles')->insert([
['user_id' => 11, 'role_id' => 2],
['user_id' => 12, 'role_id' => 2],
['user_id' => 13, 'role_id' => 2],
]);
$response = $this->getJson('/api/v1/finance/manual-pay/search?search_term=akter&school_year=2025-2026');
$response->assertOk();
$this->assertSame([
'Aisha Akter',
'Mousumi Akter',
'Zara Akter',
], array_map(
fn (array $parent) => $parent['firstname'].' '.$parent['lastname'],
$response->json('parent_matches')
));
$this->assertSame(13, $response->json('parent.id'));
}
public function test_suggest_returns_items(): void
{
$this->seedUsers();
@@ -103,6 +103,52 @@ class ParentControllerTest extends TestCase
$this->assertDatabaseHas('emergency_contacts', ['parent_id' => $parent->id, 'emergency_contact_name' => 'John Parent']);
}
public function test_statement_returns_parent_account_and_invoice_lines(): void
{
$this->seedConfig();
$parent = $this->seedParent();
DB::table('parent_accounts')->insert([
'parent_id' => $parent->id,
'school_year' => '2025-2026',
'opening_balance' => 25,
'current_balance' => 125,
'created_at' => now(),
'updated_at' => now(),
]);
DB::table('invoices')->insert([
'parent_id' => $parent->id,
'invoice_number' => 'INV-2025-001',
'total_amount' => 150,
'paid_amount' => 50,
'balance' => 100,
'has_discount' => 0,
'issue_date' => now(),
'due_date' => now()->addWeek(),
'status' => 'unpaid',
'description' => 'Tuition invoice',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
]);
Sanctum::actingAs($parent);
$response = $this->getJson('/api/v1/parents/statements?school_year=2025-2026');
$response->assertOk()
->assertJsonPath('ok', true)
->assertJsonPath('data.parent_id', $parent->id)
->assertJsonPath('data.parent_name', 'Parent User')
->assertJsonPath('data.school_year', '2025-2026')
->assertJsonPath('data.opening_balance', 25)
->assertJsonPath('data.current_balance', 125)
->assertJsonPath('data.lines.0.label', 'Tuition invoice')
->assertJsonPath('data.lines.0.amount', 100)
->assertJsonPath('data.lines.0.source_school_year', '2025-2026');
}
private function seedParent(): User
{
$roleId = DB::table('roles')->insertGetId([
@@ -5,6 +5,7 @@ namespace Tests\Feature\Api\V1\Reports;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
@@ -72,6 +73,93 @@ class FilesControllerTest extends TestCase
$response->assertHeader('Content-Disposition', 'inline; filename="1a_midterm_v2.pdf"');
}
public function test_exam_draft_final_streams_when_requested_by_draft_id(): void
{
$user = $this->seedUser();
Sanctum::actingAs($user);
DB::table('classSection')->insert([
'id' => 1,
'class_section_id' => 1,
'class_section_name' => '1A',
'class_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('exam_drafts')->insert([
'id' => 1,
'teacher_id' => 1,
'class_section_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
'exam_type' => 'Final Exam',
'draft_title' => 'Final',
'teacher_file' => 'draft1.pdf',
'final_file' => 'final1.pdf',
'version' => 3,
'status' => 'finalized',
]);
$dir = storage_path('uploads/exams/finals');
if (! is_dir($dir)) {
mkdir($dir, 0777, true);
}
$path = $dir.DIRECTORY_SEPARATOR.'final1.pdf';
file_put_contents($path, 'PDFDATA');
$response = $this->get('/api/v1/files/exams/final/1');
$response->assertOk();
$response->assertHeader('Content-Disposition', 'inline; filename="1a_final_exam_v3.pdf"');
}
public function test_exam_draft_final_ignores_numeric_final_pdf_placeholder(): void
{
$user = $this->seedUser();
Sanctum::actingAs($user);
DB::table('classSection')->insert([
'id' => 1,
'class_section_id' => 1,
'class_section_name' => '1A',
'class_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
$payload = [
'id' => 1,
'teacher_id' => 1,
'class_section_id' => 1,
'semester' => 'Fall',
'school_year' => '2025-2026',
'exam_type' => 'Final Exam',
'draft_title' => 'Final',
'teacher_file' => 'draft1.pdf',
'final_file' => 'final1.pdf',
'version' => 3,
'status' => 'finalized',
];
if (Schema::hasColumn('exam_drafts', 'final_pdf_file')) {
$payload['final_pdf_file'] = '1';
}
DB::table('exam_drafts')->insert($payload);
$dir = storage_path('uploads/exams/finals');
if (! is_dir($dir)) {
mkdir($dir, 0777, true);
}
$path = $dir.DIRECTORY_SEPARATOR.'final1.pdf';
file_put_contents($path, 'PDFDATA');
$response = $this->get('/api/v1/files/exams/final/1');
$response->assertOk();
$response->assertHeader('Content-Disposition', 'inline; filename="1a_final_exam_v3.pdf"');
}
private function seedUser(): User
{
DB::table('users')->insert([
@@ -152,28 +152,49 @@ class SchoolYearControllerTest extends TestCase
$this->assertSame([502], $row['credit_invoice_ids']);
}
public function test_credit_only_parent_is_reported_as_credit_not_unpaid_carryover(): void
public function test_parent_balance_report_uses_only_positive_invoice_balances(): void
{
$this->seedClosureData();
$this->seedParent(12, 'Credit', 'Only', 'credit@example.com');
$this->seedParent(13, 'Discount', 'Paid', 'discount-paid@example.com');
DB::table('invoices')->insert([
'id' => 503,
'parent_id' => 12,
'invoice_number' => 'INV-503-CREDIT',
'total_amount' => 0,
'balance' => -50,
'paid_amount' => 50,
'has_discount' => 0,
'issue_date' => '2026-05-11',
'due_date' => '2026-06-10',
'status' => 'credit',
'description' => 'Credit only',
'school_year' => '2025-2026',
'created_at' => now(),
'updated_at' => now(),
'updated_by' => 1,
'semester' => 'Fall',
[
'id' => 503,
'parent_id' => 12,
'invoice_number' => 'INV-503-CREDIT',
'total_amount' => 0,
'balance' => -50,
'paid_amount' => 50,
'has_discount' => 0,
'issue_date' => '2026-05-11',
'due_date' => '2026-06-10',
'status' => 'credit',
'description' => 'Credit only',
'school_year' => '2025-2026',
'created_at' => now(),
'updated_at' => now(),
'updated_by' => 1,
'semester' => 'Fall',
],
[
'id' => 505,
'parent_id' => 13,
'invoice_number' => 'INV-505-DISCOUNT-PAID',
'total_amount' => 500,
'balance' => 0,
'paid_amount' => 500,
'has_discount' => 1,
'issue_date' => '2026-05-11',
'due_date' => '2026-06-10',
'status' => 'paid',
'description' => 'Discount paid invoice',
'school_year' => '2025-2026',
'created_at' => now(),
'updated_at' => now(),
'updated_by' => 1,
'semester' => 'Fall',
],
]);
$this->actingAs(User::query()->findOrFail(1), 'api');
@@ -182,18 +203,53 @@ class SchoolYearControllerTest extends TestCase
$response->assertOk()
->assertJsonPath('data.summary.parents_with_positive_balance', 1)
->assertJsonPath('data.summary.parents_with_credit_balance', 1)
->assertJsonPath('data.summary.parents_with_credit_balance', 0)
->assertJsonPath('data.summary.total_positive_unpaid_balance', 200)
->assertJsonPath('data.summary.total_credit_balance', 50);
->assertJsonPath('data.summary.total_credit_balance', 0)
->assertJsonPath('data.summary.parent_count', 1)
->assertJsonPath('data.summary.total_transferred', 200);
$creditRow = collect($response->json('data.rows'))
->first(fn (array $row): bool => (int) $row['parent_id'] === 12);
$rows = collect($response->json('data.rows'));
$this->assertNotNull($creditRow);
$this->assertSame(0.0, (float) $creditRow['positive_unpaid_balance']);
$this->assertSame(50.0, (float) $creditRow['credit_balance']);
$this->assertSame(0.0, (float) $creditRow['amount_to_transfer']);
$this->assertSame([503], $creditRow['credit_invoice_ids']);
$this->assertTrue($rows->contains(fn (array $row): bool => (int) $row['parent_id'] === 10));
$this->assertSame(200.0, (float) $rows->first(fn (array $row): bool => (int) $row['parent_id'] === 10)['old_unpaid_amount']);
$this->assertFalse($rows->contains(fn (array $row): bool => (int) $row['parent_id'] === 12));
$this->assertFalse($rows->contains(fn (array $row): bool => (int) $row['parent_id'] === 13));
}
public function test_closing_report_unpaid_balance_totals_are_recomputed_from_positive_invoice_balances(): void
{
$this->seedClosureData();
DB::table('school_years')->where('id', 1)->update([
'status' => 'closed',
'closed_at' => now(),
'closed_by' => 1,
]);
DB::table('audit_logs')->insert([
'user_id' => 1,
'action' => 'school_year_closed',
'table_name' => 'school_years',
'record_id' => 1,
'old_value' => null,
'new_value' => null,
'metadata' => json_encode([
'new_school_year' => '2026-2027',
'balance_counts' => [
'transferred_parents' => 48,
'transferred_amount' => 9999,
],
]),
'created_at' => now(),
]);
$this->actingAs(User::query()->findOrFail(1), 'api');
$this->getJson('/api/v1/school-years/reports/closing?school_year=2025-2026')
->assertOk()
->assertJsonPath('data.totals.parents_with_unpaid_balances', 1)
->assertJsonPath('data.totals.total_unpaid_balance_transferred', 200);
}
public function test_pending_or_draft_invoice_blocks_close_but_is_not_transferred(): void
@@ -567,6 +623,139 @@ class SchoolYearControllerTest extends TestCase
]);
}
public function test_passing_age_17_student_graduates_and_is_not_enrolled_next_year(): void
{
$this->seedClosureData();
DB::table('students')->where('id', 100)->update(['age' => 17]);
$this->actingAs(User::query()->findOrFail(1), 'api');
$preview = $this->postJson('/api/v1/school-years/1/preview-close', [
'new_school_year' => [
'name' => '2026-2027',
'start_date' => '2026-09-01',
'end_date' => '2027-06-30',
],
'transfer_unpaid_balances' => true,
]);
$preview->assertOk()
->assertJsonPath('data.promotion_preview.summary.promote', 0)
->assertJsonPath('data.promotion_preview.summary.graduate', 1)
->assertJsonPath('data.promotion_preview.rows.0.promotion_action', 'graduate');
$this->postJson('/api/v1/school-years/1/close', [
'new_school_year' => [
'name' => '2026-2027',
'start_date' => '2026-09-01',
'end_date' => '2027-06-30',
],
'transfer_unpaid_balances' => true,
'confirmation' => 'CLOSE 2025-2026',
])->assertOk();
$this->assertDatabaseMissing('enrollments', [
'student_id' => 100,
'school_year' => '2026-2027',
]);
$this->assertDatabaseMissing('student_class', [
'student_id' => 100,
'school_year' => '2026-2027',
]);
}
public function test_kindergarten_student_age_six_next_year_promotes_to_grade_one_not_arabic(): void
{
$this->seedClosureData();
DB::table('classes')->insert([
['id' => 1, 'class_name' => '1', 'schedule' => 'Sunday 9:00', 'school_year' => '2026-2027', 'semester' => 'Fall', 'capacity' => 30],
['id' => 13, 'class_name' => 'KG', 'schedule' => 'Sunday 9:00', 'school_year' => '2025-2026', 'semester' => 'Fall', 'capacity' => 30],
['id' => 14, 'class_name' => 'Arabic', 'schedule' => 'Sunday 11:00', 'school_year' => '2026-2027', 'semester' => 'Fall', 'capacity' => 30],
]);
DB::table('classSection')->insert([
[
'class_section_id' => 1,
'class_section_name' => 'KG',
'class_id' => 13,
'semester' => 'Fall',
'school_year' => '2025-2026',
],
[
'class_section_id' => 10,
'class_section_name' => '1A',
'class_id' => 1,
'semester' => 'Fall',
'school_year' => '2026-2027',
],
[
'class_section_id' => 140,
'class_section_name' => 'Arabic A',
'class_id' => 14,
'semester' => 'Fall',
'school_year' => '2026-2027',
],
]);
DB::table('students')->where('id', 100)->update(['age' => 5]);
DB::table('student_class')->where('student_id', 100)->where('school_year', '2025-2026')->update([
'class_section_id' => 1,
'updated_at' => now(),
]);
DB::table('enrollments')->where('student_id', 100)->where('school_year', '2025-2026')->update([
'class_section_id' => 1,
'updated_at' => now(),
]);
$this->actingAs(User::query()->findOrFail(1), 'api');
$preview = $this->postJson('/api/v1/school-years/1/preview-close', [
'new_school_year' => [
'name' => '2026-2027',
'start_date' => '2026-09-01',
'end_date' => '2027-06-30',
],
'transfer_unpaid_balances' => true,
]);
$preview->assertOk()
->assertJsonPath('data.promotion_preview.rows.0.promotion_action', 'promote')
->assertJsonPath('data.promotion_preview.rows.0.current_grade', 'KG')
->assertJsonPath('data.promotion_preview.rows.0.target_grade', '1')
->assertJsonPath('data.promotion_preview.rows.0.target_class_section_id', 10);
$this->postJson('/api/v1/school-years/1/close', [
'new_school_year' => [
'name' => '2026-2027',
'start_date' => '2026-09-01',
'end_date' => '2027-06-30',
],
'transfer_unpaid_balances' => true,
'confirmation' => 'CLOSE 2025-2026',
])->assertOk();
$this->assertDatabaseHas('enrollments', [
'student_id' => 100,
'school_year' => '2026-2027',
'class_section_id' => 10,
]);
$this->assertDatabaseHas('student_class', [
'student_id' => 100,
'school_year' => '2026-2027',
'class_section_id' => 10,
]);
$this->assertDatabaseMissing('enrollments', [
'student_id' => 100,
'school_year' => '2026-2027',
'class_section_id' => 140,
]);
}
public function test_closed_school_year_blocks_legacy_invoice_generation(): void
{
$this->seedClosureData();
@@ -28,6 +28,7 @@ class TeacherControllerTest extends TestCase
$response->assertJson(['ok' => true]);
$this->assertNotEmpty($response->json('students'));
$this->assertSame($classSectionId, $response->json('active_class_section_id'));
$this->assertSame($classSectionId, session('class_section_id'));
}
public function test_switch_class_returns_active_id(): void
@@ -44,6 +45,7 @@ class TeacherControllerTest extends TestCase
$response->assertOk();
$response->assertJsonPath('active_class_section_id', $classSectionId);
$this->assertSame($classSectionId, session('class_section_id'));
}
public function test_absence_submit_creates_staff_attendance(): void
@@ -25,6 +25,23 @@ class ClassProgressQueryServiceTest extends TestCase
'teacher_id' => $user->id,
'class_section_id' => 202,
]);
DB::table('classSection')->insert([
'id' => 1,
'class_id' => 1,
'class_section_id' => 101,
'class_section_name' => '1-A',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('teacher_class')->insert([
'class_section_id' => 1,
'teacher_id' => $user->id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
'created_at' => now(),
'updated_at' => now(),
]);
$service = new ClassProgressQueryService(new ClassProgressRuleService);
$results = $service->listReports($user, ['class_section_id' => 101]);
@@ -32,6 +49,78 @@ class ClassProgressQueryServiceTest extends TestCase
$this->assertSame(1, $results->total());
}
public function test_list_reports_filters_by_equivalent_legacy_section_ids(): void
{
$user = $this->createUser();
DB::table('classSection')->insert([
'id' => 1,
'class_id' => 1,
'class_section_id' => 101,
'class_section_name' => '1-A',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('teacher_class')->insert([
'class_section_id' => 101,
'teacher_id' => $user->id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
'created_at' => now(),
'updated_at' => now(),
]);
$report = ClassProgressReport::factory()->create([
'teacher_id' => 999,
'class_section_id' => 1,
'school_year' => '2025-2026',
]);
$service = new ClassProgressQueryService(new ClassProgressRuleService);
$results = $service->listReports($user, ['class_section_id' => 101]);
$this->assertSame(1, $results->total());
$this->assertSame($report->id, $results->items()[0]->id);
}
public function test_teacher_assignments_prefer_section_code_over_colliding_primary_key(): void
{
$user = $this->createUser();
DB::table('classSection')->insert([
[
'id' => 1,
'class_id' => 1,
'class_section_id' => 10,
'class_section_name' => '1',
'semester' => 'Fall',
'school_year' => '2025-2026',
],
[
'id' => 10,
'class_id' => 3,
'class_section_id' => 31,
'class_section_name' => '3-A',
'semester' => 'Fall',
'school_year' => '2025-2026',
],
]);
DB::table('teacher_class')->insert([
'class_section_id' => 10,
'teacher_id' => $user->id,
'position' => 'main',
'semester' => 'Fall',
'school_year' => '2025-2026',
'created_at' => now(),
'updated_at' => now(),
]);
$service = new ClassProgressQueryService(new ClassProgressRuleService);
$assignments = $service->teacherAssignments($user, '2025-2026', 'Fall');
$this->assertCount(1, $assignments);
$this->assertSame(10, $assignments[0]['class_section_id']);
$this->assertSame('1', $assignments[0]['class_section_name']);
}
private function createUser(): User
{
DB::table('users')->insert([
@@ -60,4 +60,39 @@ class InvoicePaymentServiceTest extends TestCase
$this->assertSame(5.0, $data['invoices'][0]['refund_amount']);
$this->assertSame(60.0, $data['invoices'][0]['last_paid_amount']);
}
public function test_parent_invoice_summary_applies_full_discount_to_balance(): void
{
DB::table('invoices')->insert([
[
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-DISCOUNT',
'total_amount' => 370,
'balance' => 370,
'paid_amount' => 0,
'has_discount' => 1,
'issue_date' => '2025-01-10',
'status' => 'Paid',
'school_year' => '2025-2026',
],
]);
DB::table('discount_usages')->insert([
'id' => 1,
'voucher_id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'discount_amount' => 370,
'description' => 'Full scholarship',
'school_year' => '2025-2026',
]);
$service = new InvoicePaymentService(new InvoiceConfigService);
$data = $service->getParentInvoiceSummary(10, '2025-2026');
$this->assertSame(370.0, $data['invoices'][0]['discount']);
$this->assertSame(0.0, $data['invoices'][0]['balance']);
$this->assertSame('Paid', $data['invoices'][0]['status']);
}
}
@@ -50,6 +50,67 @@ class ParentEnrollmentServiceTest extends TestCase
$this->assertSame('enrolled', $result['students'][0]['enrollment_status']);
}
public function test_withdrawal_request_creates_pending_zero_amount_refund(): void
{
$this->seedConfig();
$parentId = $this->seedParent();
$studentId = DB::table('students')->insertGetId([
'school_id' => 'S-201',
'firstname' => 'Omar',
'lastname' => 'Parent',
'dob' => '2014-09-01',
'age' => 11,
'gender' => 'Male',
'photo_consent' => 1,
'parent_id' => $parentId,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
DB::table('enrollments')->insert([
'student_id' => $studentId,
'parent_id' => $parentId,
'school_year' => '2025-2026',
'semester' => 'Fall',
'enrollment_date' => '2025-09-01',
'enrollment_status' => 'enrolled',
'admission_status' => 'accepted',
'is_withdrawn' => 0,
]);
$invoiceId = DB::table('invoices')->insertGetId([
'parent_id' => $parentId,
'invoice_number' => 'INV-201',
'total_amount' => 100,
'paid_amount' => 100,
'balance' => 0,
'issue_date' => now(),
'due_date' => now()->addWeek(),
'status' => 'paid',
'description' => 'Tuition',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
]);
$service = new ParentEnrollmentService(new ParentConfigService);
$result = $service->updateEnrollment($parentId, [], [$studentId]);
$this->assertSame([$studentId], $result['withdrawn']);
$this->assertDatabaseHas('refunds', [
'parent_id' => $parentId,
'invoice_id' => $invoiceId,
'school_year' => '2025-2026',
'semester' => 'Fall',
'status' => 'Pending',
'refund_amount' => 0,
'refund_paid_amount' => 0,
]);
}
private function seedParent(): int
{
return DB::table('users')->insertGetId([
@@ -41,6 +41,188 @@ class ParentInvoiceServiceTest extends TestCase
$this->assertSame('INV-1', $rows[0]['invoice_number']);
}
public function test_list_invoices_derives_payment_totals_from_payments_table(): void
{
$parentId = $this->seedParent();
$invoiceId = DB::table('invoices')->insertGetId([
'parent_id' => $parentId,
'invoice_number' => 'INV-PAY',
'total_amount' => 100,
'paid_amount' => 0,
'balance' => 100,
'issue_date' => '2025-09-01',
'due_date' => '2025-10-01',
'status' => 'Unpaid',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
]);
DB::table('payments')->insert([
[
'parent_id' => $parentId,
'invoice_id' => $invoiceId,
'total_amount' => 100,
'paid_amount' => 40,
'balance' => 60,
'number_of_installments' => 1,
'payment_method' => 'Check',
'payment_date' => '2025-09-15',
'transaction_id' => 'CHK-1',
'status' => 'Paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
],
[
'parent_id' => $parentId,
'invoice_id' => $invoiceId,
'total_amount' => 100,
'paid_amount' => 25,
'balance' => 35,
'number_of_installments' => 1,
'payment_method' => 'Online',
'payment_date' => '2025-09-16',
'transaction_id' => 'PENDING-1',
'status' => 'Pending',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
],
]);
$service = new ParentInvoiceService;
$rows = $service->listInvoices($parentId, '2025-2026');
$this->assertCount(1, $rows);
$this->assertSame(40.0, $rows[0]['paid_amount']);
$this->assertSame(60.0, $rows[0]['balance']);
$this->assertSame('Partially Paid', $rows[0]['status']);
$this->assertCount(1, $rows[0]['payments']);
$this->assertSame('CHK-1', $rows[0]['payments'][0]['transaction_id']);
}
public function test_list_invoices_applies_discounts_to_balance(): void
{
$parentId = $this->seedParent();
$invoiceId = DB::table('invoices')->insertGetId([
'parent_id' => $parentId,
'invoice_number' => 'INV-DISCOUNT',
'total_amount' => 380,
'paid_amount' => 10,
'balance' => 370,
'has_discount' => 1,
'issue_date' => '2025-09-06',
'due_date' => '2025-09-21',
'status' => 'Paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
]);
DB::table('payments')->insert([
'parent_id' => $parentId,
'invoice_id' => $invoiceId,
'total_amount' => 380,
'paid_amount' => 10,
'balance' => 370,
'number_of_installments' => 1,
'payment_method' => 'Cash',
'payment_date' => '2025-09-10',
'status' => 'Paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
]);
DB::table('discount_usages')->insert([
'voucher_id' => 1,
'parent_id' => $parentId,
'invoice_id' => $invoiceId,
'discount_amount' => 370,
'description' => 'Tuition discount',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
$service = new ParentInvoiceService;
$rows = $service->listInvoices($parentId, '2025-2026');
$this->assertSame(10.0, $rows[0]['paid_amount']);
$this->assertSame(370.0, $rows[0]['discount']);
$this->assertSame(0.0, $rows[0]['balance']);
$this->assertSame('Paid', $rows[0]['status']);
}
public function test_statement_derives_current_balance_from_computed_invoice_lines(): void
{
$parentId = $this->seedParent();
$invoiceId = DB::table('invoices')->insertGetId([
'parent_id' => $parentId,
'invoice_number' => 'INV-STMT-DISCOUNT',
'total_amount' => 380,
'paid_amount' => 10,
'balance' => 370,
'has_discount' => 1,
'issue_date' => '2025-09-06',
'due_date' => '2025-09-21',
'status' => 'Paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
]);
DB::table('parent_accounts')->insert([
'parent_id' => $parentId,
'school_year' => '2025-2026',
'opening_balance' => 0,
'current_balance' => 370,
'created_at' => now(),
'updated_at' => now(),
]);
DB::table('payments')->insert([
'parent_id' => $parentId,
'invoice_id' => $invoiceId,
'total_amount' => 380,
'paid_amount' => 10,
'balance' => 370,
'number_of_installments' => 1,
'payment_method' => 'Cash',
'payment_date' => '2025-09-10',
'status' => 'Paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
]);
DB::table('discount_usages')->insert([
'voucher_id' => 1,
'parent_id' => $parentId,
'invoice_id' => $invoiceId,
'discount_amount' => 370,
'description' => 'Tuition discount',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
$service = new ParentInvoiceService;
$statement = $service->statement($parentId, '2025-2026');
$this->assertSame(0.0, $statement['lines'][0]['amount']);
$this->assertSame(0.0, $statement['current_balance']);
}
private function seedParent(string $email = 'parent@example.com'): int
{
return DB::table('users')->insertGetId([
@@ -58,4 +58,82 @@ class PaymentManualServiceTest extends TestCase
$this->assertCount(1, $results);
$this->assertSame('parent@example.com', $results[0]['value']);
}
public function test_suggest_returns_matches_in_display_name_order(): void
{
DB::table('users')->insert([
[
'id' => 10,
'school_id' => 1,
'firstname' => 'Zara',
'lastname' => 'Akter',
'cellphone' => '555-555-5555',
'email' => 'zara.akter@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
],
[
'id' => 11,
'school_id' => 1,
'firstname' => 'Aisha',
'lastname' => 'Akter',
'cellphone' => '555-555-5556',
'email' => 'aisha.akter@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
],
[
'id' => 12,
'school_id' => 1,
'firstname' => 'Mousumi',
'lastname' => 'Akter',
'cellphone' => '555-555-5557',
'email' => 'mousumi.akter@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
],
]);
$invoiceService = Mockery::mock(DiscountInvoiceService::class);
$enrollmentService = Mockery::mock(PaymentEnrollmentEventService::class);
$service = new PaymentManualService($invoiceService, $enrollmentService);
$results = $service->suggest('akter');
$this->assertSame([
'Aisha Akter',
'Mousumi Akter',
'Zara Akter',
], array_column($results, 'label'));
}
}