|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | use App\Jobs\FetchLlmUsageJob; |
| 4 | +use Carbon\CarbonImmutable; |
| 5 | +use Carbon\Exceptions\InvalidFormatException; |
4 | 6 | use Illuminate\Support\Facades\Queue; |
5 | 7 |
|
6 | 8 | it('dispatches one job per day for the default range', function () { |
|
11 | 13 | Queue::assertPushed(FetchLlmUsageJob::class, 4); |
12 | 14 | })->group('llm-analytics'); |
13 | 15 |
|
| 16 | +it('backfills from the initial sync start with the full flag', function () { |
| 17 | + Queue::fake(); |
| 18 | + |
| 19 | + $this->artisan('llm:fetch-analytics', ['--full' => true])->assertSuccessful(); |
| 20 | + |
| 21 | + $expectedDays = (int) CarbonImmutable::parse('2026-01-01')->diffInDays(CarbonImmutable::today()) + 1; |
| 22 | + |
| 23 | + Queue::assertPushed(FetchLlmUsageJob::class, $expectedDays); |
| 24 | + |
| 25 | + Queue::assertPushed(fn (FetchLlmUsageJob $job) => $job->date->toDateString() === '2026-01-01'); |
| 26 | +})->group('llm-analytics'); |
| 27 | + |
14 | 28 | it('dispatches one job per day for a custom range', function () { |
15 | 29 | Queue::fake(); |
16 | 30 |
|
|
23 | 37 | Queue::assertPushed(fn (FetchLlmUsageJob $job) => $job->date->toDateString() === '2026-01-05'); |
24 | 38 | })->group('llm-analytics'); |
25 | 39 |
|
26 | | -it('fails on an invalid date', function () { |
| 40 | +it('throws on an invalid date', function () { |
27 | 41 | Queue::fake(); |
28 | 42 |
|
29 | | - $this->artisan('llm:fetch-analytics', ['--from' => 'not-a-date'])->assertFailed(); |
30 | | - |
31 | | - Queue::assertNothingPushed(); |
32 | | -})->group('llm-analytics'); |
| 43 | + $this->artisan('llm:fetch-analytics', ['--from' => 'not-a-date']); |
| 44 | +})->throws(InvalidFormatException::class)->group('llm-analytics'); |
33 | 45 |
|
34 | 46 | it('fails when from is after to', function () { |
35 | 47 | Queue::fake(); |
|
0 commit comments