78 lines
2.3 KiB
PHP
78 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Jobs\EnsurePublicHolidaysSyncedJob;
|
|
use App\Models\PickupException;
|
|
use App\Models\Shop;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Date;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
afterEach(function (): void {
|
|
Date::setTestNow();
|
|
});
|
|
|
|
it('syncs current year before november when missing and skips subsequent runs', function (): void {
|
|
// GIVEN
|
|
Date::setTestNow('2026-06-15 07:30:00');
|
|
$shop = Shop::factory()->create();
|
|
|
|
Http::fake([
|
|
'https://calendrier.api.gouv.fr/jours-feries/metropole/2026.json' => Http::response([
|
|
'2026-01-01' => '1er janvier',
|
|
'2026-12-25' => 'Jour de Noël',
|
|
], 200),
|
|
]);
|
|
|
|
// WHEN
|
|
EnsurePublicHolidaysSyncedJob::dispatchSync();
|
|
|
|
// THEN
|
|
Http::assertSentCount(1);
|
|
expect(PickupException::query()->whereYear('date', 2026)->count())->toBe(2)
|
|
->and(PickupException::query()->whereYear('date', 2027)->count())->toBe(0)
|
|
->and($shop->pickupExceptions()->count())->toBe(2);
|
|
|
|
// WHEN (second run)
|
|
Http::fake();
|
|
EnsurePublicHolidaysSyncedJob::dispatchSync();
|
|
|
|
// THEN
|
|
Http::assertNothingSent();
|
|
});
|
|
|
|
it('catches up missing current and next year holidays on or after november and skips subsequent runs', function (): void {
|
|
// GIVEN
|
|
Date::setTestNow('2026-11-05 07:30:00');
|
|
$shop = Shop::factory()->create();
|
|
|
|
Http::fake([
|
|
'https://calendrier.api.gouv.fr/jours-feries/metropole/2026.json' => Http::response([
|
|
'2026-11-11' => 'Armistice',
|
|
'2026-12-25' => 'Jour de Noël',
|
|
], 200),
|
|
'https://calendrier.api.gouv.fr/jours-feries/metropole/2027.json' => Http::response([
|
|
'2027-11-11' => 'Armistice',
|
|
'2027-12-25' => 'Jour de Noël',
|
|
], 200),
|
|
]);
|
|
|
|
// WHEN
|
|
EnsurePublicHolidaysSyncedJob::dispatchSync();
|
|
|
|
// THEN
|
|
Http::assertSentCount(2);
|
|
expect(PickupException::query()->whereYear('date', 2026)->count())->toBe(2)
|
|
->and(PickupException::query()->whereYear('date', 2027)->count())->toBe(2)
|
|
->and($shop->pickupExceptions()->count())->toBe(4);
|
|
|
|
// WHEN (subsequent run)
|
|
Http::fake();
|
|
EnsurePublicHolidaysSyncedJob::dispatchSync();
|
|
|
|
// THEN
|
|
Http::assertNothingSent();
|
|
});
|