59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?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',
|
|
]);
|
|
}
|
|
}
|