|
| 1 | +<?php |
| 2 | + |
| 3 | +use App\Models\User; |
| 4 | +use Illuminate\Support\Facades\Hash; |
| 5 | + |
| 6 | +use function Pest\Laravel\actingAs; |
| 7 | + |
| 8 | +test('password update page is displayed', function () { |
| 9 | + actingAs(User::factory()->create()); |
| 10 | + |
| 11 | + visit(route('password.edit')) |
| 12 | + ->assertSee('Update password') |
| 13 | + ->assertSee('Ensure your account is using a long, random password to stay secure') |
| 14 | + ->assertNoConsoleLogs() |
| 15 | + ->assertNoJavaScriptErrors(); |
| 16 | +}); |
| 17 | + |
| 18 | +test('password can be updated', function () { |
| 19 | + actingAs($user = User::factory()->create()); |
| 20 | + |
| 21 | + visit(route('password.edit')) |
| 22 | + ->fill('current_password', 'password') |
| 23 | + ->fill('password', 'new-password') |
| 24 | + ->fill('password_confirmation', 'new-password') |
| 25 | + ->press('Save password') |
| 26 | + ->assertSee('Saved') |
| 27 | + ->assertUrlIs(route('password.edit')) |
| 28 | + ->assertNoConsoleLogs() |
| 29 | + ->assertNoJavaScriptErrors(); |
| 30 | + |
| 31 | + expect(Hash::check('new-password', $user->refresh()->password))->toBeTrue(); |
| 32 | +}); |
| 33 | + |
| 34 | +test('correct password must be provided to update password', function () { |
| 35 | + actingAs($user = User::factory()->create()); |
| 36 | + |
| 37 | + visit(route('password.edit')) |
| 38 | + ->fill('current_password', 'wrong-password') |
| 39 | + ->fill('password', 'new-password') |
| 40 | + ->fill('password_confirmation', 'new-password') |
| 41 | + ->press('Save password') |
| 42 | + ->assertSee('The password is incorrect.') |
| 43 | + ->assertUrlIs(route('password.edit')) |
| 44 | + ->assertNoConsoleLogs() |
| 45 | + ->assertNoJavaScriptErrors(); |
| 46 | + |
| 47 | + expect(Hash::check('wrong-password', $user->refresh()->password))->toBeFalse(); |
| 48 | +}); |
0 commit comments