edit user functionality

This commit is contained in:
2026-05-11 11:54:18 +08:00
parent 27c2869109
commit f110790e09
6 changed files with 166 additions and 1 deletions

View 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);
});