Completed
Push — master ( 769d17...6fd8a2 )
by Mahmoud
03:54
created

RefreshUserTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testRefreshUserById_() 0 15 1
A testRefreshUserByVisitorId_() 0 14 1
A testRefreshUserByToken_() 0 8 1
1
<?php
2
3
namespace App\Containers\User\UI\API\Tests\Functional;
4
5
use App\Port\Tests\PHPUnit\Abstracts\TestCase;
6
7
/**
8
 * Class RefreshUserTest.
9
 *
10
 * @author Mahmoud Zalt <[email protected]>
11
 */
12
class RefreshUserTest extends TestCase
13
{
14
15
    private $endpoint = '/users/refresh';
16
17
    public function testRefreshUserById_()
18
    {
19
        // get the logged in user (create one if no one is logged in)
20
        $user = $this->registerAndLoginTestingUser();
21
22
        $data = [
23
            'user_id' => $user->id,
24
        ];
25
26
        // send the HTTP request
27
        $response = $this->apiCall($this->endpoint, 'post', $data, false);
28
29
        // assert response status is correct
30
        $this->assertEquals($response->getStatusCode(), '200');
31
    }
32
33
    public function testRefreshUserByVisitorId_()
34
    {
35
        // get the logged in user (create one if no one is logged in)
36
        $user = $this->registerAndLoginTestingUser();
37
        unset($user->token);
38
        $user->visitor_id = str_random(40);
39
        $user->save();
40
41
        // send the HTTP request
42
        $response = $this->apiCall($this->endpoint, 'post', [], false, ['visitor-id' => $user->visitor_id]);
43
44
        // assert response status is correct
45
        $this->assertEquals($response->getStatusCode(), '200');
46
    }
47
48
    public function testRefreshUserByToken_()
49
    {
50
        // send the HTTP request
51
        $response = $this->apiCall($this->endpoint, 'post', [], true);
52
53
        // assert response status is correct
54
        $this->assertEquals($response->getStatusCode(), '200');
55
    }
56
}
57