ldc-cocotte/tests/Feature/App/Http/Requests/Fo/Orders/ConfirmOrderRequestTest.php

67 lines
2.2 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Tests\Feature\App\Http\Requests\Fo\Orders;
use App\Http\Requests\Fo\Orders\ConfirmOrderRequest;
use App\Models\Customer;
use Domain\Models\ValueObjects\Entities\ShopperId;
use Illuminate\Support\Facades\Validator;
use Infrastructure\Adapters\Services\AppCustomerAuthService;
use Shared\Helpers\UuidHelper;
describe('ConfirmOrderRequest', function (): void {
it('authorizes only when customer auth service returns true', function (): void {
// GIVEN
$authService = \Mockery::mock(AppCustomerAuthService::class);
$authService->shouldReceive('check')->twice()->andReturn(true, false);
$request = new ConfirmOrderRequest($authService);
$request->initialize();
// WHEN
$authorized = $request->authorize();
$denied = $request->authorize();
// THEN
expect($authorized)->toBeTrue()
->and($denied)->toBeFalse();
});
it('requires cgv acceptance in validation rules', function (): void {
// GIVEN
$authService = \Mockery::mock(AppCustomerAuthService::class);
$rules = new ConfirmOrderRequest($authService)->rules();
// WHEN
$missing = Validator::make([], $rules);
$rejected = Validator::make(['ok_cgv' => false], $rules);
$accepted = Validator::make(['ok_cgv' => true], $rules);
// THEN
expect($missing->errors()->has('ok_cgv'))->toBeTrue()
->and($rejected->errors()->has('ok_cgv'))->toBeTrue()
->and($accepted->passes())->toBeTrue();
});
it('maps to PlacePendingOrderInput', function (): void {
// GIVEN
$shopperId = new ShopperId(UuidHelper::v7());
$customer = new Customer();
$customer->id = $shopperId->value->toString();
$authService = \Mockery::mock(AppCustomerAuthService::class);
$authService->shouldReceive('getCustomerAsMandatory')->once()->andReturn($customer);
$request = new ConfirmOrderRequest($authService);
$request->initialize();
// WHEN
$input = $request->toPlacePendingOrderInput();
// THEN
expect($input->shopperId?->value->toString())->toBe($shopperId->value->toString());
});
});