add controllers, servoices
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Tests\Feature\Api\V1\AttendanceTracking;
|
||||
|
||||
use App\Services\AttendanceTrackingService;
|
||||
use App\Services\AttendanceTracking\AttendanceTrackingService;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -323,4 +323,4 @@ class AttendanceTrackingControllerTest extends TestCase
|
||||
$response->assertStatus(422)
|
||||
->assertJsonValidationErrors(['student_id', 'code', 'note']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Auth;
|
||||
|
||||
use App\Models\Role;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RegisterControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_captcha_endpoint_returns_value(): void
|
||||
{
|
||||
$response = $this->getJson('/api/v1/auth/register/captcha');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure(['ok', 'captcha']);
|
||||
$this->assertNotEmpty($response->json('captcha'));
|
||||
}
|
||||
|
||||
public function test_register_creates_user(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 2001, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2002, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
Role::query()->create([
|
||||
'id' => 1,
|
||||
'name' => 'parent',
|
||||
'slug' => 'parent',
|
||||
'description' => 'Parent',
|
||||
'priority' => 1,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'gender' => 'Male',
|
||||
'email' => 'parent@example.com',
|
||||
'confirm_email' => 'parent@example.com',
|
||||
'cellphone' => '5555555555',
|
||||
'address_street' => '123 Main',
|
||||
'apt' => 'A',
|
||||
'city' => 'City',
|
||||
'state' => 'CT',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'captcha' => 'ABCD',
|
||||
'is_parent' => 1,
|
||||
'no_second_parent_info' => 1,
|
||||
];
|
||||
|
||||
$response = $this->withSession(['captcha_answer' => 'ABCD'])
|
||||
->postJson('/api/v1/auth/register', $payload);
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonPath('ok', true);
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'email' => 'parent@example.com',
|
||||
'status' => 'Inactive',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Auth;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RegisterPayloadDebugTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_debug_payload_shows_json_body(): void
|
||||
{
|
||||
$payload = [
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'gender' => 'Male',
|
||||
'email' => 'parent@example.com',
|
||||
'confirm_email' => 'parent@example.com',
|
||||
'cellphone' => '5555555555',
|
||||
'address_street' => '123 Main',
|
||||
'apt' => 'A',
|
||||
'city' => 'City',
|
||||
'state' => 'CT',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'captcha' => 'ABCD',
|
||||
'is_parent' => 1,
|
||||
'no_second_parent_info' => 1,
|
||||
];
|
||||
|
||||
$response = $this->withHeaders(['X-Debug-Request' => '1'])
|
||||
->postJson('/api/v1/auth/register', $payload);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('ok', true);
|
||||
$response->assertJsonFragment(['email' => 'parent@example.com']);
|
||||
$response->assertJsonPath('debug.json_all.email', 'parent@example.com');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\BroadcastEmail;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\EmailService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BroadcastEmailControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_options_returns_parents_and_senders(): void
|
||||
{
|
||||
$this->seedParentData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/broadcast-email/options');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertNotEmpty($response->json('parents'));
|
||||
$this->assertNotEmpty($response->json('fromOptions'));
|
||||
}
|
||||
|
||||
public function test_send_test_only_dispatches_email(): void
|
||||
{
|
||||
$this->seedParentData();
|
||||
|
||||
$fake = new class extends EmailService {
|
||||
public array $sent = [];
|
||||
|
||||
public function send(
|
||||
array|string $to,
|
||||
string $subject,
|
||||
string $html,
|
||||
string $fromKey = 'general',
|
||||
array $cc = [],
|
||||
array $bcc = []
|
||||
): bool
|
||||
{
|
||||
$this->sent[] = compact('to', 'subject', 'html', 'fromKey', 'cc', 'bcc');
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
$this->app->instance(EmailService::class, $fake);
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson('/api/v1/broadcast-email/send', [
|
||||
'mode' => 'personalized',
|
||||
'subject' => 'Test Subject',
|
||||
'from_key' => 'general',
|
||||
'body_html' => '<p>Hello {{name}}</p>',
|
||||
'send_test_only' => true,
|
||||
'test_email' => 'parent@example.com',
|
||||
'wrap_layout' => false,
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
||||
'ok' => true,
|
||||
]);
|
||||
$this->assertCount(1, $fake->sent);
|
||||
}
|
||||
|
||||
private function seedParentData(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
'id' => 1,
|
||||
'name' => 'parent',
|
||||
'slug' => 'parent',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 10,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'parent@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' => 10,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
private function createUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\ClassPrep;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassPrepControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_sticker_counts_returns_payload(): void
|
||||
{
|
||||
$this->seedStickerData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/class-prep/sticker-counts?school_year=2025-2026&semester=Fall');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
||||
'ok' => true,
|
||||
'data' => [
|
||||
'totals' => [
|
||||
'primary' => 6,
|
||||
'secondary' => 1,
|
||||
'students' => 2,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_students_by_class_returns_roster(): void
|
||||
{
|
||||
$this->seedStickerData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/class-prep/classes/101/students?school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertCount(1, $response->json('students'));
|
||||
$this->assertSame('1-A', $response->json('students.0.registration_grade'));
|
||||
}
|
||||
|
||||
private function seedStickerData(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
DB::table('classes')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'class_name' => 'Class 1',
|
||||
'schedule' => 'Sun',
|
||||
'capacity' => 20,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'class_name' => 'Class 2',
|
||||
'schedule' => 'Sun',
|
||||
'capacity' => 20,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'class_name' => 'Class 3',
|
||||
'schedule' => 'Sun',
|
||||
'capacity' => 20,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '1-A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'class_id' => 2,
|
||||
'class_section_id' => 102,
|
||||
'class_section_name' => '5-B',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'class_id' => 3,
|
||||
'class_section_id' => 103,
|
||||
'class_section_name' => 'Youth-1',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
[
|
||||
'school_id' => 'S-1',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'One',
|
||||
'age' => 8,
|
||||
'gender' => 'Male',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 1,
|
||||
'is_new' => 0,
|
||||
],
|
||||
[
|
||||
'school_id' => 'S-2',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'Two',
|
||||
'age' => 10,
|
||||
'gender' => 'Female',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 1,
|
||||
'is_new' => 0,
|
||||
],
|
||||
[
|
||||
'school_id' => 'S-3',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'Three',
|
||||
'age' => 12,
|
||||
'gender' => 'Female',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 1,
|
||||
'is_new' => 1,
|
||||
],
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
[
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'student_id' => 2,
|
||||
'class_section_id' => 102,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'student_id' => 3,
|
||||
'class_section_id' => 103,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
private function createUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\ClassPreparation;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassPreparationControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_prep_payload(): void
|
||||
{
|
||||
$this->seedPrepData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/class-prep?school_year=2025-2026&semester=Fall');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
||||
'ok' => true,
|
||||
'schoolYear' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
$this->assertNotEmpty($response->json('results'));
|
||||
}
|
||||
|
||||
public function test_mark_printed_creates_snapshots(): void
|
||||
{
|
||||
$this->seedPrepData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson('/api/v1/class-prep/mark-printed', [
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'class_section_ids' => [101],
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
||||
'ok' => true,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('class_preparation_log', [
|
||||
'class_section_id' => 101,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedPrepData(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '1-A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'school_id' => 'S-1',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'One',
|
||||
'age' => 8,
|
||||
'gender' => 'Male',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('inventory_categories')->insert([
|
||||
'type' => 'classroom',
|
||||
'name' => 'Small Table',
|
||||
]);
|
||||
|
||||
DB::table('inventory_items')->insert([
|
||||
'type' => 'classroom',
|
||||
'category_id' => 1,
|
||||
'name' => 'Small Table',
|
||||
'quantity' => 10,
|
||||
'good_qty' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
}
|
||||
|
||||
private function createUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Communication;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\EmailService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CommunicationControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_options_returns_students_and_templates(): void
|
||||
{
|
||||
$this->seedCommunicationData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/communications/options');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertNotEmpty($response->json('students'));
|
||||
$this->assertNotEmpty($response->json('templates'));
|
||||
}
|
||||
|
||||
public function test_preview_returns_rendered_subject_and_body(): void
|
||||
{
|
||||
$this->seedCommunicationData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson('/api/v1/communications/preview', [
|
||||
'template_key' => 'welcome',
|
||||
'student_id' => 1,
|
||||
'family_id' => 1,
|
||||
'vars' => ['custom' => 'value'],
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertStringContainsString('Parent One', (string) $response->json('subject'));
|
||||
$this->assertStringContainsString('Student One', (string) $response->json('html'));
|
||||
}
|
||||
|
||||
public function test_send_dispatches_email(): void
|
||||
{
|
||||
$this->seedCommunicationData();
|
||||
|
||||
$fake = new class extends EmailService {
|
||||
public array $sent = [];
|
||||
|
||||
public function send(
|
||||
array|string $to,
|
||||
string $subject,
|
||||
string $html,
|
||||
string $fromKey = 'general',
|
||||
array $cc = [],
|
||||
array $bcc = []
|
||||
): bool {
|
||||
$this->sent[] = compact('to', 'subject', 'html', 'fromKey', 'cc', 'bcc');
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
$this->app->instance(EmailService::class, $fake);
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson('/api/v1/communications/send', [
|
||||
'student_id' => 1,
|
||||
'family_id' => 1,
|
||||
'template_key' => 'welcome',
|
||||
'subject' => 'Hello',
|
||||
'body' => '<p>Hi</p>',
|
||||
'recipients' => ['parent1@example.com'],
|
||||
'cc' => ['parent2@example.com'],
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertCount(1, $fake->sent);
|
||||
}
|
||||
|
||||
private function seedCommunicationData(): void
|
||||
{
|
||||
DB::table('students')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 'S-1',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'One',
|
||||
'age' => 8,
|
||||
'gender' => 'Male',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 1,
|
||||
'is_new' => 0,
|
||||
'registration_grade' => '1-A',
|
||||
]);
|
||||
|
||||
DB::table('families')->insert([
|
||||
'id' => 1,
|
||||
'family_code' => 'F-1',
|
||||
'household_name' => 'Family One',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('family_students')->insert([
|
||||
'family_id' => 1,
|
||||
'student_id' => 1,
|
||||
'is_primary_home' => 1,
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 2,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'One',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'parent1@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('family_guardians')->insert([
|
||||
'family_id' => 1,
|
||||
'user_id' => 2,
|
||||
'relation' => 'parent',
|
||||
'is_primary' => 1,
|
||||
'receive_emails' => 1,
|
||||
'receive_sms' => 0,
|
||||
]);
|
||||
|
||||
DB::table('email_templates')->insert([
|
||||
'id' => 1,
|
||||
'code' => 'welcome',
|
||||
'variant' => 'default',
|
||||
'subject' => 'Hello {{parent_salutation}}',
|
||||
'body_html' => 'Hi {{student_fullname}}',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
private function createUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\CompetitionScores;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CompetitionScoresControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_competitions_and_counts(): void
|
||||
{
|
||||
$this->seedCompetitionData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/competition-scores');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
||||
'ok' => true,
|
||||
'activeClassId' => 101,
|
||||
]);
|
||||
$this->assertNotEmpty($response->json('competitions'));
|
||||
$this->assertSame(1, $response->json('studentTotal'));
|
||||
}
|
||||
|
||||
public function test_edit_returns_students_and_scores(): void
|
||||
{
|
||||
$this->seedCompetitionData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/competition-scores/1');
|
||||
|
||||
$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();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson('/api/v1/competition-scores/1', [
|
||||
'class_section_id' => 101,
|
||||
'scores' => [
|
||||
1 => 10,
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
||||
'ok' => true,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('competition_scores', [
|
||||
'competition_id' => 1,
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'score' => 10,
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedCompetitionData(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
DB::table('classes')->insert([
|
||||
'id' => 1,
|
||||
'class_name' => 'Class 1',
|
||||
'schedule' => 'Sun',
|
||||
'capacity' => 20,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
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' => 1,
|
||||
'position' => 'main',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 'S-1',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'One',
|
||||
'age' => 8,
|
||||
'gender' => 'Male',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('competitions')->insert([
|
||||
'id' => 1,
|
||||
'title' => 'Quiz',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'class_section_id' => 101,
|
||||
'is_locked' => 0,
|
||||
]);
|
||||
|
||||
DB::table('competition_class_winners')->insert([
|
||||
'competition_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'question_count' => 20,
|
||||
]);
|
||||
|
||||
DB::table('competition_scores')->insert([
|
||||
'competition_id' => 1,
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'score' => 5,
|
||||
]);
|
||||
}
|
||||
|
||||
private function createUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Discounts;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DiscountControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_options_returns_vouchers_and_parents(): void
|
||||
{
|
||||
$this->seedDiscountData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/discounts/options');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertNotEmpty($response->json('vouchers'));
|
||||
$this->assertNotEmpty($response->json('parents'));
|
||||
}
|
||||
|
||||
public function test_apply_voucher_applies_discount(): void
|
||||
{
|
||||
$this->seedDiscountData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson('/api/v1/discounts/apply', [
|
||||
'voucher_id' => 1,
|
||||
'parent_ids' => [10],
|
||||
'allow_additional' => true,
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
|
||||
$this->assertDatabaseHas('discount_usages', [
|
||||
'voucher_id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_id' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_store_voucher_creates_row(): void
|
||||
{
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson('/api/v1/discounts/vouchers', [
|
||||
'code' => 'NEW-10',
|
||||
'discount_type' => 'percent',
|
||||
'discount_value' => 10,
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertDatabaseHas('discount_vouchers', ['code' => 'NEW-10']);
|
||||
}
|
||||
|
||||
public function test_show_voucher_returns_resource(): void
|
||||
{
|
||||
$this->seedDiscountData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/discounts/vouchers/1');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
||||
'ok' => true,
|
||||
'voucher' => [
|
||||
'id' => 1,
|
||||
'code' => 'TEST-100',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_delete_voucher_removes_row(): void
|
||||
{
|
||||
$this->seedDiscountData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->deleteJson('/api/v1/discounts/vouchers/1');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertDatabaseMissing('discount_vouchers', ['id' => 1]);
|
||||
}
|
||||
|
||||
private function seedDiscountData(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 10,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'One',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'parent@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('roles')->insert([
|
||||
'id' => 1,
|
||||
'name' => 'parent',
|
||||
'slug' => 'parent',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => 10,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('discount_vouchers')->insert([
|
||||
'id' => 1,
|
||||
'code' => 'TEST-100',
|
||||
'discount_type' => 'fixed',
|
||||
'discount_value' => 100,
|
||||
'max_uses' => 10,
|
||||
'times_used' => 0,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_number' => 'INV-1',
|
||||
'total_amount' => 100,
|
||||
'balance' => 100,
|
||||
'paid_amount' => 0,
|
||||
'status' => 'Unpaid',
|
||||
'issue_date' => '2025-09-01',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('enrollments')->insert([
|
||||
'parent_id' => 10,
|
||||
'student_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'enrollment_status' => 'payment pending',
|
||||
'enrollment_date' => '2025-09-01',
|
||||
]);
|
||||
}
|
||||
|
||||
private function createUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Expenses;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ExpenseControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_options_returns_staff_and_retailors(): void
|
||||
{
|
||||
$this->seedStaffUsers();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/expenses/options');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertNotEmpty($response->json('staff'));
|
||||
$this->assertNotEmpty($response->json('retailors'));
|
||||
}
|
||||
|
||||
public function test_store_creates_expense(): void
|
||||
{
|
||||
$this->seedStaffUsers();
|
||||
|
||||
Storage::fake();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$file = UploadedFile::fake()->create('receipt.pdf', 10, 'application/pdf');
|
||||
|
||||
$response = $this->post('/api/v1/expenses', [
|
||||
'category' => 'Expense',
|
||||
'amount' => 25.5,
|
||||
'purchased_by' => 2,
|
||||
'retailor' => 'Amazon',
|
||||
'date_of_purchase' => '2025-09-01',
|
||||
'description' => 'Supplies',
|
||||
'receipt' => $file,
|
||||
], ['Accept' => 'application/json']);
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJson(['ok' => true]);
|
||||
|
||||
$this->assertDatabaseHas('expenses', [
|
||||
'category' => 'Expense',
|
||||
'purchased_by' => 2,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_index_lists_expenses(): void
|
||||
{
|
||||
$this->seedExpenseData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/expenses');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertNotEmpty($response->json('expenses'));
|
||||
}
|
||||
|
||||
public function test_show_returns_expense(): void
|
||||
{
|
||||
$this->seedExpenseData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/expenses/1');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
||||
'ok' => true,
|
||||
'expense' => [
|
||||
'id' => 1,
|
||||
'category' => 'Expense',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_status_changes_status(): void
|
||||
{
|
||||
$this->seedExpenseData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson('/api/v1/expenses/1/status', [
|
||||
'status' => 'approved',
|
||||
'reason' => 'Ok',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
|
||||
$this->assertDatabaseHas('expenses', [
|
||||
'id' => 1,
|
||||
'status' => 'approved',
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedStaffUsers(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'administrator', 'slug' => 'administrator', 'is_active' => 1],
|
||||
['id' => 2, 'name' => 'parent', 'slug' => 'parent', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
[
|
||||
'id' => 2,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Staff',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'staff@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' => 3,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'parent@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' => 2, 'role_id' => 1],
|
||||
['user_id' => 3, 'role_id' => 2],
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedExpenseData(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 2,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Staff',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'staff@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('expenses')->insert([
|
||||
'id' => 1,
|
||||
'category' => 'Expense',
|
||||
'amount' => 10,
|
||||
'date_of_purchase' => '2025-09-01',
|
||||
'purchased_by' => 2,
|
||||
'added_by' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'status' => 'pending',
|
||||
]);
|
||||
}
|
||||
|
||||
private function createUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\ExtraCharges;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ExtraChargesControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_list_returns_rows(): void
|
||||
{
|
||||
$this->seedBaseData();
|
||||
$this->seedCharge();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/extra-charges');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertNotEmpty($response->json('rows'));
|
||||
}
|
||||
|
||||
public function test_options_returns_parent_options(): void
|
||||
{
|
||||
$this->seedBaseData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/extra-charges/options?q=Parent');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertNotEmpty($response->json('parents'));
|
||||
}
|
||||
|
||||
public function test_parent_options_returns_results(): void
|
||||
{
|
||||
$this->seedBaseData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/extra-charges/parents?q=Parent');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertNotEmpty($response->json('results'));
|
||||
}
|
||||
|
||||
public function test_invoices_for_parent_returns_results(): void
|
||||
{
|
||||
$this->seedBaseData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/extra-charges/invoices?parent_id=10&school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertNotEmpty($response->json('results'));
|
||||
}
|
||||
|
||||
public function test_store_creates_charge_and_updates_invoice(): void
|
||||
{
|
||||
$this->seedBaseData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson('/api/v1/extra-charges', [
|
||||
'parent_id' => 10,
|
||||
'title' => 'Books',
|
||||
'amount' => 20,
|
||||
'charge_type' => 'add',
|
||||
'due_date' => '2025-09-01',
|
||||
'invoice_id' => 1,
|
||||
'description' => 'Extra books',
|
||||
]);
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJson(['ok' => true]);
|
||||
|
||||
$this->assertDatabaseHas('additional_charges', [
|
||||
'parent_id' => 10,
|
||||
'title' => 'Books',
|
||||
'status' => 'applied',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'id' => 1,
|
||||
'total_amount' => 120,
|
||||
'balance' => 120,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_adjusts_charge(): void
|
||||
{
|
||||
$this->seedBaseData();
|
||||
$this->seedCharge();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->putJson('/api/v1/extra-charges/1', [
|
||||
'title' => 'Books Updated',
|
||||
'amount' => 15,
|
||||
'charge_type' => 'add',
|
||||
'due_date' => '2025-09-01',
|
||||
'description' => 'Updated',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
|
||||
$this->assertDatabaseHas('additional_charges', [
|
||||
'id' => 1,
|
||||
'title' => 'Books Updated',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_void_changes_status(): void
|
||||
{
|
||||
$this->seedBaseData();
|
||||
$this->seedCharge();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson('/api/v1/extra-charges/1/void');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertDatabaseHas('additional_charges', [
|
||||
'id' => 1,
|
||||
'status' => 'void',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_reverse_changes_status(): void
|
||||
{
|
||||
$this->seedBaseData();
|
||||
$this->seedCharge();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson('/api/v1/extra-charges/1/reverse');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertDatabaseHas('additional_charges', [
|
||||
'id' => 1,
|
||||
'status' => 'pending',
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedBaseData(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'parent', 'slug' => 'parent', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 10,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'parent@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' => 10,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_number' => 'INV-1',
|
||||
'total_amount' => 100,
|
||||
'balance' => 100,
|
||||
'paid_amount' => 0,
|
||||
'issue_date' => '2025-09-01',
|
||||
'school_year' => '2025-2026',
|
||||
'status' => 'Unpaid',
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedCharge(): void
|
||||
{
|
||||
DB::table('additional_charges')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'charge_type' => 'add',
|
||||
'title' => 'Books',
|
||||
'description' => 'Extra books',
|
||||
'amount' => 10,
|
||||
'due_date' => '2025-09-01',
|
||||
'status' => 'applied',
|
||||
'created_by' => 1,
|
||||
'created_at' => '2025-09-01 00:00:00',
|
||||
]);
|
||||
|
||||
DB::table('invoices')->where('id', 1)->update([
|
||||
'total_amount' => 110,
|
||||
'balance' => 110,
|
||||
]);
|
||||
}
|
||||
|
||||
private function createUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Finance;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FinancialControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_report_returns_financial_report(): void
|
||||
{
|
||||
$this->seedFinancialData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/finance/financial-report?school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('report.invoices'));
|
||||
}
|
||||
|
||||
public function test_summary_returns_totals(): void
|
||||
{
|
||||
$this->seedFinancialData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/finance/financial-summary?school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertGreaterThan(0, (float) $response->json('summary.totalCharges'));
|
||||
}
|
||||
|
||||
public function test_unpaid_parents_lists_balances(): void
|
||||
{
|
||||
$this->seedFinancialData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/finance/unpaid-parents?school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('results'));
|
||||
}
|
||||
|
||||
private function seedFinancialData(): void
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
[
|
||||
'id' => 2,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'parent@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('invoices')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'parent_id' => 2,
|
||||
'invoice_number' => 'INV-001',
|
||||
'total_amount' => 100,
|
||||
'balance' => 40,
|
||||
'paid_amount' => 60,
|
||||
'has_discount' => 1,
|
||||
'issue_date' => '2025-01-10',
|
||||
'due_date' => '2025-02-10',
|
||||
'status' => 'unpaid',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'parent_id' => 2,
|
||||
'invoice_number' => 'INV-002',
|
||||
'total_amount' => 50,
|
||||
'balance' => 50,
|
||||
'paid_amount' => 0,
|
||||
'has_discount' => 0,
|
||||
'issue_date' => '2025-02-01',
|
||||
'due_date' => '2025-03-01',
|
||||
'status' => 'unpaid',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
]);
|
||||
|
||||
DB::table('payments')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 2,
|
||||
'invoice_id' => 1,
|
||||
'total_amount' => 100,
|
||||
'paid_amount' => 60,
|
||||
'balance' => 40,
|
||||
'number_of_installments' => 1,
|
||||
'payment_method' => 'Cash',
|
||||
'payment_date' => '2025-01-15',
|
||||
'school_year' => '2025-2026',
|
||||
'status' => 'Paid',
|
||||
]);
|
||||
|
||||
DB::table('discount_usages')->insert([
|
||||
'id' => 1,
|
||||
'voucher_id' => 1,
|
||||
'invoice_id' => 1,
|
||||
'parent_id' => 2,
|
||||
'discount_amount' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('refunds')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 2,
|
||||
'school_year' => '2025-2026',
|
||||
'invoice_id' => 1,
|
||||
'refund_amount' => 5,
|
||||
'status' => 'Paid',
|
||||
'refund_paid_amount' => 5,
|
||||
]);
|
||||
|
||||
DB::table('expenses')->insert([
|
||||
'id' => 1,
|
||||
'category' => 'Expense',
|
||||
'amount' => 20,
|
||||
'date_of_purchase' => '2025-01-05',
|
||||
'purchased_by' => 2,
|
||||
'added_by' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'status' => 'approved',
|
||||
]);
|
||||
|
||||
DB::table('reimbursements')->insert([
|
||||
'id' => 1,
|
||||
'expense_id' => 1,
|
||||
'amount' => 15,
|
||||
'reimbursed_to' => 2,
|
||||
'added_by' => 1,
|
||||
'status' => 'Paid',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
}
|
||||
|
||||
private function createUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Finance;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InvoiceControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_management_returns_parent_invoice_data(): void
|
||||
{
|
||||
$this->seedBaseData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/finance/invoices/management?school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('invoices'));
|
||||
}
|
||||
|
||||
public function test_generate_creates_invoice(): void
|
||||
{
|
||||
$this->seedBaseData(false);
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson('/api/v1/finance/invoices/generate', [
|
||||
'parent_id' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'parent_id' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_by_parent_returns_invoices(): void
|
||||
{
|
||||
$this->seedBaseData();
|
||||
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/finance/invoices/parent/10?school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('invoices'));
|
||||
}
|
||||
|
||||
private function seedBaseData(bool $withInvoice = true): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'parent', 'slug' => 'parent', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 10,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'parent@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' => 10,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 100,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'User',
|
||||
'school_id' => 1,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'class_section_id' => 1,
|
||||
'class_section_name' => '1A',
|
||||
'class_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'is_event_only' => 0,
|
||||
]);
|
||||
|
||||
DB::table('enrollments')->insert([
|
||||
'student_id' => 100,
|
||||
'parent_id' => 10,
|
||||
'class_section_id' => 1,
|
||||
'enrollment_status' => 'enrolled',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
if ($withInvoice) {
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_number' => 'INV-001',
|
||||
'total_amount' => 100,
|
||||
'balance' => 100,
|
||||
'paid_amount' => 0,
|
||||
'has_discount' => 0,
|
||||
'issue_date' => '2025-01-10',
|
||||
'status' => 'unpaid',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function createUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Finance;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PaymentControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_store_creates_payment_plan(): void
|
||||
{
|
||||
$this->seedUsers();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
$response = $this->postJson('/api/v1/finance/payments', [
|
||||
'parent_id' => 10,
|
||||
'total_amount' => 250,
|
||||
'number_of_installments' => 2,
|
||||
'payment_date' => '2025-01-05',
|
||||
'payment_method' => 'cash',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertDatabaseHas('payments', [
|
||||
'parent_id' => 10,
|
||||
'total_amount' => 250,
|
||||
'number_of_installments' => 2,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_by_parent_returns_payments(): void
|
||||
{
|
||||
$this->seedUsers();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('payments')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_id' => 1,
|
||||
'total_amount' => 100,
|
||||
'paid_amount' => 25,
|
||||
'balance' => 75,
|
||||
'number_of_installments' => 1,
|
||||
'payment_method' => 'cash',
|
||||
'payment_date' => '2025-01-01',
|
||||
'school_year' => '2025-2026',
|
||||
'status' => 'Partially Paid',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/finance/payments/parent/10?school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('payments'));
|
||||
}
|
||||
|
||||
public function test_update_balance_updates_payment(): void
|
||||
{
|
||||
$this->seedUsers();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('payments')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_id' => 1,
|
||||
'total_amount' => 100,
|
||||
'paid_amount' => 0,
|
||||
'balance' => 100,
|
||||
'number_of_installments' => 1,
|
||||
'payment_method' => 'cash',
|
||||
'payment_date' => '2025-01-01',
|
||||
'school_year' => '2025-2026',
|
||||
'status' => 'Pending',
|
||||
]);
|
||||
|
||||
$response = $this->postJson('/api/v1/finance/payments/1/balance', [
|
||||
'paid_amount' => 25,
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertDatabaseHas('payments', [
|
||||
'id' => 1,
|
||||
'paid_amount' => 25,
|
||||
'balance' => 75,
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedUsers(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'admin', 'slug' => 'admin', 'is_active' => 1],
|
||||
['id' => 2, 'name' => 'parent', 'slug' => 'parent', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 10,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'parent@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' => 1, 'role_id' => 1],
|
||||
['user_id' => 10, 'role_id' => 2],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Finance;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PaymentEventChargesControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_store_creates_event_charges(): void
|
||||
{
|
||||
$this->seedUsers();
|
||||
$this->seedStudents();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
$response = $this->postJson('/api/v1/finance/event-charges', [
|
||||
'parent_id' => 10,
|
||||
'event_name' => 'Field Trip',
|
||||
'description' => 'Bus fee',
|
||||
'amount' => 25,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'student_ids' => [100],
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertDatabaseHas('event_charges', [
|
||||
'parent_id' => 10,
|
||||
'student_id' => 100,
|
||||
'event_name' => 'Field Trip',
|
||||
'amount' => 25,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedUsers(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'admin', 'slug' => 'admin', 'is_active' => 1],
|
||||
['id' => 2, 'name' => 'parent', 'slug' => 'parent', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 10,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'parent@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' => 1, 'role_id' => 1],
|
||||
['user_id' => 10, 'role_id' => 2],
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedStudents(): void
|
||||
{
|
||||
DB::table('students')->insert([
|
||||
'id' => 100,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'User',
|
||||
'school_id' => 1,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Finance;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PaymentManualControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_search_returns_parent_data(): 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@example.com');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertSame(10, $response->json('parent.id'));
|
||||
}
|
||||
|
||||
public function test_suggest_returns_items(): void
|
||||
{
|
||||
$this->seedUsers();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
$response = $this->getJson('/api/v1/finance/manual-pay/suggest?q=parent');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('items'));
|
||||
}
|
||||
|
||||
private function seedUsers(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'admin', 'slug' => 'admin', 'is_active' => 1],
|
||||
['id' => 2, 'name' => 'parent', 'slug' => 'parent', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 10,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'parent@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' => 1, 'role_id' => 1],
|
||||
['user_id' => 10, 'role_id' => 2],
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedConfig(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
['config_key' => 'installment_date', 'config_value' => '2025-06-01'],
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedStudent(): void
|
||||
{
|
||||
DB::table('students')->insert([
|
||||
'id' => 100,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'User',
|
||||
'school_id' => 1,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedInvoice(): void
|
||||
{
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_number' => 'INV-001',
|
||||
'total_amount' => 100,
|
||||
'balance' => 100,
|
||||
'paid_amount' => 0,
|
||||
'status' => 'unpaid',
|
||||
'school_year' => '2025-2026',
|
||||
'issue_date' => '2025-01-01',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Finance;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PaymentNotificationControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_send_creates_log(): void
|
||||
{
|
||||
Mail::fake();
|
||||
$this->seedUsers();
|
||||
$this->seedConfig();
|
||||
$this->seedInvoice();
|
||||
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
$response = $this->postJson('/api/v1/finance/payment-notifications/send', [
|
||||
'parent_id' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertDatabaseHas('payment_notification_logs', [
|
||||
'parent_id' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_index_lists_logs(): void
|
||||
{
|
||||
$this->seedUsers();
|
||||
|
||||
DB::table('payment_notification_logs')->insert([
|
||||
'parent_id' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
'period_year' => 2025,
|
||||
'period_month' => 1,
|
||||
'type' => 'installment',
|
||||
'to_email' => 'parent@example.com',
|
||||
'status' => 'sent',
|
||||
'balance_snapshot' => 100,
|
||||
'sent_at' => '2025-01-01 10:00:00',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
$response = $this->getJson('/api/v1/finance/payment-notifications');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('logs'));
|
||||
}
|
||||
|
||||
private function seedUsers(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'admin', 'slug' => 'admin', 'is_active' => 1],
|
||||
['id' => 2, 'name' => 'parent', 'slug' => 'parent', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 10,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'parent@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' => 1, 'role_id' => 1],
|
||||
['user_id' => 10, 'role_id' => 2],
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedConfig(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
['config_key' => 'installment_date', 'config_value' => '2025-06-01'],
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedInvoice(): void
|
||||
{
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_number' => 'INV-001',
|
||||
'total_amount' => 200,
|
||||
'balance' => 200,
|
||||
'paid_amount' => 0,
|
||||
'status' => 'unpaid',
|
||||
'school_year' => '2025-2026',
|
||||
'issue_date' => '2025-01-01',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Finance;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PaymentTransactionControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_store_creates_transaction(): void
|
||||
{
|
||||
$this->seedUsers();
|
||||
$this->seedPayment();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
$response = $this->postJson('/api/v1/finance/payment-transactions', [
|
||||
'transaction_id' => 'TXN-1001',
|
||||
'payment_id' => 1,
|
||||
'transaction_date' => '2025-01-10',
|
||||
'amount' => 25,
|
||||
'payment_method' => 'cash',
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertDatabaseHas('payment_transactions', [
|
||||
'transaction_id' => 'TXN-1001',
|
||||
'payment_id' => 1,
|
||||
'amount' => 25,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_by_payment_returns_transactions(): void
|
||||
{
|
||||
$this->seedUsers();
|
||||
$this->seedPayment();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('payment_transactions')->insert([
|
||||
'transaction_id' => 'TXN-1002',
|
||||
'payment_id' => 1,
|
||||
'transaction_date' => '2025-01-11',
|
||||
'amount' => 40,
|
||||
'payment_method' => 'cash',
|
||||
'payment_status' => 'Pending',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/finance/payment-transactions/payment/1');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('transactions'));
|
||||
}
|
||||
|
||||
public function test_update_status_updates_transaction(): void
|
||||
{
|
||||
$this->seedUsers();
|
||||
$this->seedPayment();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('payment_transactions')->insert([
|
||||
'transaction_id' => 'TXN-1003',
|
||||
'payment_id' => 1,
|
||||
'transaction_date' => '2025-01-11',
|
||||
'amount' => 40,
|
||||
'payment_method' => 'cash',
|
||||
'payment_status' => 'Pending',
|
||||
]);
|
||||
|
||||
$response = $this->postJson('/api/v1/finance/payment-transactions/TXN-1003/status', [
|
||||
'status' => 'Completed',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertDatabaseHas('payment_transactions', [
|
||||
'transaction_id' => 'TXN-1003',
|
||||
'payment_status' => 'Completed',
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedUsers(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'admin', 'slug' => 'admin', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => 1,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedPayment(): void
|
||||
{
|
||||
DB::table('payments')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_id' => 1,
|
||||
'total_amount' => 100,
|
||||
'paid_amount' => 0,
|
||||
'balance' => 100,
|
||||
'number_of_installments' => 1,
|
||||
'payment_method' => 'cash',
|
||||
'payment_date' => '2025-01-01',
|
||||
'school_year' => '2025-2026',
|
||||
'status' => 'Pending',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Finance;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PaypalTransactionsControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_transactions(): void
|
||||
{
|
||||
$this->seedUsers();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('paypal_payments')->insert([
|
||||
'id' => 1,
|
||||
'transaction_id' => 'PP-1001',
|
||||
'order_id' => 'ORDER-1',
|
||||
'parent_school_id' => 10,
|
||||
'payer_email' => 'payer@example.com',
|
||||
'amount' => 50,
|
||||
'net_amount' => 48,
|
||||
'currency' => 'USD',
|
||||
'status' => 'COMPLETED',
|
||||
'event_type' => 'PAYMENT.SALE.COMPLETED',
|
||||
'created_at' => '2025-01-01 10:00:00',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/finance/paypal-transactions');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('transactions'));
|
||||
}
|
||||
|
||||
public function test_csv_download(): void
|
||||
{
|
||||
$this->seedUsers();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('paypal_payments')->insert([
|
||||
'id' => 1,
|
||||
'transaction_id' => 'PP-1002',
|
||||
'order_id' => 'ORDER-2',
|
||||
'parent_school_id' => 10,
|
||||
'payer_email' => 'payer@example.com',
|
||||
'amount' => 60,
|
||||
'net_amount' => 58,
|
||||
'currency' => 'USD',
|
||||
'status' => 'COMPLETED',
|
||||
'event_type' => 'PAYMENT.SALE.COMPLETED',
|
||||
'created_at' => '2025-01-01 10:00:00',
|
||||
]);
|
||||
|
||||
$response = $this->get('/api/v1/finance/paypal-transactions/csv');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertHeader('Content-Type', 'text/csv');
|
||||
}
|
||||
|
||||
private function seedUsers(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'admin', 'slug' => 'admin', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => 1,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Finance;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ReimbursementControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_create_batch_creates_open_batch(): void
|
||||
{
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
$response = $this->postJson('/api/v1/finance/reimbursements/batches', [
|
||||
'title' => 'Test Batch',
|
||||
]);
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonPath('ok', true);
|
||||
|
||||
$this->assertDatabaseHas('reimbursement_batches', [
|
||||
'title' => 'Test Batch',
|
||||
'status' => 'open',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_mark_donation_updates_expense(): void
|
||||
{
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
DB::table('expenses')->insert([
|
||||
'id' => 1,
|
||||
'category' => 'Expense',
|
||||
'amount' => 12.00,
|
||||
'date_of_purchase' => '2025-02-01',
|
||||
'added_by' => $user->id,
|
||||
'purchased_by' => $user->id,
|
||||
'status' => 'approved',
|
||||
]);
|
||||
|
||||
$response = $this->postJson('/api/v1/finance/reimbursements/mark-donation', [
|
||||
'expense_id' => 1,
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('ok', true);
|
||||
|
||||
$this->assertDatabaseHas('expenses', [
|
||||
'id' => 1,
|
||||
'category' => 'Donation',
|
||||
'status' => 'approved',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_store_reimbursement_creates_record_and_updates_expense(): void
|
||||
{
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 2,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Recipient',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'recipient@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('expenses')->insert([
|
||||
'id' => 2,
|
||||
'category' => 'Expense',
|
||||
'amount' => 50.00,
|
||||
'date_of_purchase' => '2025-02-05',
|
||||
'added_by' => $user->id,
|
||||
'purchased_by' => $user->id,
|
||||
'status' => 'approved',
|
||||
]);
|
||||
|
||||
$response = $this->postJson('/api/v1/finance/reimbursements', [
|
||||
'expense_id' => 2,
|
||||
'amount' => 50.00,
|
||||
'reimbursed_to' => 2,
|
||||
'reimbursement_method' => 'Cash',
|
||||
'description' => 'Test reimbursement',
|
||||
]);
|
||||
|
||||
$response->assertCreated();
|
||||
$response->assertJsonPath('ok', true);
|
||||
|
||||
$this->assertDatabaseHas('reimbursements', [
|
||||
'expense_id' => 2,
|
||||
'amount' => 50.00,
|
||||
'reimbursed_to' => 2,
|
||||
'status' => 'Paid',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('expenses', [
|
||||
'id' => 2,
|
||||
'reimbursement_id' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_reimbursement_updates_fields(): void
|
||||
{
|
||||
$user = $this->createUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
DB::table('reimbursements')->insert([
|
||||
'id' => 10,
|
||||
'amount' => 25.00,
|
||||
'reimbursed_to' => $user->id,
|
||||
'added_by' => $user->id,
|
||||
'status' => 'Paid',
|
||||
'reimbursement_method' => 'Cash',
|
||||
]);
|
||||
|
||||
$response = $this->putJson('/api/v1/finance/reimbursements/10', [
|
||||
'amount' => 30.00,
|
||||
'reimbursed_to' => $user->id,
|
||||
'reimbursement_method' => 'Cash',
|
||||
'description' => 'Updated',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('ok', true);
|
||||
|
||||
$this->assertDatabaseHas('reimbursements', [
|
||||
'id' => 10,
|
||||
'amount' => 30.00,
|
||||
'description' => 'Updated',
|
||||
]);
|
||||
}
|
||||
|
||||
private function createUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Grading;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GradingControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_overview_returns_grading_data(): void
|
||||
{
|
||||
$this->seedBase();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
$response = $this->getJson('/api/v1/grading/overview?school_year=2025-2026&semester=Fall&class_id=1');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('grades'));
|
||||
}
|
||||
|
||||
public function test_toggle_lock_locks_section(): void
|
||||
{
|
||||
$this->seedBase();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
$response = $this->postJson('/api/v1/grading/locks/toggle', [
|
||||
'class_section_id' => 1,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertDatabaseHas('grading_locks', [
|
||||
'class_section_id' => 1,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'is_locked' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedBase(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
['id' => 3, 'config_key' => 'parent_scores_released_fall', 'config_value' => '0'],
|
||||
['id' => 4, 'config_key' => 'parent_scores_released_spring', 'config_value' => '0'],
|
||||
]);
|
||||
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'teacher', 'slug' => 'teacher', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'id' => 1,
|
||||
'user_id' => 1,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
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('students')->insert([
|
||||
'id' => 100,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'User',
|
||||
'school_id' => 1,
|
||||
'age' => 10,
|
||||
'gender' => 'M',
|
||||
'photo_consent' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'id' => 1,
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_event_only' => 0,
|
||||
]);
|
||||
|
||||
DB::table('semester_scores')->insert([
|
||||
'id' => 1,
|
||||
'student_id' => 100,
|
||||
'school_id' => 1,
|
||||
'class_section_id' => 1,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'semester_score' => 88,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Grading;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class HomeworkTrackingControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_tracking_payload(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'teacher', 'slug' => 'teacher', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'id' => 1,
|
||||
'user_id' => 1,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
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('teacher_class')->insert([
|
||||
'id' => 1,
|
||||
'class_section_id' => 1,
|
||||
'teacher_id' => 1,
|
||||
'position' => 'main',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
$response = $this->getJson('/api/v1/grading/homework-tracking?school_year=2025-2026&semester=Fall');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('teachers'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Incidents;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class IncidentControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_current_returns_incidents_and_grades(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
$user = $this->seedUser();
|
||||
|
||||
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('students')->insert([
|
||||
'id' => 10,
|
||||
'parent_id' => 99,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'Tester',
|
||||
'school_id' => '1',
|
||||
'age' => 10,
|
||||
'gender' => 'M',
|
||||
'photo_consent' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'id' => 1,
|
||||
'student_id' => 10,
|
||||
'class_section_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_event_only' => 0,
|
||||
]);
|
||||
|
||||
DB::table('current_incident')->insert([
|
||||
'id' => 1,
|
||||
'student_id' => 10,
|
||||
'student_name' => 'Kid Tester',
|
||||
'grade' => '1',
|
||||
'incident' => 'behavior',
|
||||
'incident_datetime' => '2025-01-01 10:00:00',
|
||||
'incident_state' => 'Open',
|
||||
'updated_by_open' => $user->id,
|
||||
'open_description' => 'Initial',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/incidents/current');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$response->assertJsonCount(1, 'incidents');
|
||||
$response->assertJsonCount(1, 'grades');
|
||||
$response->assertJsonPath('incidents.0.updated_by_open_name', 'Test User');
|
||||
}
|
||||
|
||||
public function test_store_and_close_moves_incident_to_history(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
$user = $this->seedUser();
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 11,
|
||||
'parent_id' => 99,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'Closer',
|
||||
'school_id' => '1',
|
||||
'age' => 11,
|
||||
'gender' => 'F',
|
||||
'photo_consent' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$storeResponse = $this->postJson('/api/v1/incidents', [
|
||||
'student_id' => 11,
|
||||
'grade' => '1',
|
||||
'incident' => 'behavior',
|
||||
'description' => 'Needs attention',
|
||||
]);
|
||||
|
||||
$storeResponse->assertOk();
|
||||
$storeResponse->assertJson(['ok' => true, 'created' => true]);
|
||||
$currentId = $storeResponse->json('incident_id');
|
||||
|
||||
$closeResponse = $this->postJson('/api/v1/incidents/' . $currentId . '/close', [
|
||||
'state_description' => 'Resolved',
|
||||
'action_taken' => 'Spoke with student',
|
||||
]);
|
||||
|
||||
$closeResponse->assertOk();
|
||||
$closeResponse->assertJson(['ok' => true]);
|
||||
|
||||
$historyId = $closeResponse->json('incident_id');
|
||||
|
||||
$this->assertDatabaseHas('incident', [
|
||||
'id' => $historyId,
|
||||
'student_id' => 11,
|
||||
'incident_state' => 'Closed',
|
||||
]);
|
||||
$this->assertDatabaseMissing('current_incident', ['id' => $currentId]);
|
||||
}
|
||||
|
||||
private function seedUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Test',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'test@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Reports;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FilesControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_receipt_meta_returns_file_payload(): void
|
||||
{
|
||||
$user = $this->seedUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$dir = storage_path('uploads/receipts');
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
$path = $dir . DIRECTORY_SEPARATOR . 'sample.pdf';
|
||||
file_put_contents($path, 'PDFDATA');
|
||||
|
||||
$response = $this->getJson('/api/v1/files/receipts/sample.pdf?meta=1');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$response->assertJsonPath('file.name', 'sample.pdf');
|
||||
$response->assertJsonPath('file.size', 7);
|
||||
}
|
||||
|
||||
public function test_exam_draft_teacher_streams_with_download_name(): 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' => 'Midterm',
|
||||
'draft_title' => 'Draft',
|
||||
'teacher_file' => 'draft1.pdf',
|
||||
'version' => 2,
|
||||
'status' => 'draft',
|
||||
]);
|
||||
|
||||
$dir = storage_path('uploads/exams/drafts');
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
$path = $dir . DIRECTORY_SEPARATOR . 'draft1.pdf';
|
||||
file_put_contents($path, 'PDFDATA');
|
||||
|
||||
$response = $this->get('/api/v1/files/exams/teacher/draft1.pdf');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertHeader('Content-Disposition', 'inline; filename="1a_midterm_v2.pdf"');
|
||||
}
|
||||
|
||||
private function seedUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Test',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'test@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Scores;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FinalControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_final_scores(): void
|
||||
{
|
||||
$this->seedBase();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('final_exam')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'score' => 90,
|
||||
'semester' => 'Spring',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/scores/final?class_section_id=1&semester=Spring&school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('students'));
|
||||
}
|
||||
|
||||
private function seedBase(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'teacher', 'slug' => 'teacher', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Spring',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => 1,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'class_section_id' => 1,
|
||||
'class_section_name' => '1A',
|
||||
'class_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 100,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'User',
|
||||
'school_id' => 1,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'is_event_only' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Scores;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class HomeworkControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_homework_scores(): void
|
||||
{
|
||||
$this->seedBase();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('homework')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'homework_index' => 1,
|
||||
'score' => 90,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/scores/homework?class_section_id=1&semester=Fall&school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('students'));
|
||||
}
|
||||
|
||||
private function seedBase(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'teacher', 'slug' => 'teacher', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => 1,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'class_section_id' => 1,
|
||||
'class_section_name' => '1A',
|
||||
'class_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 100,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'User',
|
||||
'school_id' => 1,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'is_event_only' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Scores;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class MidtermControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_midterm_scores(): void
|
||||
{
|
||||
$this->seedBase();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('midterm_exam')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'score' => 85,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/scores/midterm?class_section_id=1&semester=Fall&school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('students'));
|
||||
}
|
||||
|
||||
private function seedBase(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'teacher', 'slug' => 'teacher', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => 1,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'class_section_id' => 1,
|
||||
'class_section_name' => '1A',
|
||||
'class_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 100,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'User',
|
||||
'school_id' => 1,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'is_event_only' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Scores;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ParticipationControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_participation_scores(): void
|
||||
{
|
||||
$this->seedBase();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('participation')->insert([
|
||||
'id' => 1,
|
||||
'student_id' => 100,
|
||||
'school_id' => 1,
|
||||
'class_section_id' => 1,
|
||||
'updated_by' => 1,
|
||||
'score' => 93,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/scores/participation?class_section_id=1&semester=Fall&school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('students'));
|
||||
}
|
||||
|
||||
private function seedBase(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'teacher', 'slug' => 'teacher', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'id' => 1,
|
||||
'user_id' => 1,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
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('students')->insert([
|
||||
'id' => 100,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'User',
|
||||
'school_id' => 1,
|
||||
'age' => 10,
|
||||
'gender' => 'M',
|
||||
'photo_consent' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'id' => 1,
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_event_only' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Scores;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProjectControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_project_scores(): void
|
||||
{
|
||||
$this->seedBase();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('project')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'project_index' => 1,
|
||||
'score' => 95,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/scores/projects?class_section_id=1&semester=Fall&school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('students'));
|
||||
}
|
||||
|
||||
private function seedBase(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'teacher', 'slug' => 'teacher', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => 1,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'class_section_id' => 1,
|
||||
'class_section_name' => '1A',
|
||||
'class_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 100,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'User',
|
||||
'school_id' => 1,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'is_event_only' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Scores;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class QuizControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_quiz_scores(): void
|
||||
{
|
||||
$this->seedBase();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('quiz')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'quiz_index' => 1,
|
||||
'score' => 88,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/scores/quizzes?class_section_id=1&semester=Fall&school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('students'));
|
||||
}
|
||||
|
||||
private function seedBase(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'teacher', 'slug' => 'teacher', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => 1,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'class_section_id' => 1,
|
||||
'class_section_name' => '1A',
|
||||
'class_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 100,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'User',
|
||||
'school_id' => 1,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'is_event_only' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Scores;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ScoreCommentControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_store_rejects_short_comment(): void
|
||||
{
|
||||
$this->seedBase();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
$response = $this->postJson('/api/v1/scores/comments', [
|
||||
'class_section_id' => 1,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'comments' => [
|
||||
100 => [
|
||||
'ptap' => 'Too short',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
}
|
||||
|
||||
public function test_index_returns_comments(): void
|
||||
{
|
||||
$this->seedBase();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('score_comments')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'score_type' => 'ptap',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'comment' => 'Kid is doing great in class and shows effort and focus in every session.',
|
||||
'commented_by' => 1,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/scores/comments?class_section_id=1&semester=Fall&school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('students'));
|
||||
}
|
||||
|
||||
private function seedBase(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'teacher', 'slug' => 'teacher', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => 1,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'class_section_id' => 1,
|
||||
'class_section_name' => '1A',
|
||||
'class_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 100,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'User',
|
||||
'school_id' => 1,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'is_event_only' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Scores;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ScoreControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_overview_returns_students(): void
|
||||
{
|
||||
$this->seedBase();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('teacher_class')->insert([
|
||||
'teacher_id' => 1,
|
||||
'class_section_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/scores/overview?class_section_id=1&semester=Fall&school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('students'));
|
||||
}
|
||||
|
||||
public function test_lock_creates_grading_lock(): void
|
||||
{
|
||||
$this->seedBase();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
$response = $this->postJson('/api/v1/scores/lock', [
|
||||
'class_section_id' => 1,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'missing_ok' => [],
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertDatabaseHas('grading_locks', [
|
||||
'class_section_id' => 1,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'is_locked' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedBase(): void
|
||||
{
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'teacher', 'slug' => 'teacher', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => 1,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'class_section_id' => 1,
|
||||
'class_section_name' => '1A',
|
||||
'class_id' => 1,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 100,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'User',
|
||||
'school_id' => 1,
|
||||
'age' => 10,
|
||||
'gender' => 'M',
|
||||
'photo_consent' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'is_event_only' => 0,
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Scores;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ScorePredictorControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_predictions(): void
|
||||
{
|
||||
$this->seedBase();
|
||||
Sanctum::actingAs(User::query()->findOrFail(1));
|
||||
|
||||
DB::table('semester_scores')->insert([
|
||||
'id' => 1,
|
||||
'student_id' => 100,
|
||||
'school_id' => 1,
|
||||
'class_section_id' => 1,
|
||||
'semester' => 'spring',
|
||||
'school_year' => '2025-2026',
|
||||
'semester_score' => 90,
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/scores/predictor?school_year=2025-2026&class_section_id=1');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('students'));
|
||||
}
|
||||
|
||||
private function seedBase(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
['id' => 3, 'config_key' => 'trophy_score', 'config_value' => '94'],
|
||||
['id' => 4, 'config_key' => 'pass_score', 'config_value' => '60'],
|
||||
]);
|
||||
|
||||
DB::table('roles')->insert([
|
||||
['id' => 1, 'name' => 'teacher', 'slug' => 'teacher', 'is_active' => 1],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Teacher',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'teacher@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'id' => 1,
|
||||
'user_id' => 1,
|
||||
'role_id' => 1,
|
||||
]);
|
||||
|
||||
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('students')->insert([
|
||||
'id' => 100,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'User',
|
||||
'school_id' => 1,
|
||||
'age' => 10,
|
||||
'gender' => 'M',
|
||||
'photo_consent' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'id' => 1,
|
||||
'student_id' => 100,
|
||||
'class_section_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_event_only' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\System;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SemesterRangeControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_school_year_range_uses_config_dates(): void
|
||||
{
|
||||
$user = $this->seedUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'fall_semester_start', 'config_value' => '2025-09-05'],
|
||||
['id' => 2, 'config_key' => 'last_school_day', 'config_value' => '2026-06-15'],
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/system/semester-range/school-year?school_year=2025-2026');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('range.start_date', '2025-09-05');
|
||||
$response->assertJsonPath('range.end_date', '2026-06-15');
|
||||
}
|
||||
|
||||
public function test_resolve_returns_semester_for_date(): void
|
||||
{
|
||||
$user = $this->seedUser();
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'fall_semester_start', 'config_value' => '2025-09-01'],
|
||||
['id' => 2, 'config_key' => 'spring_semester_start', 'config_value' => '2026-01-20'],
|
||||
['id' => 3, 'config_key' => 'last_school_day', 'config_value' => '2026-06-01'],
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/system/semester-range/resolve?date=2025-10-01');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('resolution.semester', 'Fall');
|
||||
}
|
||||
|
||||
private function seedUser(): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Test',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'test@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Users;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UserControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_user_list_returns_users_with_roles(): void
|
||||
{
|
||||
$admin = $this->seedUser(1, 'admin@example.com');
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
DB::table('roles')->insert([
|
||||
'id' => 10,
|
||||
'name' => 'Teacher',
|
||||
'slug' => 'teacher',
|
||||
'description' => 'Teacher role',
|
||||
'dashboard_route' => 'teacher/dashboard',
|
||||
'priority' => 1,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
$this->seedUser(2, 'member@example.com');
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => 2,
|
||||
'role_id' => 10,
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/users');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$response->assertJsonFragment(['email' => 'member@example.com']);
|
||||
$response->assertJsonFragment(['roles' => ['Teacher']]);
|
||||
}
|
||||
|
||||
public function test_create_user_creates_user_and_role(): void
|
||||
{
|
||||
$admin = $this->seedUser(1, 'admin@example.com');
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
DB::table('roles')->insert([
|
||||
'id' => 20,
|
||||
'name' => 'Parent',
|
||||
'slug' => 'parent',
|
||||
'description' => 'Parent role',
|
||||
'dashboard_route' => 'parent/dashboard',
|
||||
'priority' => 2,
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
$response = $this->postJson('/api/v1/users', [
|
||||
'firstname' => 'New',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5554443333',
|
||||
'email' => 'new.user@example.com',
|
||||
'address_street' => '123 Main St',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => true,
|
||||
'role_id' => 20,
|
||||
'password' => 'secret123',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
$response->assertJson(['ok' => true]);
|
||||
|
||||
$userId = (int) ($response->json('user_id') ?? 0);
|
||||
$this->assertGreaterThan(0, $userId);
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $userId,
|
||||
'email' => 'new.user@example.com',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('user_roles', [
|
||||
'user_id' => $userId,
|
||||
'role_id' => 20,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_login_activity_returns_paginated_results(): void
|
||||
{
|
||||
$admin = $this->seedUser(1, 'admin@example.com');
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
DB::table('login_activity')->insert([
|
||||
'user_id' => 1,
|
||||
'email' => 'admin@example.com',
|
||||
'login_time' => '2025-01-02 09:00:00',
|
||||
'logout_time' => null,
|
||||
'ip_address' => '10.0.0.1',
|
||||
'user_agent' => 'TestAgent',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('login_activity')->insert([
|
||||
'user_id' => 1,
|
||||
'email' => 'admin@example.com',
|
||||
'login_time' => '2025-01-01 09:00:00',
|
||||
'logout_time' => null,
|
||||
'ip_address' => '10.0.0.2',
|
||||
'user_agent' => 'TestAgent',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/users/login-activity?per_page=1&page=2');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$response->assertJsonPath('pagination.total', 2);
|
||||
$response->assertJsonPath('pagination.currentPage', 2);
|
||||
$response->assertJsonPath('activities.0.ip_address', '10.0.0.2');
|
||||
}
|
||||
|
||||
private function seedUser(int $id, string $email): User
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => $id,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Test',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => $email,
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail($id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user