Completed
Push — master ( e94dcc...c29e00 )
by Gorka
12s
created

OrganizationResolverTest::organizationById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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;
16
17
use Lakion\ApiTestCase\JsonApiTestCase;
18
19
class OrganizationResolverTest extends JsonApiTestCase
20
{
21
    public function testNonExistOrganizationByIdResolver()
22
    {
23
        $this->organizationById(
24
            'access-token-1',
25
            'non-exist-organization-id',
26
            '/nonexistent_organization_by_id'
27
        );
28
    }
29
30
    public function testNonExistOrganizationBySlugResolver()
31
    {
32
        $this->organizationBySlug(
33
            'access-token-1',
34
            'non-exist-organization-slug',
35
            '/nonexistent_organization_by_slug'
36
        );
37
    }
38
39
    public function testUnauthorizedOrganizationByIdResolver()
40
    {
41
        $this->organizationById(
42
            'access-token-2',
43
            '71298d2c-0ff4-11e7-93ae-92361f002671',
44
            '/unauthorized_organization_by_id'
45
        );
46
    }
47
48
    public function testUnauthorizedOrganizationBySlugResolver()
49
    {
50
        $this->organizationBySlug(
51
            'access-token-2',
52
            'organization-0',
53
            '/unauthorized_organization_by_slug'
54
        );
55
    }
56
57
    public function testOrganizationByIdResolver()
58
    {
59
        $this->organizationById(
60
            'access-token-1',
61
            '71298d2c-0ff4-11e7-93ae-92361f002671',
62
            '/organization'
63
        );
64
    }
65
66
    public function testOrganizationBySlugResolver()
67
    {
68
        $this->organizationBySlug('access-token-1', 'organization-0', '/organization');
69
    }
70
71
    private function organizationById($token, $id, $jsonResult)
72
    {
73
        return $this->organizationResolver($token, $id, 'id', 'ID!', $jsonResult);
74
    }
75
76
    private function organizationBySlug($token, $slug, $jsonResult)
77
    {
78
        return $this->organizationResolver($token, $slug, 'slug', 'String!', $jsonResult);
79
    }
80
81
    private function organizationResolver($token, $value, $name, $type, $jsonResult)
82
    {
83
        $this->client->request('POST', '/?access_token=' . $token, [
84
            'query'       => <<<EOF
85
query OrganizationQueryRequest(\$$name: $type) {
86
  organization($name: \$$name) {
87
    id,
88
    name,
89
    slug,
90
    organization_members {
91
      id
92
    },
93
    owners {
94
      id
95
    },
96
    _projects4l96UD:projects(first:-1) {
97
      edges {
98
        node {
99
          id,
100
          name,
101
          slug
102
        },
103
        cursor
104
      },
105
      pageInfo {
106
        hasNextPage,
107
        hasPreviousPage
108
      }
109
    }
110
  }
111
}
112
EOF
113
            , 'variables' => [$name => $value],
114
        ]);
115
116
        $response = $this->client->getResponse();
117
118
        $this->assertResponse($response, 'graphql/query/organization' . $jsonResult);
119
    }
120
}
121