test(bo): add negative authorization tests for unauthenticated and unauthorized requests [AUD-TST-003]

This commit is contained in:
Jérémy Munsch 2026-08-26 11:17:17 +02:00
parent 4ce5488bae
commit 30077e68ad
No known key found for this signature in database
GPG key ID: 2AAECDA6B7330F91
2 changed files with 35 additions and 1 deletions

View file

@ -92,8 +92,25 @@ describe('DiscountsController', function () {
$discount->save();
$response = $this->delete("/bo/discounts/{$discount->id}");
// THEN
expect(Discount::find($discount->id))->toBeNull();
$response->assertRedirect('/bo/discounts');
});
describe('authorization rejections', function () {
it('redirects unauthenticated guest to login', function () {
auth('backend')->logout();
$response = $this->get('/bo/discounts');
$response->assertRedirect('/bo/login');
});
it('denies access to unauthorized user with customer role', function () {
$user = User::factory()->make(['role' => UserRole::Customer]);
$this->actingAs($user, 'backend');
$response = $this->get('/bo/discounts');
expect($response->status())->toBe(403);
});
});
});

View file

@ -232,4 +232,21 @@ describe('ProductsController', function () {
// THEN
expect(Product::find($product->id))->toBeNull();
});
describe('authorization rejections', function () {
it('redirects unauthenticated guest to login', function () {
auth('backend')->logout();
$response = $this->get('/bo/products');
$response->assertRedirect('/bo/login');
});
it('denies access to unauthorized user with customer role', function () {
$user = User::factory()->make(['role' => UserRole::Customer]);
$this->actingAs($user, 'backend');
$response = $this->get('/bo/products');
expect($response->status())->toBe(403);
});
});
});