ldc-cocotte/tests/Feature/App/Http/Requests/Fo/Orders/ConfirmOrderRequestTest.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

73 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
use App\Cqs\Actions\Orders\FinalizeOrderInput;
use App\Http\Requests\Fo\Orders\ConfirmOrderRequest;
use App\Models\Customer;
use Domain\Models\ValueObjects\Entities\ShopperId;
use Infrastructure\Adapters\Services\AppCustomerAuthService;
use Ramsey\Uuid\Uuid;
describe('ConfirmOrderRequest', function () {
it('authorizes when user is logged in', function () {
// GIVEN
$authService = \Mockery::mock(AppCustomerAuthService::class);
$authService->shouldReceive('check')->once()->andReturn(true);
$request = new ConfirmOrderRequest($authService);
// WHEN
$request->initialize();
// THEN
expect($request->authorize())->toBeTrue();
});
it('does not authorize when user is not logged in', function () {
// GIVEN
$authService = \Mockery::mock(AppCustomerAuthService::class);
$authService->shouldReceive('check')->once()->andReturn(false);
$request = new ConfirmOrderRequest($authService);
// WHEN
$request->initialize();
// THEN
expect($request->authorize())->toBeFalse();
});
it('has required rules for cgv acceptance', function () {
// GIVEN
$authService = \Mockery::mock(AppCustomerAuthService::class);
$request = new ConfirmOrderRequest($authService);
// WHEN
$rules = $request->rules();
// THEN
expect($rules)->toHaveKey('ok_cgv')
->and($rules['ok_cgv'])->toContain('accepted');
});
it('maps to FinalizeOrderInput', function () {
// GIVEN
$shopperId = new ShopperId(Uuid::uuid7());
$customer = \Mockery::mock(Customer::class);
$customer->shouldReceive('getId')->once()->andReturn($shopperId);
$authService = \Mockery::mock(AppCustomerAuthService::class);
$authService->shouldReceive('getCustomerAsMandatory')->once()->andReturn($customer);
$request = new ConfirmOrderRequest($authService);
$request->initialize();
// WHEN
$input = $request->toFinalizeOrderInput();
// THEN
expect($input)->toBeInstanceOf(FinalizeOrderInput::class)
->and($input->shopperId)->toBe($shopperId);
});
});