create(); $response = $this ->actingAs($user) ->get(route('app.user-password.edit')); $response->assertOk(); }); test('password can be updated', function () { $user = User::factory()->create(); $response = $this ->actingAs($user) ->from(route('app.user-password.edit')) ->put(route('app.user-password.update'), [ 'current_password' => 'password', 'password' => 'new-password', 'password_confirmation' => 'new-password', ]); $response ->assertSessionHasNoErrors() ->assertRedirect(route('app.user-password.edit')); expect(Hash::check('new-password', $user->refresh()->password))->toBeTrue(); }); test('correct password must be provided to update password', function () { $user = User::factory()->create(); $response = $this ->actingAs($user) ->from(route('app.user-password.edit')) ->put(route('app.user-password.update'), [ 'current_password' => 'wrong-password', 'password' => 'new-password', 'password_confirmation' => 'new-password', ]); $response ->assertSessionHasErrors('current_password') ->assertRedirect(route('app.user-password.edit')); }); test('password update requires authentication', function () { $response = $this->put(route('app.user-password.update'), []); $response->assertRedirect(route('login')); }); test('password must be confirmed', function () { $user = User::factory()->create(); $response = $this ->actingAs($user) ->from(route('app.user-password.edit')) ->put(route('app.user-password.update'), [ 'current_password' => 'password', 'password' => 'new-password', 'password_confirmation' => 'wrong-confirmation', ]); $response->assertSessionHasErrors('password'); });