67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\Notifications;
|
|
|
|
use App\Services\Notifications\NotificationManagementService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\TestCase;
|
|
|
|
class NotificationManagementServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_update_modifies_notification(): void
|
|
{
|
|
DB::table('notifications')->insert([
|
|
'id' => 1,
|
|
'title' => 'Old',
|
|
'message' => 'Message',
|
|
'target_group' => 'parent',
|
|
'delivery_channels' => json_encode(['in_app']),
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$service = new NotificationManagementService;
|
|
$result = $service->update(1, ['title' => 'New']);
|
|
|
|
$this->assertTrue($result['ok']);
|
|
$this->assertDatabaseHas('notifications', [
|
|
'id' => 1,
|
|
'title' => 'New',
|
|
]);
|
|
}
|
|
|
|
public function test_update_returns_false_when_missing(): void
|
|
{
|
|
$service = new NotificationManagementService;
|
|
$result = $service->update(999, ['title' => 'New']);
|
|
|
|
$this->assertFalse($result['ok']);
|
|
}
|
|
|
|
public function test_delete_and_restore_notification(): void
|
|
{
|
|
DB::table('notifications')->insert([
|
|
'id' => 1,
|
|
'title' => 'Old',
|
|
'message' => 'Message',
|
|
'target_group' => 'parent',
|
|
'delivery_channels' => json_encode(['in_app']),
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$service = new NotificationManagementService;
|
|
$this->assertTrue($service->delete(1));
|
|
$this->assertSoftDeleted('notifications', ['id' => 1]);
|
|
|
|
$this->assertTrue($service->restore(1));
|
|
$this->assertDatabaseHas('notifications', [
|
|
'id' => 1,
|
|
'deleted_at' => null,
|
|
]);
|
|
}
|
|
}
|