diff --git a/tests/Feature/Api/Users/UsersUpdateTest.php b/tests/Feature/Api/Users/UsersUpdateTest.php deleted file mode 100644 index d6e0f9e46b..0000000000 --- a/tests/Feature/Api/Users/UsersUpdateTest.php +++ /dev/null @@ -1,84 +0,0 @@ -superuser()->create(); - $manager = User::factory()->create(); - $company = Company::factory()->create(); - $department = Department::factory()->create(); - $location = Location::factory()->create(); - [$groupA, $groupB] = Group::factory()->count(2)->create(); - - $user = User::factory()->create([ - 'activated' => false, - 'remote' => false, - 'vip' => false, - ]); - - $this->actingAsForApi($admin) - ->patchJson(route('api.users.update', $user), [ - 'first_name' => 'Mabel', - 'last_name' => 'Mora', - 'username' => 'mabel', - 'password' => 'super-secret', - 'email' => 'mabel@onlymurderspod.com', - 'permissions' => '{"a.new.permission":"1"}', - 'activated' => true, - 'phone' => '619-555-5555', - 'jobtitle' => 'Host', - 'manager_id' => $manager->id, - 'employee_num' => '1111', - 'notes' => 'Pretty good artist', - 'company_id' => $company->id, - 'department_id' => $department->id, - 'location_id' => $location->id, - 'remote' => true, - 'groups' => $groupA->id, - 'vip' => true, - 'start_date' => '2021-08-01', - 'end_date' => '2025-12-31', - ]) - ->assertOk(); - - $user->refresh(); - $this->assertEquals('Mabel', $user->first_name, 'First name was not updated'); - $this->assertEquals('Mora', $user->last_name, 'Last name was not updated'); - $this->assertEquals('mabel', $user->username, 'Username was not updated'); - $this->assertTrue(Hash::check('super-secret', $user->password), 'Password was not updated'); - $this->assertEquals('mabel@onlymurderspod.com', $user->email, 'Email was not updated'); - $this->assertArrayHasKey('a.new.permission', $user->decodePermissions(), 'Permissions were not updated'); - $this->assertTrue((bool)$user->activated, 'User not marked as activated'); - $this->assertEquals('619-555-5555', $user->phone, 'Phone was not updated'); - $this->assertEquals('Host', $user->jobtitle, 'Job title was not updated'); - $this->assertTrue($user->manager->is($manager), 'Manager was not updated'); - $this->assertEquals('1111', $user->employee_num, 'Employee number was not updated'); - $this->assertEquals('Pretty good artist', $user->notes, 'Notes was not updated'); - $this->assertTrue($user->company->is($company), 'Company was not updated'); - $this->assertTrue($user->department->is($department), 'Department was not updated'); - $this->assertTrue($user->location->is($location), 'Location was not updated'); - $this->assertEquals(1, $user->remote, 'Remote was not updated'); - $this->assertTrue($user->groups->contains($groupA), 'Groups were not updated'); - $this->assertEquals(1, $user->vip, 'VIP was not updated'); - $this->assertEquals('2021-08-01', $user->start_date, 'Start date was not updated'); - $this->assertEquals('2025-12-31', $user->end_date, 'End date was not updated'); - - // `groups` can be an id or array or ids - $this->patch(route('api.users.update', $user), ['groups' => [$groupA->id, $groupB->id]]); - - $user->refresh(); - $this->assertTrue($user->groups->contains($groupA), 'Not part of expected group'); - $this->assertTrue($user->groups->contains($groupB), 'Not part of expected group'); - } -} diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Assets/Api/AssetIndexTest.php similarity index 99% rename from tests/Feature/Api/Assets/AssetIndexTest.php rename to tests/Feature/Assets/Api/AssetIndexTest.php index 0a21e13f26..c4a362d28b 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Assets/Api/AssetIndexTest.php @@ -1,13 +1,14 @@ superuser()->create(); + $manager = User::factory()->create(); + $company = Company::factory()->create(); + $department = Department::factory()->create(); + $location = Location::factory()->create(); + [$groupA, $groupB] = Group::factory()->count(2)->create(); + + $user = User::factory()->create([ + 'activated' => false, + 'remote' => false, + 'vip' => false, + ]); + + $this->actingAsForApi($admin) + ->patchJson(route('api.users.update', $user), [ + 'first_name' => 'Mabel', + 'last_name' => 'Mora', + 'username' => 'mabel', + 'password' => 'super-secret', + 'email' => 'mabel@onlymurderspod.com', + 'permissions' => '{"a.new.permission":"1"}', + 'activated' => true, + 'phone' => '619-555-5555', + 'jobtitle' => 'Host', + 'manager_id' => $manager->id, + 'employee_num' => '1111', + 'notes' => 'Pretty good artist', + 'company_id' => $company->id, + 'department_id' => $department->id, + 'location_id' => $location->id, + 'remote' => true, + 'groups' => $groupA->id, + 'vip' => true, + 'start_date' => '2021-08-01', + 'end_date' => '2025-12-31', + ]) + ->assertOk(); + + $user->refresh(); + $this->assertEquals('Mabel', $user->first_name, 'First name was not updated'); + $this->assertEquals('Mora', $user->last_name, 'Last name was not updated'); + $this->assertEquals('mabel', $user->username, 'Username was not updated'); + $this->assertTrue(Hash::check('super-secret', $user->password), 'Password was not updated'); + $this->assertEquals('mabel@onlymurderspod.com', $user->email, 'Email was not updated'); + $this->assertArrayHasKey('a.new.permission', $user->decodePermissions(), 'Permissions were not updated'); + $this->assertTrue((bool) $user->activated, 'User not marked as activated'); + $this->assertEquals('619-555-5555', $user->phone, 'Phone was not updated'); + $this->assertEquals('Host', $user->jobtitle, 'Job title was not updated'); + $this->assertTrue($user->manager->is($manager), 'Manager was not updated'); + $this->assertEquals('1111', $user->employee_num, 'Employee number was not updated'); + $this->assertEquals('Pretty good artist', $user->notes, 'Notes was not updated'); + $this->assertTrue($user->company->is($company), 'Company was not updated'); + $this->assertTrue($user->department->is($department), 'Department was not updated'); + $this->assertTrue($user->location->is($location), 'Location was not updated'); + $this->assertEquals(1, $user->remote, 'Remote was not updated'); + $this->assertTrue($user->groups->contains($groupA), 'Groups were not updated'); + $this->assertEquals(1, $user->vip, 'VIP was not updated'); + $this->assertEquals('2021-08-01', $user->start_date, 'Start date was not updated'); + $this->assertEquals('2025-12-31', $user->end_date, 'End date was not updated'); + + // `groups` can be an id or array or ids + $this->patch(route('api.users.update', $user), ['groups' => [$groupA->id, $groupB->id]]); + + $user->refresh(); + $this->assertTrue($user->groups->contains($groupA), 'Not part of expected group'); + $this->assertTrue($user->groups->contains($groupB), 'Not part of expected group'); + } + public function testApiUsersCanBeActivatedWithNumber() { $admin = User::factory()->superuser()->create(); diff --git a/tests/Feature/Api/Users/UsersSearchTest.php b/tests/Feature/Users/Api/UserSearchTest.php similarity index 98% rename from tests/Feature/Api/Users/UsersSearchTest.php rename to tests/Feature/Users/Api/UserSearchTest.php index 72f23017f5..2b1d557970 100644 --- a/tests/Feature/Api/Users/UsersSearchTest.php +++ b/tests/Feature/Users/Api/UserSearchTest.php @@ -1,13 +1,13 @@