edit user functionality
This commit is contained in:
44
tests/Feature/UserTest.php
Normal file
44
tests/Feature/UserTest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
test('user edit page requires authentication', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->get("/user/{$user->id}/edit")->assertRedirect('/login');
|
||||
});
|
||||
|
||||
test('authenticated users can view the user edit page', function () {
|
||||
$actingUser = User::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this
|
||||
->actingAs($actingUser)
|
||||
->get("/user/{$user->id}/edit");
|
||||
|
||||
$response
|
||||
->assertSuccessful()
|
||||
->assertSee('Edit User')
|
||||
->assertSee($user->name)
|
||||
->assertSee($user->email);
|
||||
});
|
||||
|
||||
test('authenticated users can update a user', function () {
|
||||
$actingUser = User::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this
|
||||
->actingAs($actingUser)
|
||||
->patch("/user/{$user->id}", [
|
||||
'name' => 'Updated User',
|
||||
'email' => 'updated@example.com',
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertRedirect("/user/{$user->id}/edit");
|
||||
|
||||
$user->refresh();
|
||||
|
||||
$this->assertSame('Updated User', $user->name);
|
||||
$this->assertSame('updated@example.com', $user->email);
|
||||
});
|
||||
Reference in New Issue
Block a user