test(bo): add negative authorization tests for unauthenticated and unauthorized requests [AUD-TST-003]
This commit is contained in:
parent
4ce5488bae
commit
30077e68ad
2 changed files with 35 additions and 1 deletions
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue