make(NotificationRepository::class), $this->make(UserRepository::class), $this->make(LanguageCore::class), ); } public function test_consume_flash_notification_returns_null_when_empty(): void { session(['notification' => '']); $service = $this->makeService(); $this->assertNull($service->consumeFlashNotification()); } public function test_consume_flash_notification_returns_payload_and_clears_session(): void { session(['notification' => 'Saved!']); session(['notificationType' => 'success']); session(['eventId' => 'ticket-42']); $service = $this->makeService(); $payload = $service->consumeFlashNotification(); $this->assertSame([ 'notification' => 'Saved!', 'type' => 'success', 'eventId' => 'ticket-42', ], $payload); // Read-once: session keys are cleared after consumption. $this->assertSame('', session('notification')); $this->assertSame('', session('notificationType')); $this->assertSame('', session('eventId')); } public function test_consume_flash_notification_defaults_missing_type_and_event(): void { session()->forget('notificationType'); session()->forget('eventId'); session(['notification' => 'Hello']); $service = $this->makeService(); $payload = $service->consumeFlashNotification(); $this->assertSame([ 'notification' => 'Hello', 'type' => '', 'eventId' => '', ], $payload); } // --------------------------------------------------------------------- // markRead() — session-based JSON-RPC wrapper (must target the session user) // --------------------------------------------------------------------- public function test_mark_read_all_targets_the_session_user(): void { session(['userdata' => ['id' => 42]]); $capturedUserId = null; $repo = $this->make(NotificationRepository::class, [ 'markAllNotificationRead' => function ($userId, ...$rest) use (&$capturedUserId) { $capturedUserId = $userId; return true; }, ]); $service = new Notifications( $repo, $this->make(UserRepository::class), $this->make(LanguageCore::class), ); $this->assertTrue($service->markRead('all')); $this->assertSame(42, $capturedUserId, "markRead('all') must use the session user"); } public function test_mark_read_specific_id_delegates_to_repo(): void { session(['userdata' => ['id' => 7]]); $calledWith = null; $repo = $this->make(NotificationRepository::class, [ 'markNotificationRead' => function ($id, ...$rest) use (&$calledWith) { $calledWith = $id; return true; }, ]); $service = new Notifications( $repo, $this->make(UserRepository::class), $this->make(LanguageCore::class), ); $this->assertTrue($service->markRead(5)); $this->assertSame(5, $calledWith); } }