|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MinepicTests\Http\Controllers; |
|
6
|
|
|
|
|
7
|
|
|
use Database\Factories\AccountFactory; |
|
8
|
|
|
use MinepicTests\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
class JsonControllerTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
protected function setUp(): void |
|
13
|
|
|
{ |
|
14
|
|
|
parent::setUp(); |
|
15
|
|
|
\DB::beginTransaction(); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
protected function tearDown(): void |
|
19
|
|
|
{ |
|
20
|
|
|
\DB::rollBack(); |
|
21
|
|
|
parent::tearDown(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testReturnTypeaheadEntries(): void |
|
25
|
|
|
{ |
|
26
|
|
|
AccountFactory::new()->create(['username' => 'Cyber']); |
|
27
|
|
|
AccountFactory::new()->create(['username' => '_Cyb3r']); |
|
28
|
|
|
|
|
29
|
|
|
$this->get('/api/v1/typeahead/Cy'); |
|
30
|
|
|
self::assertJson($this->response->content()); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testShouldReturnUserDataUsingUuid(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->get('/api/v1/user/d59dcabb30424b978f7201d1a076637f'); |
|
36
|
|
|
$responseContent = $this->response->content(); |
|
37
|
|
|
$decodedData = json_decode($responseContent, true); |
|
38
|
|
|
self::assertJson($responseContent); |
|
39
|
|
|
self::assertArrayHasKey('ok', $decodedData); |
|
40
|
|
|
self::assertArrayHasKey('data', $decodedData); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testShouldNotReturnUserDataUsingInvalidUuid(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->get('/api/v1/user/d59dcabb30424b978f7201ffffffffff'); |
|
46
|
|
|
$responseContent = $this->response->content(); |
|
47
|
|
|
$decodedData = json_decode($responseContent, true); |
|
48
|
|
|
$this->assertResponseStatus(404); |
|
49
|
|
|
self::assertJson($responseContent); |
|
50
|
|
|
self::assertArrayHasKey('ok', $decodedData); |
|
51
|
|
|
self::assertArrayHasKey('message', $decodedData); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testShouldReturnUserDataUsingUsername(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$this->get('/api/v1/user/_Cyb3r'); |
|
57
|
|
|
$responseContent = $this->response->content(); |
|
58
|
|
|
$decodedData = json_decode($responseContent, true); |
|
59
|
|
|
self::assertJson($responseContent); |
|
60
|
|
|
self::assertArrayHasKey('ok', $decodedData); |
|
61
|
|
|
self::assertArrayHasKey('data', $decodedData); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testShouldReturnMostWantedUser(): void |
|
65
|
|
|
{ |
|
66
|
|
|
$this->get('/api/v1/stats/user/most-wanted'); |
|
67
|
|
|
$responseContent = $this->response->content(); |
|
68
|
|
|
$decodedData = json_decode($responseContent, true); |
|
69
|
|
|
self::assertJson($responseContent); |
|
70
|
|
|
self::assertArrayHasKey('ok', $decodedData); |
|
71
|
|
|
self::assertArrayHasKey('data', $decodedData); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|