|
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
|
|
|
|