Completed
Push — master ( 979dd4...351c6b )
by Beñat
18s
created

ProjectResolverTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 98
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testNonExistProjectByIdResolver() 0 4 1
A testProjectByIdResolver() 0 4 1
A testNonExistProjectBySlugResolver() 0 7 1
A testProjectBySlugResolver() 0 7 1
A testProjectWithOtherUserResolver() 0 8 1
B projectByIdResolver() 0 26 1
B projectByInputResolver() 0 26 1
A projectResolver() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\TaskManager\Tests\Integration\GraphQl\Query\Projects;
16
17
use Lakion\ApiTestCase\JsonApiTestCase;
18
19
class ProjectResolverTest extends JsonApiTestCase
20
{
21
    public function testNonExistProjectByIdResolver()
22
    {
23
        $this->projectByIdResolver('access-token-1', 'non-exist-project-id', '/nonexistent_project_by_id');
24
    }
25
26
    public function testProjectByIdResolver()
27
    {
28
        $this->projectByIdResolver('access-token-1', '0dada084-1220-11e7-93ae-92361f002671', '/project');
29
    }
30
31
    public function testNonExistProjectBySlugResolver()
32
    {
33
        $this->projectByInputResolver('access-token-1', [
34
            'slug'             => 'non-exist-project-slug',
35
            'organizationSlug' => 'organization-0',
36
        ], '/nonexistent_project_by_slug');
37
    }
38
39
    public function testProjectBySlugResolver()
40
    {
41
        $this->projectByInputResolver('access-token-1', [
42
            'slug'             => 'project-1',
43
            'organizationSlug' => 'organization-0',
44
        ], '/project_by_slug');
45
    }
46
47
    public function testProjectWithOtherUserResolver()
48
    {
49
        $this->projectByIdResolver(
50
            'access-token-2',
51
            '0dada5ca-1220-11e7-93ae-92361f002671',
52
            '/project_with_other_user'
53
        );
54
    }
55
56
    private function projectByIdResolver($token, $id, $jsonResult)
57
    {
58
        $this->projectResolver($token, $jsonResult, [
59
            'query'       => <<<EOF
60
query ProjectQueryRequest(\$id: ID!) {
61
  project(id: \$id) {
62
    id,
63
    name,
64
    slug,
65
    organization {
66
      id,
67
      name,
68
      slug,
69
      owners {
70
        id
71
      },
72
      organization_members {
73
        id
74
      }
75
    }
76
  }
77
}
78
EOF
79
            , 'variables' => ['id' => $id],
80
        ]);
81
    }
82
83
    private function projectByInputResolver($token, $projectInput, $jsonResult)
84
    {
85
        $this->projectResolver($token, $jsonResult, [
86
            'query'       => <<<EOF
87
query ProjectQueryRequest(\$projectInput: ProjectInput!) {
88
  project(projectInput: \$projectInput) {
89
    id,
90
    name,
91
    slug,
92
    organization {
93
      id,
94
      name,
95
      slug,
96
      owners {
97
        id
98
      },
99
      organization_members {
100
        id
101
      }
102
    }
103
  }
104
}
105
EOF
106
            , 'variables' => ['projectInput' => $projectInput],
107
        ]);
108
    }
109
110
    private function projectResolver(string $token, string $jsonResult, array $query) : void
111
    {
112
        $this->client->request('POST', '/?access_token=' . $token, $query);
113
        $response = $this->client->getResponse();
114
        $this->assertResponse($response, 'graphql/query/project' . $jsonResult);
115
    }
116
}
117