add notifications logic and add support of both JWT and Sanctum
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Notifications;
|
||||
|
||||
use App\Services\Notifications\UserNotificationDispatchService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UserNotificationDispatchServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_notify_user_creates_notification(): void
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5551112222',
|
||||
'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',
|
||||
]);
|
||||
|
||||
$service = new UserNotificationDispatchService();
|
||||
$result = $service->notifyUser(1, 'Title', 'Message', ['in_app'], 'registration', 'parent');
|
||||
|
||||
$this->assertTrue($result['ok']);
|
||||
$this->assertDatabaseHas('notifications', [
|
||||
'title' => 'Title',
|
||||
'target_group' => 'parent',
|
||||
]);
|
||||
$this->assertDatabaseHas('user_notifications', [
|
||||
'user_id' => 1,
|
||||
'is_read' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_notify_user_rejects_invalid_user(): void
|
||||
{
|
||||
$service = new UserNotificationDispatchService();
|
||||
$result = $service->notifyUser(0, 'Title', 'Message');
|
||||
|
||||
$this->assertFalse($result['ok']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user