75 lines
2.3 KiB
PHP
75 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\App\Http\Requests\Fo\Orders;
|
|
|
|
use App\Cqs\Actions\Orders\PlacePendingOrderInput;
|
|
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 PlacePendingOrderInput', 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->toPlacePendingOrderInput();
|
|
|
|
// THEN
|
|
expect($input)->toBeInstanceOf(PlacePendingOrderInput::class)
|
|
->and($input->shopperId)->toBe($shopperId);
|
|
});
|
|
});
|