singleloginsystem/tests/Feature/NotificationResolutionTest.php
= 67002d6979 Feat: add ticket assignment, comments, and notifications
- Added migration for ticket assignment and comments (`assigned_user_id` and `ticket_replies` table).
- Implemented `TicketAssignedNotification` and `TicketCommentedNotification`.
- Created `ReplyData`, `TicketListData`, and `PostReplyRequest` data classes.
- Introduced `ResolveNotificationRouteController` for modular notification redirection.
- Updated UI to support assigning users and posting comments on tickets.
- User is navigated to comments page when clicked on the ticket, upon navigation ticket details modal is opened.
- Extended tests to cover assignments, comments, status transitions, and notifications.
2026-05-26 07:01:18 +00:00

64 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Models\{Ticket, TicketStatus, User};
use App\Notifications\TicketAssignedNotification;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class NotificationResolutionTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->seed(DatabaseSeeder::class);
}
public function test_guest_cannot_resolve_notifications(): void
{
$this->get(route('notifications.resolve', ['id' => 'some-uuid']))
->assertRedirect(route('login'));
}
public function test_user_can_resolve_and_redirect_notification_modularly(): void
{
$creator = User::factory()->create();
$creator->assignRole('user');
$supportUser = User::factory()->create();
$supportUser->assignRole('Support');
$openStatus = TicketStatus::where('name', 'open')->firstOrFail();
$ticket = Ticket::create([
'user_id' => $creator->id,
'issue_category' => 'Billing Query',
'status_id' => $openStatus->id,
'assigned_user_id' => $supportUser->id,
]);
// Send a notification
$supportUser->notify(new TicketAssignedNotification($ticket));
// Retrieve unread notification
$notification = $supportUser->unreadNotifications()->firstOrFail();
$this->actingAs($supportUser);
// Resolve notification
$response = $this->get(route('notifications.resolve', ['id' => $notification->id]));
// Should mark as read
$this->assertSame(0, $supportUser->unreadNotifications()->count());
// Should redirect modularly to support tickets index page with ticket ID parameter
$response->assertRedirect(route('tickets.index', ['ticket' => $ticket->id]));
}
}