Skip to content

A free open source IT asset/license management system

Implement test case

Marcus Moore899c2eb19b48
diff --git a/app/Http/Requests/SaveUserRequest.php b/app/Http/Requests/SaveUserRequest.php
index 98e561549e..6527fca56f 100644
--- a/app/Http/Requests/SaveUserRequest.php
+++ b/app/Http/Requests/SaveUserRequest.php
@@ -32,6 +32,7 @@ class SaveUserRequest extends FormRequest
public function rules()
{
$rules = [
+ 'department_id' => 'nullable|integer|exists:departments,id',
'manager_id' => 'nullable|exists:users,id',
];
diff --git a/tests/Feature/Api/Users/UsersUpdateTest.php b/tests/Feature/Api/Users/UsersUpdateTest.php
index c813012354..14c9dcdbcb 100644
--- a/tests/Feature/Api/Users/UsersUpdateTest.php
+++ b/tests/Feature/Api/Users/UsersUpdateTest.php
@@ -15,11 +15,6 @@ class UsersUpdateTest extends TestCase
{
use InteractsWithSettings;
- public function testValidationForUpdatingUserViaPatch()
- {
- $this->markTestIncomplete();
- }
-
public function testCanUpdateUserViaPatch()
{
$admin = User::factory()->superuser()->create();
@@ -38,7 +33,7 @@ class UsersUpdateTest extends TestCase
]);
$this->actingAsForApi($admin)
- ->patch(route('api.users.update', $user), [
+ ->patchJson(route('api.users.update', $user), [
'first_name' => 'Mabel',
'last_name' => 'Mora',
'username' => 'mabel',
@@ -107,22 +102,12 @@ class UsersUpdateTest extends TestCase
$this->markTestIncomplete();
}
- public function testDepartmentPatching()
+ public function testDepartmentValidation()
{
- $admin = User::factory()->superuser()->create();
- $user = User::factory()->forDepartment(['name' => 'Department A'])->create();
- $department = Department::factory()->create();
-
- $this->actingAsForApi($admin)->patch(route('api.users.update', $user), [
- // This isn't valid but doesn't return an error
- 'department_id' => ['id' => $department->id],
- // This is the correct syntax
- // 'department_id' => $department->id,
- ])->assertOk();
-
- $this->assertTrue(
- $user->fresh()->department()->is($department),
- 'User is not associated with expected department'
- );
+ $this->actingAsForApi(User::factory()->superuser()->create())
+ ->patchJson(route('api.users.update', User::factory()->create()), [
+ // This isn't valid but was not returning an error
+ 'department_id' => ['id' => 1],
+ ])->assertJsonValidationErrorFor('department_id');
}
}