From 932b4c1c189766c4c4864d5be80a99275b5d192b Mon Sep 17 00:00:00 2001 From: mohammad-alavi Date: Tue, 28 Sep 2021 17:06:58 +0330 Subject: [PATCH] rename and refactor --- .../Functional/AssignRolesToUserTest.php | 74 +++++++++++++++++++ .../Tests/Functional/AssignUserToRoleTest.php | 64 ---------------- 2 files changed, 74 insertions(+), 64 deletions(-) create mode 100644 app/Containers/AppSection/Authorization/UI/API/Tests/Functional/AssignRolesToUserTest.php delete mode 100644 app/Containers/AppSection/Authorization/UI/API/Tests/Functional/AssignUserToRoleTest.php diff --git a/app/Containers/AppSection/Authorization/UI/API/Tests/Functional/AssignRolesToUserTest.php b/app/Containers/AppSection/Authorization/UI/API/Tests/Functional/AssignRolesToUserTest.php new file mode 100644 index 000000000..aa8c0dff4 --- /dev/null +++ b/app/Containers/AppSection/Authorization/UI/API/Tests/Functional/AssignRolesToUserTest.php @@ -0,0 +1,74 @@ + '', + 'permissions' => 'manage-admins-access', + ]; + + public function testAssignRoleToUser(): void + { + $user = User::factory()->create(); + $role = Role::factory()->create(); + $data = [ + 'roles_ids' => [$role->getHashedKey()], + 'user_id' => $user->getHashedKey(), + ]; + + $response = $this->makeCall($data); + + $response->assertStatus(200); + $response->assertJson( + fn (AssertableJson $json) => + $json->has('data') + ->has('data.roles.data', 1) + ->where('data.id', $data['user_id']) + ->where('data.roles.data.0.id', $data['roles_ids'][0]) + ->etc() + ); + } + + public function testAssignManyRolesToUser(): void + { + $user = User::factory()->create(); + $role1 = Role::factory()->create(); + $role2 = Role::factory()->create(); + $data = [ + 'roles_ids' => [ + $role1->getHashedKey(), + $role2->getHashedKey(), + ], + 'user_id' => $user->getHashedKey(), + ]; + + $response = $this->makeCall($data); + + $response->assertStatus(200); + $response->assertJson( + fn (AssertableJson $json) => + $json->has('data') + ->has('data.roles.data', 2) + ->where('data.id', $data['user_id']) + ->where('data.roles.data.0.id', $data['roles_ids'][0]) + ->where('data.roles.data.1.id', $data['roles_ids'][1]) + ->etc() + ); + } +} diff --git a/app/Containers/AppSection/Authorization/UI/API/Tests/Functional/AssignUserToRoleTest.php b/app/Containers/AppSection/Authorization/UI/API/Tests/Functional/AssignUserToRoleTest.php deleted file mode 100644 index ed6584d02..000000000 --- a/app/Containers/AppSection/Authorization/UI/API/Tests/Functional/AssignUserToRoleTest.php +++ /dev/null @@ -1,64 +0,0 @@ - '', - 'permissions' => 'manage-admins-access', - ]; - - public function testAssignUserToRole(): void - { - $randomUser = User::factory()->create(); - $role = Role::factory()->create(); - $data = [ - 'roles_ids' => [$role->getHashedKey()], - 'user_id' => $randomUser->getHashedKey(), - ]; - - $response = $this->makeCall($data); - - $response->assertStatus(200); - $responseContent = $this->getResponseContentObject(); - $this->assertEquals($data['user_id'], $responseContent->data->id); - $this->assertEquals($data['roles_ids'][0], $responseContent->data->roles->data[0]->id); - } - - public function testAssignUserToManyRoles(): void - { - $randomUser = User::factory()->create(); - $role1 = Role::factory()->create(); - $role2 = Role::factory()->create(); - $data = [ - 'roles_ids' => [ - $role1->getHashedKey(), - $role2->getHashedKey(), - ], - 'user_id' => $randomUser->getHashedKey(), - ]; - - $response = $this->makeCall($data); - - $response->assertStatus(200); - $responseContent = $this->getResponseContentObject(); - $this->assertTrue(count($responseContent->data->roles->data) > 1); - $roleIds = Arr::pluck($responseContent->data->roles->data, 'id'); - $this->assertContains($data['roles_ids'][0], $roleIds); - $this->assertContains($data['roles_ids'][1], $roleIds); - } -}