diff --git a/app/Cqs/Actions/PickupExceptions/UpsertShopsPickupExceptionsForYear.php b/app/Cqs/Actions/PickupExceptions/UpsertShopsPickupExceptionsForYear.php new file mode 100644 index 00000000..4984ba37 --- /dev/null +++ b/app/Cqs/Actions/PickupExceptions/UpsertShopsPickupExceptionsForYear.php @@ -0,0 +1,62 @@ + + */ +final class UpsertShopsPickupExceptionsForYear implements Action +{ + /** + * @param \App\Cqs\Actions\PickupExceptions\UpsertShopsPickupExceptionsForYearInput $input + */ + #[\Override] + public function __invoke(ActionInput $input): void + { + Assert::isInstanceOf($input, UpsertShopsPickupExceptionsForYearInput::class); + + if ($input->holidays === []) { + return; + } + + foreach ($input->holidays as $holiday) { + $exception = PickupException::query() + ->firstOrNew([ + 'date' => $holiday->date->format('Y-m-d'), + 'label' => $holiday->label, + ]); + $exception->fill([ + 'date' => $holiday->date->format('Y-m-d'), + 'repeatable' => true, + 'repeat_frequency' => RepeatFrequency::YEARLY, + ]); + $exception->setAttribute('auto_updated', true); + $exception->saveOrFail(); + } + + $repeatables = PickupException::query() + ->whereYear('date', $input->year) + ->whereIn('label', array_map( + fn (PublicHolidayDto $holiday): string => $holiday->label, + $input->holidays + )) + ->get(); + + Shop::query()->get() + ->each(fn (Shop $shop) => $shop->pickupExceptions() + ->syncWithoutDetaching($repeatables)); + } +} diff --git a/app/Cqs/Actions/PickupExceptions/UpsertShopsPickupExceptionsForYearInput.php b/app/Cqs/Actions/PickupExceptions/UpsertShopsPickupExceptionsForYearInput.php new file mode 100644 index 00000000..ee1f0f19 --- /dev/null +++ b/app/Cqs/Actions/PickupExceptions/UpsertShopsPickupExceptionsForYearInput.php @@ -0,0 +1,23 @@ + $holidays + */ + public function __construct( + public int $year, + public array $holidays, + ) { + Assert::greaterThanEq($this->year, 2026); + Assert::allIsInstanceOf($this->holidays, PublicHolidayDto::class); + } +} diff --git a/app/Cqs/Actions/PickupExceptions/UpsertShopsPickupExceptionsUsingApiForYear.php b/app/Cqs/Actions/PickupExceptions/UpsertShopsPickupExceptionsUsingApiForYear.php deleted file mode 100644 index 9c65481e..00000000 --- a/app/Cqs/Actions/PickupExceptions/UpsertShopsPickupExceptionsUsingApiForYear.php +++ /dev/null @@ -1,130 +0,0 @@ - - */ -final class UpsertShopsPickupExceptionsUsingApiForYear implements Action -{ - private const string CALENDAR_API_URL = 'https://calendrier.api.gouv.fr/jours-feries/metropole/:year.json'; - - private const int API_CALL_TIMEOUT = 120; - - /** - * @param \App\Cqs\Actions\PickupExceptions\UpsertShopsPickupExceptionsUsingApiForYearInput $input - */ - #[\Override] - public function __invoke(ActionInput $input): void - { - Assert::isInstanceOf($input, UpsertShopsPickupExceptionsUsingApiForYearInput::class); - - if ( - $input->onlyIfMissing - && PickupException::query() - ->whereYear('date', $input->year) - ->where('auto_updated', true) - ->exists() - ) { - return; - } - - $holidayList = $this->getHolidaysForYear($input->year); - - foreach ($holidayList as $holiday) { - $exception = PickupException::query() - ->firstOrNew([ - 'date' => $holiday->date->format('Y-m-d'), - 'label' => $holiday->label, - ]); - $exception->fill([ - 'date' => $holiday->date->format('Y-m-d'), - 'repeatable' => true, - 'repeat_frequency' => RepeatFrequency::YEARLY, - ]); - $exception->setAttribute('auto_updated', true); - $exception->saveOrFail(); - } - - $repeatablesFromApi = PickupException::query() - ->whereYear('date', $input->year) - ->whereIn('label', array_map( - fn ($v) => $v->label, - $holidayList - )) - ->get(); - - Shop::query()->get() - ->each(fn ($shop) => $shop->pickupExceptions() - ->syncWithoutDetaching($repeatablesFromApi)); - } - - /** @return object{date:\DateTimeInterface,label:string}[] */ - private function getHolidaysForYear(int $year): array - { - $url = $this->getCalendarApiUrlFor($year); - - $response = Http::timeout(self::API_CALL_TIMEOUT)->get($url); - throw_unless( - $response->successful(), - \UnexpectedValueException::class, - 'Failed to fetch calendar from api' - ); - - $outputList = $response - ->collect() - ->map(fn ($label, $date) => [ - 'date' => $date, - 'label' => $label, - ])->all(); - - $rules = [ - '*' => 'array', - '*.date' => ['required', 'date'], - '*.label' => ['required', 'string'], - ]; - - $validator = Validator::make($outputList, $rules); - - if ($validator->fails()) { - $errors = $validator->errors(); - throw new \UnexpectedValueException( - 'Invalid response: ' . - json_encode($errors->messages()) - ); - } - - return array_map(fn (array $entry) => (object) [ - 'date' => Date::parse( - $entry['date'], - new \DateTimeZone('Europe/Paris') - ), - 'label' => Arr::string($entry, 'label'), - ], $outputList); - } - - private function getCalendarApiUrlFor(int $year): string - { - return str_replace( - ':year', - strval($year), - self::CALENDAR_API_URL - ); - } -} diff --git a/app/Cqs/Actions/PickupExceptions/UpsertShopsPickupExceptionsUsingApiForYearInput.php b/app/Cqs/Actions/PickupExceptions/UpsertShopsPickupExceptionsUsingApiForYearInput.php deleted file mode 100644 index c818c1b8..00000000 --- a/app/Cqs/Actions/PickupExceptions/UpsertShopsPickupExceptionsUsingApiForYearInput.php +++ /dev/null @@ -1,18 +0,0 @@ -year, 2026); - } -} diff --git a/app/Cqs/Queries/PickupExceptions/HasAutoUpdatedPickupExceptionsForYearQuery.php b/app/Cqs/Queries/PickupExceptions/HasAutoUpdatedPickupExceptionsForYearQuery.php new file mode 100644 index 00000000..bac8ae0e --- /dev/null +++ b/app/Cqs/Queries/PickupExceptions/HasAutoUpdatedPickupExceptionsForYearQuery.php @@ -0,0 +1,33 @@ + + */ +final readonly class HasAutoUpdatedPickupExceptionsForYearQuery implements Query +{ + /** + * @param \App\Cqs\Queries\PickupExceptions\HasAutoUpdatedPickupExceptionsForYearQueryInput $input + */ + #[\Override] + public function __invoke(QueryInput $input): bool + { + Assert::isInstanceOf($input, HasAutoUpdatedPickupExceptionsForYearQueryInput::class); + + return PickupException::query() + ->whereYear('date', $input->year) + ->where('auto_updated', true) + ->exists(); + } +} diff --git a/app/Cqs/Queries/PickupExceptions/HasAutoUpdatedPickupExceptionsForYearQueryInput.php b/app/Cqs/Queries/PickupExceptions/HasAutoUpdatedPickupExceptionsForYearQueryInput.php new file mode 100644 index 00000000..4d97c6ba --- /dev/null +++ b/app/Cqs/Queries/PickupExceptions/HasAutoUpdatedPickupExceptionsForYearQueryInput.php @@ -0,0 +1,17 @@ +year, 2026); + } +} diff --git a/app/Dto/PublicHolidayDto.php b/app/Dto/PublicHolidayDto.php new file mode 100644 index 00000000..bfce6b21 --- /dev/null +++ b/app/Dto/PublicHolidayDto.php @@ -0,0 +1,16 @@ + + */ + public array $backoff = [10, 30]; + public function handle( Executor $executor, - UpsertShopsPickupExceptionsAction $action, + HasAutoUpdatedPickupExceptionsForYearQuery $hasHolidaysQuery, + PublicHolidaysApiService $apiService, + UpsertShopsPickupExceptionsForYear $action, ): void { $now = Date::now(); if ($now->year >= 2026) { - $executor->execute( + $this->syncYearIfMissing( + $now->year, + $executor, + $hasHolidaysQuery, + $apiService, $action, - new UpsertShopsPickupExceptionsUsingApiForYearInput($now->year, onlyIfMissing: true), ); } if ($now->month >= 11) { - $executor->execute( + $this->syncYearIfMissing( + $now->year + 1, + $executor, + $hasHolidaysQuery, + $apiService, $action, - new UpsertShopsPickupExceptionsUsingApiForYearInput($now->year + 1, onlyIfMissing: true), ); } } + + private function syncYearIfMissing( + int $year, + Executor $executor, + HasAutoUpdatedPickupExceptionsForYearQuery $hasHolidaysQuery, + PublicHolidaysApiService $apiService, + UpsertShopsPickupExceptionsForYear $action, + ): void { + $alreadySynced = $executor->execute( + $hasHolidaysQuery, + new HasAutoUpdatedPickupExceptionsForYearQueryInput($year), + ); + + if ($alreadySynced) { + return; + } + + $holidays = $apiService->fetchForYear($year); + + $executor->execute( + $action, + new UpsertShopsPickupExceptionsForYearInput($year, $holidays), + ); + } } diff --git a/app/Jobs/UpsertShopsPickupExceptionsUsingApiForYear.php b/app/Jobs/UpsertShopsPickupExceptionsUsingApiForYear.php index 6d221d5d..f555911e 100644 --- a/app/Jobs/UpsertShopsPickupExceptionsUsingApiForYear.php +++ b/app/Jobs/UpsertShopsPickupExceptionsUsingApiForYear.php @@ -5,8 +5,9 @@ declare(strict_types=1); namespace App\Jobs; use App\Contracts\Executor; -use App\Cqs\Actions\PickupExceptions\UpsertShopsPickupExceptionsUsingApiForYear as UpsertShopsPickupExceptionsAction; -use App\Cqs\Actions\PickupExceptions\UpsertShopsPickupExceptionsUsingApiForYearInput; +use App\Cqs\Actions\PickupExceptions\UpsertShopsPickupExceptionsForYear; +use App\Cqs\Actions\PickupExceptions\UpsertShopsPickupExceptionsForYearInput; +use App\Services\PublicHolidaysApiService; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Queue\Queueable; use Illuminate\Support\Facades\Date; @@ -15,6 +16,13 @@ class UpsertShopsPickupExceptionsUsingApiForYear implements ShouldQueue { use Queueable; + public int $tries = 3; + + /** + * @var list + */ + public array $backoff = [10, 30]; + protected int $year; public function __construct(?int $year = null) @@ -29,11 +37,14 @@ class UpsertShopsPickupExceptionsUsingApiForYear implements ShouldQueue public function handle( Executor $executor, - UpsertShopsPickupExceptionsAction $action, + PublicHolidaysApiService $apiService, + UpsertShopsPickupExceptionsForYear $action, ): void { + $holidays = $apiService->fetchForYear($this->year); + $executor->execute( $action, - new UpsertShopsPickupExceptionsUsingApiForYearInput($this->year), + new UpsertShopsPickupExceptionsForYearInput($this->year, $holidays), ); } } diff --git a/app/Services/PublicHolidaysApiService.php b/app/Services/PublicHolidaysApiService.php new file mode 100644 index 00000000..c39a2255 --- /dev/null +++ b/app/Services/PublicHolidaysApiService.php @@ -0,0 +1,65 @@ + + */ + public function fetchForYear(int $year): array + { + Assert::greaterThanEq($year, 2026); + + $url = str_replace(':year', strval($year), self::CALENDAR_API_URL); + $response = Http::timeout(self::API_CALL_TIMEOUT_SECONDS)->get($url); + + throw_unless( + $response->successful(), + \UnexpectedValueException::class, + 'Failed to fetch calendar from api' + ); + + $outputList = $response + ->collect() + ->map(fn ($label, $date): array => [ + 'date' => $date, + 'label' => $label, + ])->values()->all(); + + $validator = Validator::make($outputList, [ + '*' => 'array', + '*.date' => ['required', 'date'], + '*.label' => ['required', 'string'], + ]); + + if ($validator->fails()) { + throw new \UnexpectedValueException( + 'Invalid response: ' . json_encode($validator->errors()->messages()) + ); + } + + $timezone = new \DateTimeZone('Europe/Paris'); + + return array_values(array_map( + fn (array $entry): PublicHolidayDto => new PublicHolidayDto( + date: CarbonImmutable::parse(Arr::string($entry, 'date'), $timezone), + label: Arr::string($entry, 'label'), + ), + $outputList + )); + } +} diff --git a/tests/Integration/WithApp/App/Actions/PickupExceptions/UpsertShopsPickupExceptionsForYearTest.php b/tests/Integration/WithApp/App/Actions/PickupExceptions/UpsertShopsPickupExceptionsForYearTest.php new file mode 100644 index 00000000..5a1922f3 --- /dev/null +++ b/tests/Integration/WithApp/App/Actions/PickupExceptions/UpsertShopsPickupExceptionsForYearTest.php @@ -0,0 +1,102 @@ +count(2)->create(); + $holidays = [ + new PublicHolidayDto(CarbonImmutable::parse('2026-01-01', 'Europe/Paris'), '1er janvier'), + new PublicHolidayDto(CarbonImmutable::parse('2026-12-25', 'Europe/Paris'), 'Jour de Noël'), + ]; + + $action = new UpsertShopsPickupExceptionsForYear(); + $input = new UpsertShopsPickupExceptionsForYearInput(2026, $holidays); + + // WHEN + $action($input); + + // THEN + expect(PickupException::query()->count())->toBe(2); + $newYear = PickupException::query()->where('label', '1er janvier')->first(); + 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) + ->and($newYear?->auto_updated)->toBeTrue() + ->and($shops->first()?->pickupExceptions()->count())->toBe(2) + ->and($shops->last()?->pickupExceptions()->count())->toBe(2); + }); + + it('does not overwrite previous year holidays when importing a new year and preserves shop associations', function (): void { + // GIVEN + $shop = Shop::factory()->create(); + + $armistice2026 = PickupException::factory()->create([ + 'date' => '2026-11-11', + 'label' => 'Armistice', + 'repeatable' => true, + 'repeat_frequency' => RepeatFrequency::YEARLY, + 'auto_updated' => true, + ]); + $christmas2026 = PickupException::factory()->create([ + 'date' => '2026-12-25', + 'label' => 'Jour de Noël', + 'repeatable' => true, + 'repeat_frequency' => RepeatFrequency::YEARLY, + 'auto_updated' => true, + ]); + $shop->pickupExceptions()->attach([$armistice2026->id, $christmas2026->id]); + + $holidays = [ + new PublicHolidayDto(CarbonImmutable::parse('2027-11-11', 'Europe/Paris'), 'Armistice'), + new PublicHolidayDto(CarbonImmutable::parse('2027-12-25', 'Europe/Paris'), 'Jour de Noël'), + ]; + + $action = new UpsertShopsPickupExceptionsForYear(); + $input = new UpsertShopsPickupExceptionsForYearInput(2027, $holidays); + + // WHEN + $action($input); + + // THEN + expect(PickupException::query()->count())->toBe(4) + ->and(PickupException::query()->whereYear('date', 2026)->count())->toBe(2) + ->and(PickupException::query()->whereYear('date', 2027)->count())->toBe(2) + ->and($armistice2026->fresh()?->date?->format('Y-m-d'))->toBe('2026-11-11') + ->and($christmas2026->fresh()?->date?->format('Y-m-d'))->toBe('2026-12-25') + ->and($shop->pickupExceptions()->count())->toBe(4); + }); + + it('rejects years before 2026 in input', function (): void { + // GIVEN / WHEN / THEN + expect(fn () => new UpsertShopsPickupExceptionsForYearInput(2025, [])) + ->toThrow(\InvalidArgumentException::class); + }); + + it('throws when an invalid input is passed', function (): void { + // GIVEN + $action = new UpsertShopsPickupExceptionsForYear(); + $invalidInput = new class () implements ActionInput + { + }; + + // WHEN + expect( + /** @phpstan-ignore argument.type */ + fn () => $action($invalidInput) + ) + // THEN + ->toThrow(\InvalidArgumentException::class); + }); +}); diff --git a/tests/Integration/WithApp/App/Actions/PickupExceptions/UpsertShopsPickupExceptionsUsingApiForYearTest.php b/tests/Integration/WithApp/App/Actions/PickupExceptions/UpsertShopsPickupExceptionsUsingApiForYearTest.php deleted file mode 100644 index 08a0c707..00000000 --- a/tests/Integration/WithApp/App/Actions/PickupExceptions/UpsertShopsPickupExceptionsUsingApiForYearTest.php +++ /dev/null @@ -1,154 +0,0 @@ -count(2)->create(); - Http::fake([ - '*' => Http::response([ - '2026-01-01' => '1er janvier', - '2026-12-25' => 'Jour de Noël', - ], 200), - ]); - - $action = new UpsertShopsPickupExceptionsUsingApiForYear(); - $input = new UpsertShopsPickupExceptionsUsingApiForYearInput(2026); - - // WHEN - $action($input); - - // THEN - expect(PickupException::query()->count())->toBe(2); - $newYear = PickupException::query()->where('label', '1er janvier')->first(); - 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) - ->and($shops->first()?->pickupExceptions()->count())->toBe(2) - ->and($shops->last()?->pickupExceptions()->count())->toBe(2); - }); - - it('does not overwrite previous year holidays when importing a new year and preserves shop associations', function (): void { - // GIVEN - $shop = Shop::factory()->create(); - - $armistice2026 = PickupException::factory()->create([ - 'date' => '2026-11-11', - 'label' => 'Armistice', - 'repeatable' => true, - 'repeat_frequency' => RepeatFrequency::YEARLY, - 'auto_updated' => true, - ]); - $christmas2026 = PickupException::factory()->create([ - 'date' => '2026-12-25', - 'label' => 'Jour de Noël', - 'repeatable' => true, - 'repeat_frequency' => RepeatFrequency::YEARLY, - 'auto_updated' => true, - ]); - $shop->pickupExceptions()->attach([$armistice2026->id, $christmas2026->id]); - - Http::fake([ - 'https://calendrier.api.gouv.fr/jours-feries/metropole/2027.json' => Http::response([ - '2027-11-11' => 'Armistice', - '2027-12-25' => 'Jour de Noël', - ], 200), - ]); - - $action = new UpsertShopsPickupExceptionsUsingApiForYear(); - $input = new UpsertShopsPickupExceptionsUsingApiForYearInput(2027); - - // WHEN - $action($input); - - // THEN - expect(PickupException::query()->count())->toBe(4) - ->and(PickupException::query()->whereYear('date', 2026)->count())->toBe(2) - ->and(PickupException::query()->whereYear('date', 2027)->count())->toBe(2) - ->and($armistice2026->fresh()?->date?->format('Y-m-d'))->toBe('2026-11-11') - ->and($christmas2026->fresh()?->date?->format('Y-m-d'))->toBe('2026-12-25') - ->and($shop->pickupExceptions()->count())->toBe(4); - }); - - it('skips the api call when onlyIfMissing is true and auto-updated holidays exist for the year', function (): void { - // GIVEN - PickupException::factory()->create([ - 'date' => '2026-01-01', - 'label' => '1er janvier', - 'repeatable' => true, - 'repeat_frequency' => RepeatFrequency::YEARLY, - 'auto_updated' => true, - ]); - - Http::fake(); - - $action = new UpsertShopsPickupExceptionsUsingApiForYear(); - $input = new UpsertShopsPickupExceptionsUsingApiForYearInput(2026, onlyIfMissing: true); - - // WHEN - $action($input); - - // THEN - Http::assertNothingSent(); - expect(PickupException::query()->count())->toBe(1); - }); - - it('calls the api when onlyIfMissing is true and no auto-updated holidays exist for the year', function (): void { - // GIVEN - PickupException::factory()->create([ - 'date' => '2026-05-01', - 'label' => 'Manual exception', - 'repeatable' => false, - 'repeat_frequency' => RepeatFrequency::YEARLY, - 'auto_updated' => false, - ]); - - Http::fake([ - 'https://calendrier.api.gouv.fr/jours-feries/metropole/2026.json' => Http::response([ - '2026-01-01' => '1er janvier', - ], 200), - ]); - - $action = new UpsertShopsPickupExceptionsUsingApiForYear(); - $input = new UpsertShopsPickupExceptionsUsingApiForYearInput(2026, onlyIfMissing: true); - - // WHEN - $action($input); - - // THEN - Http::assertSentCount(1); - expect(PickupException::query()->whereYear('date', 2026)->where('auto_updated', true)->count())->toBe(1); - }); - - it('rejects years before 2026 in input', function (): void { - // GIVEN / WHEN / THEN - expect(fn () => new UpsertShopsPickupExceptionsUsingApiForYearInput(2025)) - ->toThrow(\InvalidArgumentException::class); - }); - - it('throws when an invalid input is passed', function (): void { - // GIVEN - $action = new UpsertShopsPickupExceptionsUsingApiForYear(); - $invalidInput = new class () implements ActionInput - { - }; - - // WHEN - expect( - /** @phpstan-ignore argument.type */ - fn () => $action($invalidInput) - ) - // THEN - ->toThrow(\InvalidArgumentException::class); - }); -}); diff --git a/tests/Integration/WithApp/App/Queries/PickupExceptions/HasAutoUpdatedPickupExceptionsForYearQueryTest.php b/tests/Integration/WithApp/App/Queries/PickupExceptions/HasAutoUpdatedPickupExceptionsForYearQueryTest.php new file mode 100644 index 00000000..72568e13 --- /dev/null +++ b/tests/Integration/WithApp/App/Queries/PickupExceptions/HasAutoUpdatedPickupExceptionsForYearQueryTest.php @@ -0,0 +1,40 @@ +create([ + 'date' => '2026-05-01', + 'label' => 'Manual exception', + 'repeatable' => false, + 'repeat_frequency' => RepeatFrequency::YEARLY, + 'auto_updated' => false, + ]); + + $query = new HasAutoUpdatedPickupExceptionsForYearQuery(); + + // WHEN + $beforeAuto = $query(new HasAutoUpdatedPickupExceptionsForYearQueryInput(2026)); + + PickupException::factory()->create([ + 'date' => '2026-01-01', + 'label' => '1er janvier', + 'repeatable' => true, + 'repeat_frequency' => RepeatFrequency::YEARLY, + 'auto_updated' => true, + ]); + + $afterAuto = $query(new HasAutoUpdatedPickupExceptionsForYearQueryInput(2026)); + + // THEN + expect($beforeAuto)->toBeFalse() + ->and($afterAuto)->toBeTrue(); + }); +}); diff --git a/tests/Integration/WithApp/App/Services/PublicHolidaysApiServiceTest.php b/tests/Integration/WithApp/App/Services/PublicHolidaysApiServiceTest.php new file mode 100644 index 00000000..9c7119d9 --- /dev/null +++ b/tests/Integration/WithApp/App/Services/PublicHolidaysApiServiceTest.php @@ -0,0 +1,59 @@ + Http::response([ + '2026-01-01' => '1er janvier', + '2026-12-25' => 'Jour de Noël', + ], 200), + ]); + + $service = new PublicHolidaysApiService(); + + // WHEN + $holidays = $service->fetchForYear(2026); + + // THEN + expect($holidays)->toHaveCount(2) + ->and($holidays[0])->toBeInstanceOf(PublicHolidayDto::class) + ->and($holidays[0]->date)->toBeInstanceOf(CarbonImmutable::class) + ->and($holidays[0]->date->format('Y-m-d'))->toBe('2026-01-01') + ->and($holidays[0]->label)->toBe('1er janvier') + ->and($holidays[1]->date->format('Y-m-d'))->toBe('2026-12-25') + ->and($holidays[1]->label)->toBe('Jour de Noël'); + + Http::assertSent(fn (Request $request): bool => $request->url() === 'https://calendrier.api.gouv.fr/jours-feries/metropole/2026.json'); + }); + + it('throws when the API returns a non-successful status', function (): void { + // GIVEN + Http::fake([ + '*' => Http::response([], 503), + ]); + + $service = new PublicHolidaysApiService(); + + // WHEN / THEN + expect(fn () => $service->fetchForYear(2026)) + ->toThrow(\UnexpectedValueException::class, 'Failed to fetch calendar from api'); + }); + + it('throws when year is before 2026', function (): void { + // GIVEN + $service = new PublicHolidaysApiService(); + + // WHEN / THEN + expect(fn () => $service->fetchForYear(2025)) + ->toThrow(\InvalidArgumentException::class); + }); +});