1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Yproximite\Api\Client; |
4
|
|
|
|
5
|
|
|
use Http\Client\HttpClient; |
6
|
|
|
use Http\Message\MessageFactory; |
7
|
|
|
use PhpSpec\ObjectBehavior; |
8
|
|
|
use Yproximite\Api\Client\AuthClient; |
9
|
|
|
use Yproximite\Api\Client\GraphQLClient; |
10
|
|
|
use Yproximite\Api\Exception\UploadEmptyFilesException; |
11
|
|
|
use Yproximite\Api\Response; |
12
|
|
|
|
13
|
|
|
class GraphQLClientSpec extends ObjectBehavior |
14
|
|
|
{ |
15
|
|
|
const GRAPHQL_ENDPOINT = 'https://graphql.yproximite.fr'; |
16
|
|
|
|
17
|
|
|
public function it_is_initializable() |
18
|
|
|
{ |
19
|
|
|
$this->shouldHaveType(GraphQLClient::class); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function let(HttpClient $httpClient, AuthClient $authClient, MessageFactory $messageFactory) |
23
|
|
|
{ |
24
|
|
|
$authClient->getApiToken()->willReturn('<api token>'); |
25
|
|
|
$authClient->isAuthenticated()->willReturn(true); |
26
|
|
|
|
27
|
|
|
$this->beConstructedWith($authClient, self::GRAPHQL_ENDPOINT, $httpClient, $messageFactory); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function it_should_send_auth_request_before_graphql_request() |
31
|
|
|
{ |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function it_should_handle_case_where_api_token_is_invalid() |
35
|
|
|
{ |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function it_should_handle_case_auth_response_returns_401() |
39
|
|
|
{ |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function it_should_handle_case_auth_response_is_invalid_json() |
43
|
|
|
{ |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function it_should_send_graphql_query() |
47
|
|
|
{ |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function it_should_handle_case_when_graphql_query_returns_errors() |
51
|
|
|
{ |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function it_should_handle_case_when_graphql_query_returns_warnings() |
55
|
|
|
{ |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function it_should_send_graphql_mutation() |
59
|
|
|
{ |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function it_should_handle_case_when_mutation_query_returns_errors() |
63
|
|
|
{ |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function it_should_handle_case_when_mutation_query_returns_warnings() |
67
|
|
|
{ |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function it_should_upload_files() |
71
|
|
|
{ |
72
|
|
|
$responseData = [ |
73
|
|
|
[ |
74
|
|
|
'id' => 1, |
75
|
|
|
'name' => 'Logo Yprox-1.png', |
76
|
|
|
'fullpathFilename' => 'https://example.com/media/original/Logo Yprox-1.png', |
77
|
|
|
], |
78
|
|
|
[ |
79
|
|
|
'id' => 2, |
80
|
|
|
'name' => 'GraphQL-2.png', |
81
|
|
|
'fullpathFilename' => 'https://example.com/media/original/GraphQL-2.png', |
82
|
|
|
], |
83
|
|
|
]; |
84
|
|
|
|
85
|
|
|
$response = new Response(['data' => $responseData]); |
86
|
|
|
|
87
|
|
|
$this->upload(123, [ |
88
|
|
|
['path' => __DIR__.'/../fixtures/Yproximite.png', 'name' => 'Logo Yprox.png'], |
89
|
|
|
__DIR__.'/../fixtures/GraphQL.png', |
90
|
|
|
])->shouldReturn($response); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function it_should_handle_case_when_uploading_empty_files() |
94
|
|
|
{ |
95
|
|
|
$this->shouldThrow(UploadEmptyFilesException::class)->during('upload', [123]); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function it_should_handle_case_when_uploading_is_failing() |
99
|
|
|
{ |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|