<?php

namespace Tests\Unit\Services\PurchaseOrders;

use App\Models\PurchaseOrder;
use App\Services\PurchaseOrders\PurchaseOrderStatusService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class PurchaseOrderStatusServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_cancel_marks_purchase_order_canceled(): void
    {
        $po = PurchaseOrder::query()->create([
            'po_number' => 'PO-700',
            'supplier_id' => 1,
            'status' => PurchaseOrder::STATUS_ORDERED,
            'subtotal' => 0,
            'tax' => 0,
            'total' => 0,
        ]);

        $service = new PurchaseOrderStatusService();
        $updated = $service->cancel($po->id);

        $this->assertSame(PurchaseOrder::STATUS_CANCELED, $updated->status);
        $this->assertDatabaseHas('purchase_orders', [
            'id' => $po->id,
            'status' => PurchaseOrder::STATUS_CANCELED,
        ]);
    }
}
