mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Implement test case
This commit is contained in:
parent
1c3c36f2a0
commit
899c2eb19b
|
@ -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',
|
||||
];
|
||||
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue