<?php

namespace Tests\Feature\Migrations;

use App\Domains\Tenant\Models\Tenant;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class AddCheckoutEditingPolicyToTenantsTest extends TestCase
{
    use RefreshDatabase;

    public function test_it_disables_checkout_editing_for_every_tenant(): void
    {
        Tenant::query()->where('codigo', 'sonder')->update([
            'cart_editing_policy' => 'disabled',
        ]);
        Tenant::query()->where('codigo', 'fiesta_futbol_infantil')->update([
            'cart_editing_policy' => 'quantity_and_remove',
        ]);

        $migration = require database_path(
            'migrations/2026_08_20_000000_add_checkout_editing_policy_to_tenants.php'
        );

        $migration->down();
        $migration->up();

        $this->assertDatabaseHas('tenants', [
            'codigo' => 'sonder',
            'cart_editing_policy' => 'disabled',
            'checkout_editing_policy' => 'disabled',
        ]);
        $this->assertDatabaseHas('tenants', [
            'codigo' => 'fiesta_futbol_infantil',
            'cart_editing_policy' => 'quantity_and_remove',
            'checkout_editing_policy' => 'disabled',
        ]);
    }
}
