Passed
Push — refactor_render ( 1be99d...7e011e )
by Mattia
09:18
created

JsonControllerTest::shouldReturnMostWantedUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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