forked from laravel/jetstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdatePasswordTest.php
44 lines (32 loc) · 1.25 KB
/
UpdatePasswordTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
use App\Models\User;
use Illuminate\Support\Facades\Hash;
test('password can be updated', function () {
$this->actingAs($user = User::factory()->create());
$response = $this->put('/user/password', [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
expect(Hash::check('new-password', $user->fresh()->password))->toBeTrue();
});
test('current password must be correct', function () {
$this->actingAs($user = User::factory()->create());
$response = $this->put('/user/password', [
'current_password' => 'wrong-password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
$response->assertSessionHasErrors();
expect(Hash::check('password', $user->fresh()->password))->toBeTrue();
});
test('new passwords must match', function () {
$this->actingAs($user = User::factory()->create());
$response = $this->put('/user/password', [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'wrong-password',
]);
$response->assertSessionHasErrors();
expect(Hash::check('password', $user->fresh()->password))->toBeTrue();
});