|
1 | 1 | <?php
|
| 2 | + |
| 3 | +use App\Models\User; |
| 4 | + |
| 5 | +use function Pest\Laravel\actingAs; |
| 6 | +use function Pest\Laravel\assertAuthenticated; |
| 7 | +use function Pest\Laravel\assertGuest; |
| 8 | + |
| 9 | +test('profile page is displayed', function () { |
| 10 | + actingAs($user = User::factory()->create()); |
| 11 | + |
| 12 | + visit(route('profile.edit')) |
| 13 | + ->assertSee('Profile information') |
| 14 | + ->assertSee('Update your name and email address') |
| 15 | + ->assertValue('name', $user->name) |
| 16 | + ->assertValue('email', $user->email) |
| 17 | + ->assertNoConsoleLogs() |
| 18 | + ->assertNoJavaScriptErrors(); |
| 19 | +}); |
| 20 | + |
| 21 | +test('profile information can be updated', function () { |
| 22 | + actingAs($user = User::factory()->create()); |
| 23 | + |
| 24 | + visit(route('profile.edit')) |
| 25 | + ->assertSee('Profile information') |
| 26 | + ->assertSee('Update your name and email address') |
| 27 | + ->fill('name', 'Test User') |
| 28 | + -> fill( 'email', '[email protected]') |
| 29 | + ->press('Save') |
| 30 | + ->assertSee('Saved.') |
| 31 | + ->assertUrlIs(route('profile.edit')) |
| 32 | + ->assertNoConsoleLogs() |
| 33 | + ->assertNoJavaScriptErrors(); |
| 34 | + |
| 35 | + $user->refresh(); |
| 36 | + |
| 37 | + expect($user->name)->toBe('Test User'); |
| 38 | + expect( $user-> email)-> toBe( '[email protected]'); |
| 39 | + expect($user->email_verified_at)->toBeNull(); |
| 40 | +}); |
| 41 | + |
| 42 | +test('email verification status is unchanged when the email address is unchanged', function () { |
| 43 | + actingAs($user = User::factory()->create()); |
| 44 | + |
| 45 | + visit(route('profile.edit')) |
| 46 | + ->assertSee('Profile information') |
| 47 | + ->assertSee('Update your name and email address') |
| 48 | + ->fill('name', 'Test User') |
| 49 | + ->fill('email', $user->email) |
| 50 | + ->press('Save') |
| 51 | + ->assertSee('Saved.') |
| 52 | + ->assertUrlIs(route('profile.edit')) |
| 53 | + ->assertNoConsoleLogs() |
| 54 | + ->assertNoJavaScriptErrors(); |
| 55 | + |
| 56 | + expect($user->refresh()->email_verified_at)->not->toBeNull(); |
| 57 | +}); |
| 58 | + |
| 59 | +test('user can delete their account', function () { |
| 60 | + actingAs($user = User::factory()->create()); |
| 61 | + |
| 62 | + visit(route('profile.edit')) |
| 63 | + ->press('@delete-user') |
| 64 | + ->assertSee('Are you sure you want to delete your account?') |
| 65 | + ->fill('password', 'password') |
| 66 | + ->press('@confirm-delete-user') |
| 67 | + ->assertUrlIs(route('home')) |
| 68 | + ->assertNoConsoleLogs() |
| 69 | + ->assertNoJavaScriptErrors(); |
| 70 | + |
| 71 | + assertGuest(); |
| 72 | + expect($user->fresh())->toBeNull(); |
| 73 | +}); |
| 74 | + |
| 75 | +test('correct password must be provided to delete account', function () { |
| 76 | + actingAs($user = User::factory()->create()); |
| 77 | + |
| 78 | + visit(route('profile.edit')) |
| 79 | + ->press('@delete-user') |
| 80 | + ->assertSee('Are you sure you want to delete your account?') |
| 81 | + ->fill('password', 'wrong-password') |
| 82 | + ->press('@confirm-delete-user') |
| 83 | + ->assertUrlIs(route('profile.edit')) |
| 84 | + ->assertNoConsoleLogs() |
| 85 | + ->assertNoJavaScriptErrors(); |
| 86 | + |
| 87 | + assertAuthenticated(); |
| 88 | + expect($user->fresh())->not->toBeNull(); |
| 89 | +}); |
0 commit comments