Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 28s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
54 lines
2.1 KiB
PHP
54 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use App\Notifications\DashboardAlert;
|
|
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class NotificationInboxTest extends TestCase
|
|
{
|
|
use LazilyRefreshDatabase;
|
|
|
|
public function test_guests_cannot_read_notifications(): void
|
|
{
|
|
$this->getJson(route('notifications.index'))->assertUnauthorized();
|
|
}
|
|
|
|
public function test_user_sees_only_their_notifications_and_can_mark_them_read(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$other = User::factory()->create();
|
|
$user->notify(new DashboardAlert('order', 'New Etsy order #1', 'Buyer · GBP 5.00', 'success', route('shipping')));
|
|
$other->notify(new DashboardAlert('order', 'Private', 'Not yours', 'info'));
|
|
|
|
$response = $this->actingAs($user)->getJson(route('notifications.index'))->assertOk()
|
|
->assertJsonPath('unread', 1)->assertJsonCount(1, 'items')
|
|
->assertJsonPath('items.0.title', 'New Etsy order #1')->assertJsonPath('items.0.level', 'success');
|
|
|
|
$id = $response->json('items.0.id');
|
|
$this->actingAs($other)->postJson(route('notifications.read', $id))->assertOk();
|
|
$this->assertSame(1, $user->unreadNotifications()->count());
|
|
|
|
$this->actingAs($user)->postJson(route('notifications.read', $id))->assertOk();
|
|
$this->assertSame(0, $user->unreadNotifications()->count());
|
|
}
|
|
|
|
public function test_mark_all_read_clears_the_unread_count(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$user->notify(new DashboardAlert('print', 'One', 'a'));
|
|
$user->notify(new DashboardAlert('print', 'Two', 'b'));
|
|
|
|
$this->actingAs($user)->postJson(route('notifications.read-all'))->assertOk();
|
|
$this->actingAs($user)->getJson(route('notifications.index'))->assertJsonPath('unread', 0);
|
|
}
|
|
|
|
public function test_pages_include_the_notification_bell(): void
|
|
{
|
|
$this->actingAs(User::factory()->create())->get(route('dashboard'))->assertOk()
|
|
->assertSee('data-notifications-toggle', false)->assertSee('data-toast-region', false);
|
|
}
|
|
}
|