12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace Tests\Api\v1\Controllers\Auth;
- use App\Models\User;
- use Illuminate\Support\Facades\Hash;
- use Illuminate\Support\Facades\Password;
- use Illuminate\Support\Facades\Notification;
- use Tests\FeatureTestCase;
- class ResetPasswordControllerTest extends FeatureTestCase
- {
- /**
- * @var \App\Models\User
- */
- protected $user;
- /**
- * @test
- */
- public function test_submit_reset_password_without_input_returns_validation_error()
- {
- $response = $this->json('POST', '/api/v1/user/password/reset', [
- 'email' => '',
- 'password' => '',
- 'password_confirmation' => '',
- 'token' => ''
- ]);
- $response->assertStatus(422)
- ->assertJsonValidationErrors(['email', 'password', 'token']);
- }
- /**
- * @test
- */
- public function test_submit_reset_password_with_invalid_data_returns_validation_error()
- {
- $response = $this->json('POST', '/api/v1/user/password/reset', [
- 'email' => 'qsdqsdqsd',
- 'password' => 'foofoofoo',
- 'password_confirmation' => 'barbarbar',
- 'token' => 'token'
- ]);
- $response->assertStatus(422)
- ->assertJsonValidationErrors(['email', 'password']);
- }
- /**
- * @test
- */
- public function test_submit_reset_password_with_too_short_pwd_returns_validation_error()
- {
- $response = $this->json('POST', '/api/v1/user/password/reset', [
- 'email' => 'foo@bar.com',
- 'password' => 'foo',
- 'password_confirmation' => 'foo',
- 'token' => 'token'
- ]);
- $response->assertStatus(422)
- ->assertJsonValidationErrors(['password']);
- }
- /**
- * @test
- */
- public function test_submit_reset_password_returns_success()
- {
- Notification::fake();
- $this->user = User::factory()->create();
- $token = Password::broker()->createToken($this->user);
- $response = $this->json('POST', '/api/v1/user/password/reset', [
- 'email' => $this->user->email,
- 'password' => 'newpassword',
- 'password_confirmation' => 'newpassword',
- 'token' => $token
- ]);
- $this->user->refresh();
- $response->assertOk();
- $this->assertTrue(Hash::check('newpassword', $this->user->password));
- }
- }
|