diff --git a/tests/Feature/App/Http/Controllers/Bo/DiscountsControllerTest.php b/tests/Feature/App/Http/Controllers/Bo/DiscountsControllerTest.php index 6d0c7751..c70666f1 100644 --- a/tests/Feature/App/Http/Controllers/Bo/DiscountsControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Bo/DiscountsControllerTest.php @@ -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); + }); + }); }); diff --git a/tests/Feature/App/Http/Controllers/Bo/ProductsControllerTest.php b/tests/Feature/App/Http/Controllers/Bo/ProductsControllerTest.php index 4ae1761f..5ca31bbd 100644 --- a/tests/Feature/App/Http/Controllers/Bo/ProductsControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Bo/ProductsControllerTest.php @@ -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); + }); + }); });