ldc-cocotte/tests/Feature/App/Http/Requests/Bo/Dashboard/DashboardRequestTest.php
Jérémy Munsch d0efb0f527
refactor: update namespaces for actions and queries
Refactored the codebase to change the namespaces of various actions and queries from `App\Actions` to `App\Cqs\Actions` and `App\Queries` to `App\Cqs\Queries`. This restructuring improves organization and clarity in the codebase.
2026-11-10 15:13:26 +01:00

86 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Cqs\Queries\Dashboard\GetBoDashboardQueryInput;
use App\Http\Requests\Bo\Dashboard\DashboardRequest;
use Infrastructure\Adapters\Services\AppAdminAuthService;
use function Pest\Laravel\mock;
describe('DashboardRequest', function () {
it('authorizes via auth service', function () {
// GIVEN
$authService = mock(AppAdminAuthService::class);
$authService->shouldReceive('check')->once()->andReturn(true);
$request = new DashboardRequest($authService);
// WHEN
$request->initialize();
// THEN
expect($request->authorize())->toBeTrue();
});
it('returns rules', function () {
// GIVEN
$authService = mock(AppAdminAuthService::class);
$request = new DashboardRequest($authService);
$request->initialize();
// WHEN
$rules = $request->rules();
// THEN
expect($rules)->toHaveKeys(['start', 'end']);
});
it('gets start date', function () {
// GIVEN
$authService = mock(AppAdminAuthService::class);
$request = new DashboardRequest($authService);
$request->initialize();
expect($request->getStart())->toBeNull();
// WHEN
$request->merge(['start' => '2023-01-01']);
// THEN
expect($request->getStart()->format('Y-m-d'))->toBe('2023-01-01');
});
it('gets end date', function () {
// GIVEN
$authService = mock(AppAdminAuthService::class);
$request = new DashboardRequest($authService);
$request->initialize();
expect($request->getEnd())->toBeNull();
// WHEN
$request->merge(['end' => '2023-12-31']);
// THEN
expect($request->getEnd()->format('Y-m-d'))->toBe('2023-12-31');
});
it('maps to GetBoDashboardQueryInput', function () {
// GIVEN
$authService = mock(AppAdminAuthService::class);
$request = new DashboardRequest($authService);
$request->initialize(query: [
'start' => '2026-01-01',
'end' => '2026-01-31',
]);
// WHEN
$input = $request->toGetBoDashboardQueryInput();
// THEN
expect($input)->toBeInstanceOf(GetBoDashboardQueryInput::class)
->and($input->start?->format('Y-m-d'))->toBe('2026-01-01')
->and($input->end?->format('Y-m-d'))->toBe('2026-01-31');
});
});