2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-09-29 16:59:07 +02:00
|
|
|
use App\Dto\RangeDto;
|
2026-06-14 21:32:07 +02:00
|
|
|
use App\Models\Customer;
|
|
|
|
|
use App\Models\Range;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Policies\Backend\RangePolicy;
|
|
|
|
|
use Domain\Enums\UserRole;
|
|
|
|
|
|
|
|
|
|
describe('RangePolicy', function () {
|
|
|
|
|
test('viewAny returns false for customer', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$customer = new Customer();
|
|
|
|
|
$policy = new RangePolicy();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $policy->viewAny($customer);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('viewAny returns true for admin user', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$user = new User();
|
|
|
|
|
$user->role = UserRole::Admin;
|
|
|
|
|
$policy = new RangePolicy();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $policy->viewAny($user);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('view returns false for customer', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$customer = new Customer();
|
|
|
|
|
$policy = new RangePolicy();
|
|
|
|
|
$modelInstance = new Range();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $policy->view($customer, $modelInstance);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('view returns true for admin user', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$user = new User();
|
|
|
|
|
$user->role = UserRole::Admin;
|
|
|
|
|
$policy = new RangePolicy();
|
|
|
|
|
$modelInstance = new Range();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $policy->view($user, $modelInstance);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('create returns false for customer', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$customer = new Customer();
|
|
|
|
|
$policy = new RangePolicy();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $policy->create($customer);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('create returns true for admin user', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$user = new User();
|
|
|
|
|
$user->role = UserRole::Admin;
|
|
|
|
|
$policy = new RangePolicy();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $policy->create($user);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update returns false for customer', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$customer = new Customer();
|
|
|
|
|
$policy = new RangePolicy();
|
|
|
|
|
$modelInstance = new Range();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $policy->update($customer, $modelInstance);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('update returns true for admin user', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$user = new User();
|
|
|
|
|
$user->role = UserRole::Admin;
|
|
|
|
|
$policy = new RangePolicy();
|
|
|
|
|
$modelInstance = new Range();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $policy->update($user, $modelInstance);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('delete returns false for customer', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$customer = new Customer();
|
|
|
|
|
$policy = new RangePolicy();
|
|
|
|
|
$modelInstance = new Range();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $policy->delete($customer, $modelInstance);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('delete returns true for admin user', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$user = new User();
|
|
|
|
|
$user->role = UserRole::Admin;
|
|
|
|
|
$policy = new RangePolicy();
|
|
|
|
|
$modelInstance = new Range();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $policy->delete($user, $modelInstance);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeTrue();
|
|
|
|
|
});
|
2026-09-29 16:59:07 +02:00
|
|
|
|
|
|
|
|
test('toggleStatus returns false for customer', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$customer = new Customer();
|
|
|
|
|
$policy = new RangePolicy();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $policy->toggleStatus($customer);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('toggleStatus returns true for admin user', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$user = new User();
|
|
|
|
|
$user->role = UserRole::Admin;
|
|
|
|
|
$policy = new RangePolicy();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $policy->toggleStatus($user);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('view, update, delete return true for admin user with RangeDto', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$user = new User();
|
|
|
|
|
$user->role = UserRole::Admin;
|
|
|
|
|
$policy = new RangePolicy();
|
|
|
|
|
$dto = new RangeDto(
|
|
|
|
|
id: 1,
|
|
|
|
|
name: 'Gamme Test',
|
|
|
|
|
slug: 'gamme-test',
|
|
|
|
|
description: null,
|
|
|
|
|
picture: null,
|
|
|
|
|
picture_alt: '',
|
|
|
|
|
picture_title: '',
|
|
|
|
|
order: 1,
|
|
|
|
|
status: true,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect($policy->view($user, $dto))->toBeTrue()
|
|
|
|
|
->and($policy->update($user, $dto))->toBeTrue()
|
|
|
|
|
->and($policy->delete($user, $dto))->toBeTrue();
|
|
|
|
|
});
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|