HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/be.naniguide.com/tests/Feature/UnauthenticatedResponseTest.php
<?php

/**
 * Feature tests for the auth-failure response shape after the Laravel 12
 * exception handler was wired up in bootstrap/app.php (replacing the dead
 * app/Exceptions/Handler.php). Covers the three branches of the renderer:
 *   - JSON request    → 401 with `{"message":"Unauthenticated."}`
 *   - HTML admin path → redirect to refactor.admin.login
 *   - HTML customer   → redirect to the `login` route
 */

uses(\Tests\TestCase::class);

test('JSON 401 returns the framework-default message shape', function () {
    $response = $this->getJson('/rui/admin');
    expect($response->status())->toBe(401);
    expect($response->json('message'))->toBe('Unauthenticated.');
});

test('HTML admin path 401 redirects to the admin login', function () {
    $response = $this->get('/rui/admin');
    $response->assertRedirect(route('refactor.admin.login'));
});

test('HTML customer path 401 redirects to the customer login', function () {
    $response = $this->get('/dashboard');
    $response->assertRedirect(route('login'));
});