forked from apiato/apiato
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e3a274
commit 932b4c1
Showing
2 changed files
with
74 additions
and
64 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
app/Containers/AppSection/Authorization/UI/API/Tests/Functional/AssignRolesToUserTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace App\Containers\AppSection\Authorization\UI\API\Tests\Functional; | ||
|
||
use App\Containers\AppSection\Authorization\Models\Role; | ||
use App\Containers\AppSection\Authorization\UI\API\Tests\ApiTestCase; | ||
use App\Containers\AppSection\User\Models\User; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Testing\Fluent\AssertableJson; | ||
|
||
/** | ||
* Class AssignRolesToUserTest. | ||
* | ||
* @group authorization | ||
* @group api | ||
*/ | ||
class AssignRolesToUserTest extends ApiTestCase | ||
{ | ||
protected string $endpoint = 'post@v1/roles/assign?include=roles'; | ||
|
||
protected array $access = [ | ||
'roles' => '', | ||
'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() | ||
); | ||
} | ||
} |
64 changes: 0 additions & 64 deletions
64
app/Containers/AppSection/Authorization/UI/API/Tests/Functional/AssignUserToRoleTest.php
This file was deleted.
Oops, something went wrong.