2FAuth/tests/Api/v1/Controllers/Auth/ResetPasswordControllerTest.php

92 lines
2.3 KiB
PHP
Raw Normal View History

2020-03-03 17:06:40 +01:00
<?php
2020-03-04 17:19:13 +01:00
namespace Tests\Feature\Auth;
2020-03-03 17:06:40 +01:00
use App\User;
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
/**
* @var \App\User
*/
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
{
2021-11-22 01:09:54 +01:00
$response = $this->json('POST', '/api/v1/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
{
2021-11-22 01:09:54 +01:00
$response = $this->json('POST', '/api/v1/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
{
2021-11-22 01:09:54 +01:00
$response = $this->json('POST', '/api/v1/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-11-22 01:09:54 +01:00
$this->user = factory(User::class)->create();
2020-03-03 17:06:40 +01:00
$token = Password::broker()->createToken($this->user);
2021-11-22 01:09:54 +01:00
$response = $this->json('POST', '/api/v1/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));
}
}