new UpsertShopsPickupExceptionsUsingApiForYear($invalidYear)) ->toThrow(\InvalidArgumentException::class); }); it('upserts holidays from the api and syncs them to all shops', function (): void { // GIVEN $year = 2026; $shops = Shop::factory()->count(2)->create(); Http::fake([ '*' => Http::response([ '2026-01-01' => '1er janvier', '2026-12-25' => 'Jour de Noël', ], 200), ]); // WHEN UpsertShopsPickupExceptionsUsingApiForYear::dispatchSync($year); // THEN expect(PickupException::query()->count())->toBe(2); $newYear = PickupException::query()->where('label', '1er janvier')->first(); Assert::notNull($newYear); expect($newYear)->not->toBeNull() ->and($newYear->date->format('Y-m-d'))->toBe('2026-01-01') ->and($newYear->repeatable)->toBeTrue() ->and($newYear->repeat_frequency)->toBe(RepeatFrequency::YEARLY); $firstShop = $shops->first(); $lastShop = $shops->last(); Assert::notNull($firstShop); Assert::notNull($lastShop); expect($firstShop->pickupExceptions()->count())->toBe(2) ->and($lastShop->pickupExceptions()->count())->toBe(2); }); it('updates existing pickup exceptions without creating duplicates', function (): void { // GIVEN $year = 2026; $shop = Shop::factory()->create(); PickupException::factory()->create([ 'label' => '1er janvier', 'date' => '2026-01-01', 'repeatable' => false, 'repeat_frequency' => 'Weekly', ]); Http::fake([ '*' => Http::response([ '2026-01-01' => '1er janvier', ], 200), ]); // WHEN UpsertShopsPickupExceptionsUsingApiForYear::dispatchSync($year); // THEN expect(PickupException::query()->count())->toBe(1); $updatedException = PickupException::query()->firstOrFail(); expect($updatedException->date->format('Y-m-d'))->toBe('2026-01-01') ->and($updatedException->repeatable)->toBeTrue() ->and($updatedException->repeat_frequency)->toBe(RepeatFrequency::YEARLY); expect($shop->pickupExceptions()->count())->toBe(1); });