|
9 | 9 | use function Pest\Laravel\patch; |
10 | 10 |
|
11 | 11 | describe('Users', function () { |
12 | | - test('Can edit their accounts', function () { |
| 12 | + test('Can access the edit page', function () { |
13 | 13 | $user = User::factory()->create(); |
14 | 14 |
|
15 | 15 | actingAs($user) |
|
25 | 25 | }); |
26 | 26 |
|
27 | 27 | test('Can update their details', function () { |
28 | | - $user = User::factory()->create($oldData = [ |
| 28 | + $user = User::factory()->create([ |
29 | 29 | 'first_name' => 'Jim', |
30 | 30 | 'last_name' => 'Gordon', |
31 | 31 | 'email' => 'jim@test.com', |
32 | 32 | 'password' => 'oldPassword#123', |
33 | 33 | ]); |
34 | 34 |
|
35 | | - expect($user) |
36 | | - ->first_name->toBe($oldData['first_name']) |
37 | | - ->last_name->toBe($oldData['last_name']) |
38 | | - ->email->toBe($oldData['email']); |
39 | | - |
40 | | - expect(Hash::check($oldData['password'], $user->password))->toBeTrue(); |
41 | | - |
42 | 35 | actingAs($user) |
43 | 36 | ->patch(route('account.update'), $newData = [ |
44 | 37 | 'first_name' => 'Tim', |
|
56 | 49 |
|
57 | 50 | expect(Hash::check($newData['password'], $user->password))->toBeTrue(); |
58 | 51 | }); |
| 52 | + |
| 53 | + test("Can't update their email to one that already exists", function () { |
| 54 | + User::factory()->create([ |
| 55 | + 'email' => 'jim@test.com', |
| 56 | + ]); |
| 57 | + |
| 58 | + $user = User::factory()->create([ |
| 59 | + 'email' => 'jeff@test.com', |
| 60 | + ]); |
| 61 | + |
| 62 | + actingAs($user) |
| 63 | + ->patch(route('account.update'), $newData = [ |
| 64 | + 'email' => 'jim@test.com', |
| 65 | + ]) |
| 66 | + ->assertSessionHasErrors('email'); |
| 67 | + |
| 68 | + expect($user->refresh()->email)->not()->toBe($newData['email']); |
| 69 | + }); |
59 | 70 | }); |
60 | 71 |
|
61 | 72 | describe('Guests', function () { |
62 | | - test("Can't edit accounts", function () { |
| 73 | + test("Can't access the edit page", function () { |
63 | 74 | get(route('account.edit')) |
64 | 75 | ->assertRedirect(route('login')); |
65 | 76 | }); |
|
0 commit comments