ldc-cocotte/tests/Unit/App/Actions/Orders/CancelOrderTest.php
Jérémy Munsch 3ff21bdd49
feat(orders): implement CancelOrder action with output handling
Added CancelOrder action to handle order cancellations with appropriate output responses.
2026-11-15 20:12:16 +01:00

54 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Cqs\Actions\Orders\CancelOrder;
use App\Cqs\Actions\Orders\CancelOrderInput;
use App\Cqs\Actions\Orders\CancelOrderOutput;
use App\Models\Order;
use Domain\Models\ValueObjects\Entities\OrderId;
use Domain\Services\OrderService;
use Ramsey\Uuid\Uuid;
describe('CancelOrder', function (): void {
it('cancels the order and returns CANCELLED when OrderService succeeds', function (): void {
// GIVEN
$orderId = new OrderId(Uuid::uuid7());
$order = new Order();
$order->id = $orderId->value->toString();
$orderService = \Mockery::mock(OrderService::class);
$orderService->shouldReceive('cancelOrder')
->once()
->with(\Mockery::on(fn (OrderId $id) => $id->equals($orderId)));
$action = new CancelOrder($orderService);
// WHEN
$output = $action(new CancelOrderInput($order));
// THEN
expect($output)->toBe(CancelOrderOutput::CANCELLED);
});
it('returns NOT_FOUND when OrderService throws DomainException', function (): void {
// GIVEN
$orderId = new OrderId(Uuid::uuid7());
$order = new Order();
$order->id = $orderId->value->toString();
$orderService = \Mockery::mock(OrderService::class);
$orderService->shouldReceive('cancelOrder')
->once()
->with(\Mockery::on(fn (OrderId $id) => $id->equals($orderId)))
->andThrow(new \DomainException('Order not found'));
$action = new CancelOrder($orderService);
// WHEN
$output = $action(new CancelOrderInput($order));
// THEN
expect($output)->toBe(CancelOrderOutput::NOT_FOUND);
});
});