86 lines
3.1 KiB
PHP
86 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Integration\WithApp\App\Cqs\Queries\Orders;
|
|
|
|
use App\Cqs\Queries\Orders\GetBoTodayOrdersQuery;
|
|
use App\Cqs\Queries\Orders\GetBoTodayOrdersQueryInput;
|
|
use App\Models\Order;
|
|
use App\Models\Shop;
|
|
use App\Services\DataTableService;
|
|
use Carbon\CarbonImmutable;
|
|
use Domain\Enums\OrderStatus;
|
|
use Domain\Models\ValueObjects\DeliveryAddress;
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
use Domain\Models\ValueObjects\OrderEmployee;
|
|
use Domain\Models\ValueObjects\OrderReference;
|
|
use Domain\Models\ValueObjects\ShopperEstablishmentCode;
|
|
use Domain\Models\ValueObjects\ShopperServiceCode;
|
|
use Domain\Models\ValueObjects\ShopperSiteCode;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Date;
|
|
use Money\Money;
|
|
use Shared\Helpers\UuidHelper;
|
|
use Shared\Pagination\PageNumber;
|
|
use Shared\Pagination\PageSize;
|
|
use Shared\Pagination\Pagination;
|
|
|
|
describe('GetBoTodayOrdersQuery', function (): void {
|
|
afterEach(function (): void {
|
|
Date::setTestNow();
|
|
CarbonImmutable::setTestNow();
|
|
});
|
|
|
|
it('returns today business orders and excludes PENDING and FAILED orders', function (): void {
|
|
// GIVEN
|
|
$now = CarbonImmutable::parse('2026-11-16 12:00:00', 'UTC');
|
|
Date::setTestNow($now);
|
|
CarbonImmutable::setTestNow($now);
|
|
|
|
$shop = Shop::factory()->create();
|
|
|
|
$createOrder = static function (OrderStatus $status) use ($shop): Order {
|
|
$order = new Order();
|
|
$order->reference = new OrderReference(UuidHelper::v7());
|
|
$order->total = Money::EUR(2000);
|
|
$order->status = $status;
|
|
$order->pickup_day = Date::now()->addDays(4);
|
|
$order->shop_id = $shop->id;
|
|
$order->delivery_address = new DeliveryAddress('Shop', '1 rue Test', '72300', 'Sablé');
|
|
$order->employee = new OrderEmployee(
|
|
matricule: new Matricule('1234567'),
|
|
firstname: 'Jean',
|
|
lastname: 'Dupont',
|
|
facility: new ShopperEstablishmentCode('FAC01'),
|
|
site: new ShopperSiteCode('SITE'),
|
|
service: new ShopperServiceCode('101'),
|
|
);
|
|
$order->save();
|
|
|
|
return $order;
|
|
};
|
|
|
|
$validated = $createOrder(OrderStatus::VALIDATED);
|
|
$waiting = $createOrder(OrderStatus::WAITING);
|
|
$canceled = $createOrder(OrderStatus::CANCELED);
|
|
$createOrder(OrderStatus::PENDING);
|
|
$createOrder(OrderStatus::FAILED);
|
|
|
|
$request = new Request();
|
|
$session = app('session.store');
|
|
$query = new GetBoTodayOrdersQuery(
|
|
new DataTableService($request, $session, static fn (): array => ['id', 'reference', 'status']),
|
|
);
|
|
|
|
// WHEN
|
|
$result = $query(new GetBoTodayOrdersQueryInput(
|
|
Pagination::ofPage(new PageNumber(1), new PageSize(20)),
|
|
));
|
|
|
|
// THEN
|
|
$ids = array_map(static fn ($dto): string => $dto->id, $result->items());
|
|
expect($result->total())->toBe(3)
|
|
->and($ids)->toContain($validated->id, $waiting->id, $canceled->id);
|
|
});
|
|
});
|