2020-03-03 17:06:40 +01:00
|
|
|
<?php
|
|
|
|
|
2022-03-31 08:38:35 +02:00
|
|
|
namespace Tests\Feature\Auth;
|
2020-03-03 17:06:40 +01:00
|
|
|
|
2021-12-02 13:15:53 +01:00
|
|
|
use App\Models\User;
|
2020-03-03 17:06:40 +01:00
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
use Illuminate\Support\Facades\Password;
|
|
|
|
use Illuminate\Support\Facades\Notification;
|
2021-11-22 01:09:54 +01:00
|
|
|
use Tests\FeatureTestCase;
|
2020-03-03 17:06:40 +01:00
|
|
|
|
2021-11-22 01:09:54 +01:00
|
|
|
class ResetPasswordControllerTest extends FeatureTestCase
|
2020-03-03 17:06:40 +01:00
|
|
|
{
|
2021-11-22 01:09:54 +01:00
|
|
|
/**
|
2021-12-02 13:15:53 +01:00
|
|
|
* @var \App\Models\User
|
2021-11-22 01:09:54 +01:00
|
|
|
*/
|
2020-03-03 17:06:40 +01:00
|
|
|
protected $user;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-22 01:09:54 +01:00
|
|
|
* @test
|
2020-03-03 17:06:40 +01:00
|
|
|
*/
|
2021-11-22 01:09:54 +01:00
|
|
|
public function test_submit_reset_password_without_input_returns_validation_error()
|
2020-03-03 17:06:40 +01:00
|
|
|
{
|
2022-03-31 08:38:35 +02:00
|
|
|
$response = $this->json('POST', '/user/password/reset', [
|
2020-03-03 17:06:40 +01:00
|
|
|
'email' => '',
|
|
|
|
'password' => '',
|
|
|
|
'password_confirmation' => '',
|
|
|
|
'token' => ''
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response->assertStatus(422)
|
|
|
|
->assertJsonValidationErrors(['email', 'password', 'token']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-22 01:09:54 +01:00
|
|
|
* @test
|
2020-03-03 17:06:40 +01:00
|
|
|
*/
|
2021-11-22 01:09:54 +01:00
|
|
|
public function test_submit_reset_password_with_invalid_data_returns_validation_error()
|
2020-03-03 17:06:40 +01:00
|
|
|
{
|
2022-03-31 08:38:35 +02:00
|
|
|
$response = $this->json('POST', '/user/password/reset', [
|
2020-03-03 17:06:40 +01:00
|
|
|
'email' => 'qsdqsdqsd',
|
|
|
|
'password' => 'foofoofoo',
|
|
|
|
'password_confirmation' => 'barbarbar',
|
|
|
|
'token' => 'token'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response->assertStatus(422)
|
|
|
|
->assertJsonValidationErrors(['email', 'password']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-22 01:09:54 +01:00
|
|
|
* @test
|
2020-03-03 17:06:40 +01:00
|
|
|
*/
|
2021-11-22 01:09:54 +01:00
|
|
|
public function test_submit_reset_password_with_too_short_pwd_returns_validation_error()
|
2020-03-03 17:06:40 +01:00
|
|
|
{
|
2022-03-31 08:38:35 +02:00
|
|
|
$response = $this->json('POST', '/user/password/reset', [
|
2020-03-03 17:06:40 +01:00
|
|
|
'email' => 'foo@bar.com',
|
|
|
|
'password' => 'foo',
|
|
|
|
'password_confirmation' => 'foo',
|
|
|
|
'token' => 'token'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response->assertStatus(422)
|
|
|
|
->assertJsonValidationErrors(['password']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-22 01:09:54 +01:00
|
|
|
* @test
|
2020-03-03 17:06:40 +01:00
|
|
|
*/
|
2021-11-22 01:09:54 +01:00
|
|
|
public function test_submit_reset_password_returns_success()
|
2020-03-03 17:06:40 +01:00
|
|
|
{
|
|
|
|
Notification::fake();
|
|
|
|
|
2021-12-02 13:15:53 +01:00
|
|
|
$this->user = User::factory()->create();
|
2020-03-03 17:06:40 +01:00
|
|
|
$token = Password::broker()->createToken($this->user);
|
|
|
|
|
2022-03-31 08:38:35 +02:00
|
|
|
$response = $this->json('POST', '/user/password/reset', [
|
2020-03-03 17:06:40 +01:00
|
|
|
'email' => $this->user->email,
|
|
|
|
'password' => 'newpassword',
|
|
|
|
'password_confirmation' => 'newpassword',
|
|
|
|
'token' => $token
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->user->refresh();
|
|
|
|
|
2021-11-22 01:09:54 +01:00
|
|
|
$response->assertOk();
|
2020-03-03 17:06:40 +01:00
|
|
|
$this->assertTrue(Hash::check('newpassword', $this->user->password));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|