37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
use App\Models\User;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* T6.3 — every exception reaching an api/* route gets a consistent JSON
|
||
|
|
* envelope, regardless of the client's Accept header, and never a bare
|
||
|
|
* unenveloped 500 (bootstrap/app.php).
|
||
|
|
*/
|
||
|
|
test('an unauthenticated request to a protected api route gets a 401 JSON envelope', function () {
|
||
|
|
$this->postJson('/api/v1/bookings/EVB-DOES-NOT-EXIST/cancel')
|
||
|
|
->assertUnauthorized()
|
||
|
|
->assertJsonStructure(['message']);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('a route model binding miss on an api route gets a 404 JSON envelope', function () {
|
||
|
|
$user = User::factory()->create();
|
||
|
|
$token = $user->createToken('test')->plainTextToken;
|
||
|
|
|
||
|
|
$this->withHeader('Authorization', "Bearer {$token}")
|
||
|
|
->getJson('/api/v1/bookings/EVB-DOES-NOT-EXIST')
|
||
|
|
->assertNotFound()
|
||
|
|
->assertJsonStructure(['message']);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('an unknown api route gets a 404 JSON envelope, not an HTML page', function () {
|
||
|
|
$this->getJson('/api/v1/this-route-does-not-exist')
|
||
|
|
->assertNotFound()
|
||
|
|
->assertJsonStructure(['message']);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('an unsupported HTTP method on a known api route gets a 405 JSON envelope', function () {
|
||
|
|
$this->putJson('/api/v1/companies')
|
||
|
|
->assertStatus(405)
|
||
|
|
->assertJsonStructure(['message']);
|
||
|
|
});
|