<?php

namespace Tests\Unit\Services\Inventory;

use App\Services\Inventory\InventoryCategoryService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class InventoryCategoryServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_create_category(): void
    {
        $service = new InventoryCategoryService();
        $result = $service->create([
            'type' => 'office',
            'name' => 'Supplies',
        ]);

        $this->assertTrue($result['ok']);
        $this->assertDatabaseHas('inventory_categories', ['name' => 'Supplies']);
    }

    public function test_update_category(): void
    {
        $categoryId = DB::table('inventory_categories')->insertGetId([
            'type' => 'office',
            'name' => 'Office',
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        $service = new InventoryCategoryService();
        $result = $service->update($categoryId, ['name' => 'Updated']);

        $this->assertTrue($result['ok']);
        $this->assertDatabaseHas('inventory_categories', ['id' => $categoryId, 'name' => 'Updated']);
    }
}
