Total Complexity | 3 |
Total Lines | 86 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | final class AuthCest |
||
12 | { |
||
13 | public function auth(AcceptanceTester $I): void |
||
14 | { |
||
15 | $I->haveHttpHeader('Content-Type', 'application/json'); |
||
16 | $I->sendPOST( |
||
17 | '/auth/', |
||
18 | [ |
||
19 | 'login' => 'Opal1144', |
||
20 | 'password' => 'Opal1144', |
||
21 | ] |
||
22 | ); |
||
23 | $I->seeResponseCodeIs(HttpCode::OK); |
||
24 | $I->seeResponseIsJson(); |
||
25 | $I->seeResponseContainsJson( |
||
26 | [ |
||
27 | 'status' => 'success', |
||
28 | 'error_message' => '', |
||
29 | 'error_code' => null, |
||
30 | ] |
||
31 | ); |
||
32 | |||
33 | $response = Json::decode($I->grabResponse()); |
||
34 | $I->seeInDatabase( |
||
35 | 'user', |
||
36 | [ |
||
37 | 'id' => 1, |
||
38 | 'token' => $response['data']['token'], |
||
39 | ] |
||
40 | ); |
||
41 | } |
||
42 | |||
43 | public function logout(AcceptanceTester $I): void |
||
44 | { |
||
45 | $I->haveHttpHeader( |
||
46 | 'X-Api-Key', |
||
47 | 'lev1ZsWCzqrMlXRI2sT8h4ApYpSgBMl1xf6D4bCRtiKtDqw6JN36yLznargilQ_rEJz9zTfcUxm53PLODCToF9gGin38Rd4NkhQPOVeH5VvZvBaQlUg64E6icNCubiAv' |
||
48 | ); |
||
49 | |||
50 | $I->sendPOST( |
||
51 | '/logout/' |
||
52 | ); |
||
53 | |||
54 | $I->seeResponseCodeIs(HttpCode::OK); |
||
55 | $I->seeResponseIsJson(); |
||
56 | $I->seeResponseContainsJson( |
||
57 | [ |
||
58 | 'status' => 'success', |
||
59 | 'error_message' => '', |
||
60 | 'error_code' => null, |
||
61 | ] |
||
62 | ); |
||
63 | |||
64 | $I->dontSeeInDatabase( |
||
65 | 'user', |
||
66 | [ |
||
67 | 'id' => 1, |
||
68 | 'token' => 'lev1ZsWCzqrMlXRI2sT8h4ApYpSgBMl1xf6D4bCRtiKtDqw6JN36yLznargilQ_rEJz9zTfcUxm53PLODCToF9gGin38Rd4NkhQPOVeH5VvZvBaQlUg64E6icNCubiAv', |
||
69 | ] |
||
70 | ); |
||
71 | } |
||
72 | |||
73 | public function logoutWithBadToken(AcceptanceTester $I): void |
||
74 | { |
||
75 | $I->haveHttpHeader( |
||
76 | 'X-Api-Key', |
||
77 | 'bad-token' |
||
78 | ); |
||
79 | |||
80 | $I->haveHttpHeader( |
||
81 | 'Accept', |
||
82 | 'application/json' |
||
83 | ); |
||
84 | |||
85 | $I->sendPOST( |
||
86 | '/logout/' |
||
87 | ); |
||
88 | |||
89 | $I->seeResponseCodeIs(HttpCode::UNAUTHORIZED); |
||
90 | $I->seeResponseIsJson(); |
||
91 | $I->seeResponseContainsJson( |
||
92 | [ |
||
93 | 'status' => 'failed', |
||
94 | 'error_message' => 'Unauthorised request', |
||
95 | 'error_code' => HttpCode::UNAUTHORIZED, |
||
96 | 'data' => null, |
||
97 | ] |
||
101 |