add all controllers logic

This commit is contained in:
root
2026-03-11 17:53:15 -04:00
parent 3e6c577085
commit 2ef71cc92b
421 changed files with 12009 additions and 5211 deletions
@@ -0,0 +1,72 @@
<?php
namespace Tests\Unit\Services\Messaging;
use App\Models\User;
use App\Services\Messaging\MessageCommandService;
use App\Services\System\GlobalConfigService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class MessageCommandServiceTest extends TestCase
{
use RefreshDatabase;
public function test_create_sends_message(): void
{
DB::table('configuration')->insert([
['config_key' => 'school_year', 'config_value' => '2025-2026'],
['config_key' => 'semester', 'config_value' => 'Fall'],
]);
$sender = $this->createUser('sender@example.com');
$recipient = $this->createUser('recipient@example.com');
$service = new MessageCommandService(new GlobalConfigService());
$message = $service->create($sender->id, [
'recipient_id' => $recipient->id,
'subject' => 'Subject',
'message' => 'Body',
]);
$this->assertNotNull($message->id);
$this->assertDatabaseHas('messages', [
'id' => $message->id,
'subject' => 'Subject',
]);
}
public function test_create_rejects_invalid_role(): void
{
$sender = $this->createUser('sender2@example.com');
$service = new MessageCommandService(new GlobalConfigService());
$this->expectException(\RuntimeException::class);
$service->create($sender->id, [
'recipient_role' => 'invalid',
'subject' => 'Subject',
'message' => 'Body',
]);
}
private function createUser(string $email): User
{
return User::query()->create([
'firstname' => 'Test',
'lastname' => 'User',
'email' => $email,
'cellphone' => '5555555555',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'status' => 'Active',
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
}
}
@@ -0,0 +1,58 @@
<?php
namespace Tests\Unit\Services\Messaging;
use App\Models\Message;
use App\Models\User;
use App\Services\Messaging\MessageQueryService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class MessageQueryServiceTest extends TestCase
{
use RefreshDatabase;
public function test_inbox_filters_messages(): void
{
$sender = $this->createUser('sender@example.com');
$recipient = $this->createUser('recipient@example.com');
Message::query()->create([
'sender_id' => $sender->id,
'recipient_id' => $recipient->id,
'subject' => 'Hello',
'message' => 'Body',
'sent_datetime' => now(),
'read_status' => 0,
'message_number' => 'MSG-10',
'priority' => 'normal',
'status' => 'sent',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
$service = new MessageQueryService();
$paginator = $service->inbox($recipient->id, [], 1, 20);
$this->assertSame(1, $paginator->total());
}
private function createUser(string $email): User
{
return User::query()->create([
'firstname' => 'Test',
'lastname' => 'User',
'email' => $email,
'cellphone' => '5555555555',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'status' => 'Active',
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
}
}
@@ -0,0 +1,111 @@
<?php
namespace Tests\Unit\Services\Messaging;
use App\Models\ParentModel;
use App\Models\Student;
use App\Models\User;
use App\Services\Messaging\MessageRecipientService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class MessageRecipientServiceTest extends TestCase
{
use RefreshDatabase;
public function test_teachers_returns_list(): void
{
$teacher = $this->createUser('teacher@example.com');
DB::table('teacher_class')->insert([
'teacher_id' => $teacher->id,
'class_section_id' => 1,
'position' => 'main',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
]);
$service = new MessageRecipientService();
$rows = $service->teachers();
$this->assertSame($teacher->id, $rows[0]['id']);
}
public function test_parents_returns_list(): void
{
$teacher = $this->createUser('teacher2@example.com');
$parent = $this->createUser('parent@example.com');
$secondParent = $this->createUser('parent2@example.com');
DB::table('teacher_class')->insert([
'teacher_id' => $teacher->id,
'class_section_id' => 2,
'position' => 'main',
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
]);
$studentId = Student::query()->insertGetId([
'school_id' => 'S-1',
'firstname' => 'Student',
'lastname' => 'One',
'age' => 10,
'gender' => 'Male',
'photo_consent' => 1,
'parent_id' => $parent->id,
'year_of_registration' => '2025',
'is_active' => 1,
'is_new' => 1,
]);
DB::table('student_class')->insert([
'student_id' => $studentId,
'class_section_id' => 2,
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
]);
ParentModel::query()->create([
'secondparent_firstname' => 'Second',
'secondparent_lastname' => 'Parent',
'secondparent_email' => 'parent2@example.com',
'secondparent_phone' => '5555555555',
'firstparent_id' => $parent->id,
'secondparent_id' => $secondParent->id,
'school_year' => '2025-2026',
]);
$service = new MessageRecipientService();
$rows = $service->parents();
$ids = array_column($rows, 'id');
$this->assertContains($parent->id, $ids);
$this->assertContains($secondParent->id, $ids);
}
private function createUser(string $email): User
{
return User::query()->create([
'firstname' => 'Test',
'lastname' => 'User',
'email' => $email,
'cellphone' => '5555555555',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'status' => 'Active',
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
}
}