Level 70
@vidhyaprakash85 Try this:
test('super admin can update user', function () {
// Arrange: Create necessary instances
$user = User::factory()->create();
$gender = Gender::factory()->create();
// other related models...
// Act: Visit the edit route and attempt to update the user
$response = $this->get(route('user.edit', $user->id));
$response->assertStatus(200);
$updateData = [
'username' => 'Test',
'gender_id' => $gender->id,
/* other fields */
];
$response = $this->put(route('user.update', $user->id), $updateData);
// Assert: Check database and response
$this->assertDatabaseHas('users', $updateData);
$response->assertStatus(302);
$response->assertRedirect(route('user.index'));
});
3 likes