ldc-cocotte/tests/Integration/WithApp/App/Queries/Discounts/GetPaginatedDiscountsQueryTest.php
Jérémy Munsch 3b3997d547
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees)
- Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue)
- Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts
- Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs
- Remove legacy and dead CSV employee import/export code
- Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation
- Add comprehensive Pest unit, integration, and feature test coverage
2026-10-27 09:58:44 +01:00

61 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Integration\WithApp\App\Queries\Discounts;
use App\Contracts\QueryInput;
use App\Dto\DiscountDto;
use App\Models\Discount;
use App\Queries\Discounts\GetPaginatedDiscountsQuery;
use App\Queries\Discounts\GetPaginatedDiscountsQueryInput;
use App\Services\DataTableService;
use Domain\Enums\DiscountType;
use Domain\Models\ValueObjects\DiscountValue;
describe('GetPaginatedDiscountsQuery', function (): void {
it('returns a paginator of DiscountDto instances', function (): void {
// GIVEN
$discount1 = new Discount();
$discount1->type = DiscountType::PERCENT;
$discount1->value = DiscountValue::fromPercentage(10);
$discount1->is_old_price_displayed = true;
$discount1->save();
$discount2 = new Discount();
$discount2->type = DiscountType::PERCENT;
$discount2->value = DiscountValue::fromPercentage(20);
$discount2->is_old_price_displayed = false;
$discount2->save();
$query = new GetPaginatedDiscountsQuery(app(DataTableService::class));
$input = new GetPaginatedDiscountsQueryInput(
pagination: Pagination::ofPage(1, 10),
);
// WHEN
$paginator = $query($input);
// THEN
expect($paginator->total())->toBe(2)
->and($paginator->items())->toHaveCount(2)
->and($paginator->items()[0])->toBeInstanceOf(DiscountDto::class)
->and($paginator->items()[1])->toBeInstanceOf(DiscountDto::class);
});
it('throws when an invalid input is passed', function (): void {
// GIVEN
$query = new GetPaginatedDiscountsQuery(app(DataTableService::class));
$invalidInput = new class () implements QueryInput
{
};
// WHEN
expect(
/** @phpstan-ignore argument.type */
fn () => $query($invalidInput)
)
// THEN
->toThrow(\InvalidArgumentException::class);
});
});