2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-16 14:26:35 +01:00
|
|
|
namespace Tests\Feature\App\Http\Requests\Basket;
|
|
|
|
|
|
2026-06-14 21:32:07 +02:00
|
|
|
use App\Http\Requests\Basket\RemoveBasketRequest;
|
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
2026-11-17 12:15:39 +01:00
|
|
|
use Shared\Helpers\UuidHelper;
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
describe('RemoveBasketRequest', function () {
|
|
|
|
|
it('authorizes always', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$request = new RemoveBasketRequest();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$request->initialize();
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($request->authorize())->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('validates correct rules', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$request = new RemoveBasketRequest();
|
|
|
|
|
$request->initialize();
|
|
|
|
|
$request->merge([
|
2026-11-17 12:15:39 +01:00
|
|
|
'rowId' => UuidHelper::v7()->toString(),
|
2026-06-14 21:32:07 +02:00
|
|
|
'qty' => 1,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$validator = Validator::make($request->all(), $request->rules());
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($validator->passes())->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails validation on incorrect rules', function () {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$request = new RemoveBasketRequest();
|
|
|
|
|
$request->initialize();
|
|
|
|
|
$request->merge([
|
|
|
|
|
'rowId' => 'not-a-uuid',
|
|
|
|
|
'qty' => 0,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$validator = Validator::make($request->all(), $request->rules());
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($validator->passes())->toBeFalse()
|
|
|
|
|
->and($validator->errors()->keys())->toContain('rowId', 'qty');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can get product id as value object', function () {
|
|
|
|
|
// GIVEN
|
2026-11-17 12:15:39 +01:00
|
|
|
$uuid = UuidHelper::v7()->toString();
|
2026-06-14 21:32:07 +02:00
|
|
|
$request = new RemoveBasketRequest();
|
|
|
|
|
$request->initialize();
|
|
|
|
|
$request->merge(['rowId' => $uuid]);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$productId = $request->getProductId();
|
|
|
|
|
|
|
|
|
|
// THEN
|
2026-11-16 15:23:40 +01:00
|
|
|
expect($productId->value->toString())->toBe($uuid);
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|
|
|
|
|
});
|