Completed
Pull Request — master (#9)
by Hugo
01:44
created

GraphQLClientSpec::it_should_send_graphql_query()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace spec\Yproximite\Api\Client;
4
5
use GuzzleHttp\Psr7\MultipartStream;
6
use Http\Client\HttpClient;
7
use Http\Message\MessageFactory;
8
use PhpSpec\ObjectBehavior;
9
use Prophecy\Argument;
10
use Psr\Http\Message\RequestInterface;
11
use Psr\Http\Message\ResponseInterface;
12
use Psr\Http\Message\StreamInterface;
13
use Yproximite\Api\Client\AuthClient;
14
use Yproximite\Api\Client\GraphQLClient;
15
use Yproximite\Api\Exception\UploadEmptyFilesException;
16
17
class GraphQLClientSpec extends ObjectBehavior
18
{
19
    const GRAPHQL_ENDPOINT = 'https://graphql.yproximite.fr';
20
21
    public function it_is_initializable()
22
    {
23
        $this->shouldHaveType(GraphQLClient::class);
24
    }
25
26
    public function let(HttpClient $httpClient, AuthClient $authClient, MessageFactory $messageFactory)
27
    {
28
        $this->beConstructedWith($authClient, self::GRAPHQL_ENDPOINT, $httpClient, $messageFactory);
29
    }
30
31
    public function it_should_send_auth_request_before_graphql_request()
32
    {
33
    }
34
35
    public function it_should_handle_case_where_api_token_is_invalid()
36
    {
37
    }
38
39
    public function it_should_handle_case_auth_response_returns_401()
40
    {
41
    }
42
43
    public function it_should_handle_case_auth_response_is_invalid_json()
44
    {
45
    }
46
47
    public function it_should_send_graphql_query()
48
    {
49
    }
50
51
    public function it_should_handle_case_when_graphql_query_returns_errors()
52
    {
53
    }
54
55
    public function it_should_handle_case_when_graphql_query_returns_warnings()
56
    {
57
    }
58
59
    public function it_should_send_graphql_mutation()
60
    {
61
    }
62
63
    public function it_should_handle_case_when_mutation_query_returns_errors()
64
    {
65
    }
66
67
    public function it_should_handle_case_when_mutation_query_returns_warnings()
68
    {
69
    }
70
71
    public function it_should_upload_files(
72
        HttpClient $httpClient,
73
        MessageFactory $messageFactory,
74
        RequestInterface $request,
75
        ResponseInterface $response,
76
        StreamInterface $stream,
77
        AuthClient $authClient
78
    ) {
79
        $authClient->getApiToken()->willReturn('<api token>')->shouldBeCalled();
80
        $authClient->isAuthenticated()->willReturn(true)->shouldBeCalled();
81
        $authClient->auth()->shouldBeCalled();
82
83
        $messageFactory->createRequest('POST', self::GRAPHQL_ENDPOINT, Argument::type('array'), Argument::type(MultipartStream::class))->willReturn($request);
84
        $httpClient->sendRequest($request)->willReturn($response);
85
        $response->getStatusCode()->willReturn(200);
86
        $response->getBody()->willReturn($stream);
87
        $stream->__toString()->willReturn(json_encode([
88
            'data' => [
89
                'uploadMedias' => [
90
                    ['id' => 1, 'name' => 'Logo Yprox-1.png', 'fullpathFilename' => 'https://example.com/media/original/Logo Yprox-1.png'],
91
                    ['id' => 2, 'name' => 'GraphQL-2.png', 'fullpathFilename' => 'https://example.com/media/original/GraphQL-2.png'],
92
                ],
93
            ],
94
        ]));
95
96
        $response = $this->upload(123, [
97
            ['path' => __DIR__.'/../fixtures/Yproximite.png', 'name' => 'Logo Yprox.png'],
98
            __DIR__.'/../fixtures/GraphQL.png',
99
        ]);
100
101
        $response->hasErrors()->shouldBe(false);
102
        $response->hasWarnings()->shouldBe(false);
103
        $response->getData()->shouldBeLike((object) [
104
            'uploadMedias' => [
105
                ['id' => 1, 'name' => 'Logo Yprox-1.png', 'fullpathFilename' => 'https://example.com/media/original/Logo Yprox-1.png'],
106
                ['id' => 2, 'name' => 'GraphQL-2.png', 'fullpathFilename' => 'https://example.com/media/original/GraphQL-2.png'],
107
            ],
108
        ]);
109
    }
110
111
    public function it_should_handle_case_when_uploading_empty_files()
112
    {
113
        $this->shouldThrow(UploadEmptyFilesException::class)->during('upload', [123]);
114
    }
115
116
    public function it_should_handle_case_when_uploading_is_failing()
117
    {
118
    }
119
}
120