<?php

use App\Livewire\Modals\DeleteAccount;
use App\Models\User;
use Livewire\Livewire;

it('renders delete account modal', function () {
    $user = User::factory()->create();

    Livewire::actingAs($user)->test(DeleteAccount::class)
        ->assertOk()
        ->assertSee('Delete Account');
});

it('requires password confirmation to delete account', function () {
    $user = User::factory()->create();

    Livewire::actingAs($user)->test(DeleteAccount::class)
        ->call('delete')
        ->assertHasErrors(['password' => 'required']);
});

it('rejects wrong password on delete account', function () {
    $user = User::factory()->create();

    Livewire::actingAs($user)->test(DeleteAccount::class)
        ->set('password', 'wrong-password')
        ->call('delete')
        ->assertHasErrors(['password']);
});

it('soft-deletes account with correct password and redirects', function () {
    $user = User::factory()->create();

    Livewire::actingAs($user)->test(DeleteAccount::class)
        ->set('password', 'password')
        ->call('delete')
        ->assertRedirect('/');

    $this->assertSoftDeleted('users', ['id' => $user->id]);
});
