- Updated DataTableService to accept a Pagination object for pagination parameters. - Refactored paginateQuery method to utilize pageSize and pageNumber from Pagination. refactor: replace ActionExecutor with Executor in controller traits - Updated ChangesModelOrder, TogglesModelStar, and TogglesModelStatus traits to use Executor interface instead of ActionExecutor. feat: add PictureMetadata and Slug value objects - Introduced PictureMetadata for managing image metadata with validation. - Added Slug value object for slug generation and validation. feat: update breadcrumbs to support RangeDto - Modified breadcrumbs-bo.php to accept RangeDto in the edit route. test: add tests for RangesController - Added tests for accessing, creating, updating, and deleting ranges. - Included tests for toggling range status. test: add integration tests for range actions - Created tests for CreateRange, DeleteRange, and UpdateRange actions. - Validated input handling and database interactions. test: add unit tests for range input classes - Implemented tests for CreateRangeInput and UpdateRangeInput to validate input constraints. test: add unit tests for value objects - Added tests for PictureMetadata and Slug to ensure proper validation and instantiation. test: add unit tests for RangeDto - Created tests to verify RangeDto mapping from Range model. test: add unit tests for RangePolicy - Implemented tests for RangePolicy to validate permissions based on user roles.
191 lines
4.8 KiB
PHP
191 lines
4.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Dto\RangeDto;
|
|
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();
|
|
});
|
|
|
|
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();
|
|
});
|
|
});
|