add more controller

This commit is contained in:
root
2026-03-10 00:48:32 -04:00
parent 5eeaec0257
commit 20ee70d153
151 changed files with 9481 additions and 8407 deletions
@@ -0,0 +1,124 @@
<?php
namespace Tests\Feature\Api\V1\Administrator;
use App\Models\EmergencyContact;
use App\Models\Student;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class EmergencyContactControllerTest extends TestCase
{
use RefreshDatabase;
public function test_index_returns_grouped_contacts(): void
{
$admin = User::factory()->create();
$parent = User::factory()->create([
'firstname' => 'Omar',
'lastname' => 'Parent',
'cellphone' => '1111111111',
]);
DB::table('parents')->insert([
'secondparent_firstname' => 'Nora',
'secondparent_lastname' => 'Parent',
'secondparent_gender' => 'Female',
'secondparent_email' => 'nora.parent@example.com',
'secondparent_phone' => '2222222222',
'firstparent_id' => $parent->id,
'secondparent_id' => 1234,
'semester' => 'Fall',
'school_year' => '2025-2026',
'created_at' => now(),
'updated_at' => now(),
]);
Student::factory()->create([
'parent_id' => $parent->id,
'firstname' => 'Rami',
'lastname' => 'Student',
'school_id' => 'S-202',
]);
EmergencyContact::query()->create([
'parent_id' => $parent->id,
'emergency_contact_name' => 'Uncle Amin',
'cellphone' => '3333333333',
'email' => 'amin@example.com',
'relation' => 'Uncle',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
Sanctum::actingAs($admin);
$response = $this->getJson('/api/v1/administrator/emergency-contacts');
$response->assertOk();
$response->assertJson(['ok' => true]);
$response->assertJsonPath('groups.0.parent_id', $parent->id);
$response->assertJsonPath('groups.0.parent_phones.0', '1111111111');
$response->assertJsonPath('groups.0.parent_phones.1', '2222222222');
}
public function test_update_changes_emergency_contact(): void
{
$admin = User::factory()->create();
$parent = User::factory()->create();
$contact = EmergencyContact::query()->create([
'parent_id' => $parent->id,
'emergency_contact_name' => 'Old Name',
'cellphone' => '4444444444',
'email' => 'old@example.com',
'relation' => 'Friend',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
Sanctum::actingAs($admin);
$response = $this->patchJson('/api/v1/administrator/emergency-contacts/' . $contact->id, [
'name' => 'New Name',
'cellphone' => '5555555555',
'email' => 'new@example.com',
'relation' => 'Neighbor',
]);
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertDatabaseHas('emergency_contacts', [
'id' => $contact->id,
'emergency_contact_name' => 'New Name',
'email' => 'new@example.com',
'relation' => 'Neighbor',
]);
}
public function test_destroy_deletes_emergency_contact(): void
{
$admin = User::factory()->create();
$parent = User::factory()->create();
$contact = EmergencyContact::query()->create([
'parent_id' => $parent->id,
'emergency_contact_name' => 'Delete Name',
'cellphone' => '6666666666',
'email' => 'delete@example.com',
'relation' => 'Friend',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
Sanctum::actingAs($admin);
$response = $this->deleteJson('/api/v1/administrator/emergency-contacts/' . $contact->id);
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertDatabaseMissing('emergency_contacts', [
'id' => $contact->id,
]);
}
}
@@ -0,0 +1,141 @@
<?php
namespace Tests\Feature\Api\V1\Administrator;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class TeacherClassAssignmentControllerTest extends TestCase
{
use RefreshDatabase;
public function test_index_returns_teachers_and_classes(): void
{
$this->seedConfig();
$admin = $this->seedAdminUser();
$this->seedTeacherUser();
$this->seedClassSection();
Sanctum::actingAs($admin);
$response = $this->getJson('/api/v1/administrator/teacher-class/assignments?school_year=2025-2026');
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertNotEmpty($response->json('teachers'));
$this->assertNotEmpty($response->json('classes'));
}
public function test_store_and_delete_assignment(): void
{
$this->seedConfig();
$admin = $this->seedAdminUser();
$teacher = $this->seedTeacherUser();
$classSectionId = $this->seedClassSection();
Sanctum::actingAs($admin);
$storeResponse = $this->postJson('/api/v1/administrator/teacher-class/assign', [
'teacher_id' => $teacher->id,
'class_section_id' => $classSectionId,
'teacher_role' => 'teacher',
'school_year' => '2025-2026',
]);
$storeResponse->assertOk();
$this->assertDatabaseHas('teacher_class', [
'teacher_id' => $teacher->id,
'class_section_id' => $classSectionId,
'position' => 'main',
]);
$deleteResponse = $this->postJson('/api/v1/administrator/teacher-class/delete', [
'teacher_id' => $teacher->id,
'class_section_id' => $classSectionId,
'position' => 'main',
'school_year' => '2025-2026',
]);
$deleteResponse->assertOk();
$this->assertDatabaseMissing('teacher_class', [
'teacher_id' => $teacher->id,
'class_section_id' => $classSectionId,
'position' => 'main',
]);
}
private function seedConfig(): void
{
DB::table('configuration')->insert([
['config_key' => 'school_year', 'config_value' => '2025-2026'],
['config_key' => 'semester', 'config_value' => 'Fall'],
]);
}
private function seedAdminUser(): User
{
$userId = DB::table('users')->insertGetId([
'firstname' => 'Admin',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'admin.teacher.assignment@example.com',
'address_street' => '123 Street',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'password' => bcrypt('password'),
'user_type' => 'primary',
'semester' => 'Fall',
'school_year' => '2025-2026',
'status' => 'Active',
]);
return User::query()->findOrFail($userId);
}
private function seedTeacherUser(): User
{
$roleId = DB::table('roles')->insertGetId([
'name' => 'teacher',
]);
$userId = DB::table('users')->insertGetId([
'firstname' => 'Olivia',
'lastname' => 'Teacher',
'cellphone' => '6666666666',
'email' => 'teacher.assignment.admin@example.com',
'address_street' => '123 Street',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'password' => bcrypt('password'),
'user_type' => 'primary',
'semester' => 'Fall',
'school_year' => '2025-2026',
'status' => 'Active',
]);
DB::table('user_roles')->insert([
'user_id' => $userId,
'role_id' => $roleId,
]);
return User::query()->findOrFail($userId);
}
private function seedClassSection(): int
{
DB::table('classSection')->insert([
'class_id' => 1,
'class_section_id' => 401,
'class_section_name' => '4A',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
return 401;
}
}