Completed
Push — master ( 44b3f2...31d5aa )
by Beñat
15s
created

ProjectResolverTest::projectByIdResolver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 49
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 9.2258
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
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\Project;
16
17
use Lakion\ApiTestCase\JsonApiTestCase;
18
19
class ProjectResolverTest extends JsonApiTestCase
20
{
21
    public function testNonExistProjectByIdResolver() : void
22
    {
23
        $this->projectByIdResolver('access-token-1', 'non-exist-project-id', '/nonexistent_project_by_id');
24
    }
25
26
    public function testProjectByIdResolver() : void
27
    {
28
        $this->projectByIdResolver('access-token-1', '0dadad5e-1220-11e7-93ae-92361f002671', '/project');
29
    }
30
31
    public function testNonExistProjectBySlugResolver() : void
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() : void
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() : void
48
    {
49
        $this->projectByIdResolver(
50
            'access-token-2',
51
            '0dadad5e-1220-11e7-93ae-92361f002671',
52
            '/project_with_other_user'
53
        );
54
    }
55
56
    private function projectByIdResolver(string $token, string $id, string $jsonResult) : void
57
    {
58
        $this->projectResolver($token, $jsonResult, [
59
            'query'       => <<<EOF
60
query ProjectQueryRequest(\$id: ID!, \$first: Int) {
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
    tasks(first: \$first) {
77
      totalCount
78
      edges {
79
        node {
80
          id,
81
          title,
82
          description,
83
          numeric_id,
84
          progress,
85
          priority,
86
          assignee {
87
            id
88
          },
89
          creator {
90
            id
91
          }
92
        }
93
      },
94
      pageInfo {
95
        endCursor,
96
        hasNextPage
97
      }
98
    }
99
  }
100
}
101
EOF
102
            , 'variables' => ['id' => $id, 'first' => 10],
103
        ]);
104
    }
105
106
    private function projectByInputResolver(string $token, array $projectInput, string $jsonResult) : void
107
    {
108
        $this->projectResolver($token, $jsonResult, [
109
            'query'       => <<<EOF
110
query ProjectQueryRequest(\$projectInput: ProjectInput!) {
111
  project(projectInput: \$projectInput) {
112
    id,
113
    name,
114
    slug,
115
    organization {
116
      id,
117
      name,
118
      slug,
119
      owners {
120
        id
121
      },
122
      organization_members {
123
        id
124
      }
125
    }
126
  }
127
}
128
EOF
129
            , 'variables' => ['projectInput' => $projectInput],
130
        ]);
131
    }
132
133
    private function projectResolver(string $token, string $jsonResult, array $query) : void
134
    {
135
        $this->client->request('POST', '/?access_token=' . $token, $query);
136
        $response = $this->client->getResponse();
137
        $this->assertResponse($response, 'graphql/query/project' . $jsonResult);
138
    }
139
}
140