Completed
Push — master ( 36ad26...3f6195 )
by Mahmoud
03:35
created

SyncUserRolesTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testSyncMultipleRolesOnUser() 0 33 1
1
<?php
2
3
namespace App\Containers\Authorization\UI\API\Tests\Functional;
4
5
use App\Containers\Authorization\Models\Role;
6
use App\Containers\Authorization\Tests\TestCase;
7
use App\Containers\User\Models\User;
8
9
/**
10
 * Class SyncUserRolesTest.
11
 *
12
 * @author  Mahmoud Zalt <[email protected]>
13
 */
14
class SyncUserRolesTest extends TestCase
15
{
16
17
    protected $endpoint = '/roles/sync';
18
19
    protected $access = [
20
        'roles'       => 'admin',
21
        'permissions' => '',
22
    ];
23
24
    public function testSyncMultipleRolesOnUser()
25
    {
26
        $this->getTestingUser();
27
28
        $role1 = factory(Role::class)->create(['display_name' => '111']);
29
        $role2 = factory(Role::class)->create(['display_name' => '222']);
30
31
        $randomUser = factory(User::class)->create();
32
        $randomUser->assignRole($role1);
33
34
35
        $data = [
36
            'roles_ids' => [
37
                $role1->getHashedKey(),
38
                $role2->getHashedKey(),
39
            ],
40
            'user_id'   => $randomUser->getHashedKey(),
41
        ];
42
43
        // send the HTTP request
44
        $response = $this->apiCall($this->endpoint, 'post', $data, true);
45
46
        // assert response status is correct
47
        $this->assertEquals('200', $response->getStatusCode());
48
49
        $responseObject = $this->getResponseObject($response);
50
51
        $this->assertTrue(count($responseObject->data->roles->data) > 1);
52
53
        $this->assertEquals($data['roles_ids'][0], $responseObject->data->roles->data[0]->id);
54
55
        $this->assertEquals($data['roles_ids'][1], $responseObject->data->roles->data[1]->id);
56
    }
57
58
}
59