comparison stubs/default/pest-tests/Feature/ProfileTest.php @ 0:90e38de8f2ba

Initial Commit
author luka
date Wed, 13 Aug 2025 22:17:20 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:90e38de8f2ba
1 <?php
2
3 use App\Models\User;
4
5 test('profile page is displayed', function () {
6 $user = User::factory()->create();
7
8 $response = $this
9 ->actingAs($user)
10 ->get('/profile');
11
12 $response->assertOk();
13 });
14
15 test('profile information can be updated', function () {
16 $user = User::factory()->create();
17
18 $response = $this
19 ->actingAs($user)
20 ->patch('/profile', [
21 'name' => 'Test User',
22 'email' => 'test@example.com',
23 ]);
24
25 $response
26 ->assertSessionHasNoErrors()
27 ->assertRedirect('/profile');
28
29 $user->refresh();
30
31 $this->assertSame('Test User', $user->name);
32 $this->assertSame('test@example.com', $user->email);
33 $this->assertNull($user->email_verified_at);
34 });
35
36 test('email verification status is unchanged when the email address is unchanged', function () {
37 $user = User::factory()->create();
38
39 $response = $this
40 ->actingAs($user)
41 ->patch('/profile', [
42 'name' => 'Test User',
43 'email' => $user->email,
44 ]);
45
46 $response
47 ->assertSessionHasNoErrors()
48 ->assertRedirect('/profile');
49
50 $this->assertNotNull($user->refresh()->email_verified_at);
51 });
52
53 test('user can delete their account', function () {
54 $user = User::factory()->create();
55
56 $response = $this
57 ->actingAs($user)
58 ->delete('/profile', [
59 'password' => 'password',
60 ]);
61
62 $response
63 ->assertSessionHasNoErrors()
64 ->assertRedirect('/');
65
66 $this->assertGuest();
67 $this->assertNull($user->fresh());
68 });
69
70 test('correct password must be provided to delete account', function () {
71 $user = User::factory()->create();
72
73 $response = $this
74 ->actingAs($user)
75 ->from('/profile')
76 ->delete('/profile', [
77 'password' => 'wrong-password',
78 ]);
79
80 $response
81 ->assertSessionHasErrorsIn('userDeletion', 'password')
82 ->assertRedirect('/profile');
83
84 $this->assertNotNull($user->fresh());
85 });