BackfillPaidOrderStatusesCommandTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Tests\Feature;
  3. use App\Jobs\BackfillPaidOrderStatusesJob;
  4. use App\Models\Order;
  5. use App\Models\ProductSKU;
  6. use Illuminate\Foundation\Testing\RefreshDatabase;
  7. use Illuminate\Support\Facades\Artisan;
  8. use Illuminate\Support\Facades\Queue;
  9. use Tests\TestCase;
  10. class BackfillPaidOrderStatusesCommandTest extends TestCase
  11. {
  12. use RefreshDatabase;
  13. protected $seed = true;
  14. public function test_command_dispatches_backfill_job(): void
  15. {
  16. Queue::fake();
  17. $exitCode = Artisan::call('orders:backfill-paid-statuses', [
  18. '--year' => 2026,
  19. '--chunk' => 250,
  20. ]);
  21. $this->assertSame(0, $exitCode);
  22. Queue::assertPushed(BackfillPaidOrderStatusesJob::class);
  23. }
  24. public function test_command_can_run_backfill_synchronously(): void
  25. {
  26. $order = Order::factory()->create([
  27. 'year' => 2026,
  28. 'order_status_id' => Order::STATUS_HANDED_OVER,
  29. ]);
  30. ProductSKU::factory()->forOrder($order)->create([
  31. 'year' => 2026,
  32. 'statement_number' => 'ST-1',
  33. 'upd_number' => 'UPD-1',
  34. ]);
  35. $exitCode = Artisan::call('orders:backfill-paid-statuses', [
  36. '--year' => 2026,
  37. '--sync' => true,
  38. ]);
  39. $this->assertSame(0, $exitCode);
  40. $this->assertSame(Order::STATUS_PAID, $order->refresh()->order_status_id);
  41. }
  42. public function test_command_fails_when_chunk_size_is_invalid(): void
  43. {
  44. Queue::fake();
  45. $exitCode = Artisan::call('orders:backfill-paid-statuses', [
  46. '--chunk' => 0,
  47. ]);
  48. $this->assertSame(1, $exitCode);
  49. Queue::assertNothingPushed();
  50. }
  51. }