| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace Tests\Feature;
- use App\Jobs\BackfillPaidOrderStatusesJob;
- use App\Models\Order;
- use App\Models\ProductSKU;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Illuminate\Support\Facades\Artisan;
- use Illuminate\Support\Facades\Queue;
- use Tests\TestCase;
- class BackfillPaidOrderStatusesCommandTest extends TestCase
- {
- use RefreshDatabase;
- protected $seed = true;
- public function test_command_dispatches_backfill_job(): void
- {
- Queue::fake();
- $exitCode = Artisan::call('orders:backfill-paid-statuses', [
- '--year' => 2026,
- '--chunk' => 250,
- ]);
- $this->assertSame(0, $exitCode);
- Queue::assertPushed(BackfillPaidOrderStatusesJob::class);
- }
- public function test_command_can_run_backfill_synchronously(): void
- {
- $order = Order::factory()->create([
- 'year' => 2026,
- 'order_status_id' => Order::STATUS_HANDED_OVER,
- ]);
- ProductSKU::factory()->forOrder($order)->create([
- 'year' => 2026,
- 'statement_number' => 'ST-1',
- 'upd_number' => 'UPD-1',
- ]);
- $exitCode = Artisan::call('orders:backfill-paid-statuses', [
- '--year' => 2026,
- '--sync' => true,
- ]);
- $this->assertSame(0, $exitCode);
- $this->assertSame(Order::STATUS_PAID, $order->refresh()->order_status_id);
- }
- public function test_command_fails_when_chunk_size_is_invalid(): void
- {
- Queue::fake();
- $exitCode = Artisan::call('orders:backfill-paid-statuses', [
- '--chunk' => 0,
- ]);
- $this->assertSame(1, $exitCode);
- Queue::assertNothingPushed();
- }
- }
|