<?php

namespace Tests\Feature;

use App\Services\Installer\InstallMigrationAction;
use App\Services\Installer\WizardSessionStore;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Schema;
use Tests\TestCase;

class InstallMigrationActionTest extends TestCase
{
    public function test_migrations_run_after_database_step(): void
    {
        $sqlitePath = database_path('migration-step-test-'.uniqid().'.sqlite');
        touch($sqlitePath);

        app(WizardSessionStore::class)->merge([
            'db_connection' => 'sqlite',
            'db_database' => $sqlitePath,
        ]);

        $state = app(WizardSessionStore::class)->get();

        app(InstallMigrationAction::class)->execute($state);

        $this->assertTrue(Schema::connection('sqlite')->hasTable('sessions'));
        $this->assertTrue(Schema::connection('sqlite')->hasTable('users'));

        File::delete($sqlitePath);
    }
}
