<?php

namespace Tests\Feature;

use App\Actions\Fortify\ResetUserPassword;
use Illuminate\Validation\ValidationException;
use Mtc\MercuryDataModels\User;
use Tests\DatabaseTestCase;

class ResetUserPasswordTest extends DatabaseTestCase
{

    /**
     * A basic unit test example.
     *
     * @return void
     */
    public function testUpdatesUserPassword()
    {
        $user = User::factory()->create();

        $input = [
            'password' => 'SomethingSuperStrong2#',
            'password_confirmation' => 'SomethingSuperStrong2#',
        ];
        new ResetUserPassword()->reset($user, $input);
        $user->refresh();

        $this->assertTrue(password_verify('SomethingSuperStrong2#', (string) $user->password));
    }
    /**
     * A basic unit test example.
     *
     * @return void
     */
    public function testFailsWithoutRequiredData()
    {
        $user = User::factory()->create();

        $input = [
            'password' => 'SomethingSuperStrong2#',
        ];
        $this->expectException(ValidationException::class);
        new ResetUserPassword()->reset($user, $input);

        $input = [
            'password_confirmation' => 'SomethingSuperStrong2#',
        ];
        $this->expectException(ValidationException::class);
        new ResetUserPassword()->reset($user, $input);
    }
}
