Skip to content

Commit 1e1938b

Browse files
committed
Added DiscountCode::isValid endpoint
1 parent 1bca4cd commit 1e1938b

4 files changed

Lines changed: 169 additions & 59 deletions

File tree

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
- restore_cache:
1313
keys:
1414
- v1-dependencies-{{ checksum "composer.json" }}
15-
- v1-dependencies-
1615

1716
- run: composer install -n --prefer-dist
1817

src/Fapi/FapiClient/EndPoints/DiscountCodes.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,14 @@ public function __construct(FapiRestClient $client)
2626
$this->resources = 'discount_codes';
2727
}
2828

29+
/**
30+
* @param string $code
31+
* @param string $path
32+
* @return mixed[]
33+
*/
34+
public function isValid(string $code, string $path): array
35+
{
36+
return $this->client->getSingularResource($this->path . '/is-valid', ['code' => $code, 'form' => $path]);
37+
}
38+
2939
}

tests/Fapi/FapiClientTests/FapiClientDiscountCodesTest.phpt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class FapiClientDiscountCodesTest extends TestCase
3232
);
3333

3434
$this->fapiClient = new FapiClient(
35-
'test1@slischka.cz',
36-
'pi120wrOyzNlb7p4iQwTO1vcK',
35+
'slischkaj-2019-11-26@gmail.com',
36+
'nWHypJS0XJZB6e3dWlPOULmQ4',
3737
'https://api.fapi.cz/',
3838
$this->httpClient
3939
);
@@ -82,6 +82,11 @@ class FapiClientDiscountCodesTest extends TestCase
8282
Assert::type('int', $discountCode['id']);
8383
Assert::type('array', $discountCode);
8484

85+
//is valid - invalid form path
86+
$isValid = $this->fapiClient->getDiscountCodes()->isValid($discountCode['code'], 'form-path');
87+
Assert::false($isValid['applicable']);
88+
Assert::type('array', $isValid);
89+
8590
//list
8691
$discountCodes = $this->fapiClient->getDiscountCodes()->findAll();
8792
Assert::type('int', $discountCodes[0]['id']);

tests/Fapi/FapiClientTests/MockHttpClients/FapiClientDiscountCodesMockHttpClient.php

Lines changed: 152 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,86 +20,160 @@ public function __construct()
2020
'Host' => ['api.fapi.cz'],
2121
'Content-Type' => ['application/json'],
2222
'Accept' => ['application/json'],
23-
'Authorization' => ['Basic dGVzdDFAc2xpc2Noa2EuY3o6cGkxMjB3ck95ek5sYjdwNGlRd1RPMXZjSw=='],
23+
'Authorization' => [
24+
'Basic c2xpc2Noa2FqLTIwMTktMTEtMjZAZ21haWwuY29tOm5XSHlwSlMwWEpaQjZlM2RXbFBPVUxtUTQ=',
25+
],
2426
]
2527
),
2628
new HttpResponse(
2729
201,
2830
[
29-
'Date' => ['Sat, 17 Nov 2018 10:11:28 GMT'],
31+
'Date' => ['Thu, 26 Mar 2020 07:16:39 GMT'],
3032
'Content-Type' => ['application/json'],
31-
'Transfer-Encoding' => ['chunked'],
33+
'Content-Length' => ['197'],
3234
'Connection' => ['keep-alive'],
33-
'Set-Cookie' => [
34-
'AWSALB=2YX+Xph4FlRTWPhRAVa8tT9yZqtfOpnq11tNoayafy3mGCwgkTc6An8e1D1z54Zrx8iMkZm1vqC7j2VLra9qr8fymwMbfyGPrLBmAQlJN0E8tSP5NldEh817gbTY; Expires=Sat, 24 Nov 2018 10:11:28 GMT; Path=/',
35-
],
36-
'Server' => ['nginx/1.14.0'],
35+
'Server' => ['nginx/1.16.1'],
3736
'X-Powered-By' => ['Nette Framework'],
38-
'X-Origin-Instance' => ['prd-fapi-web5'],
39-
'X-Content-Type-Options' => ['nosniff'],
40-
'X-Frame-Options' => ['sameorigin'],
37+
'X-NewRelic-App-Data' => [
38+
'PxQOV1BaCxACVldQAQEBREgTYVYAMhEDXhFZAUxRW1xvSngCRQhcDDgZVhEPPxdFAThOBl5CVAkRX0IeAQkHB0NAFFIWCAQCA1UVUR9RAFJcAxtQX1QUEQhcUVUHVA4DVQMCUAMEUAYSTl4DVEtRbw==',
39+
],
40+
'Strict-Transport-Security' => [
41+
'max-age=63072000; includeSubDomains; preload',
42+
'max-age=63072000; includeSubDomains; preload',
43+
],
44+
'X-Content-Type-Options' => ['nosniff', 'nosniff'],
45+
'X-Frame-Options' => ['sameorigin', 'sameorigin'],
46+
'X-Origin-Instance' => ['web3.prod.fapi.cloud', 'web1.prod.fapi.cloud'],
47+
'Access-Control-Allow-Origin' => ['*', '*'],
48+
'Access-Control-Allow-Headers' => [
49+
'Origin, X-Requested-With, Content-Type, Accept',
50+
'Origin, X-Requested-With, Content-Type, Accept',
51+
],
4152
],
42-
'{"id":2645,"name":"test","code":"unique","type":"percent","validity_type":"always","percent_discount":5}'
53+
'{"id":7148,"user_id":11812,"name":"test","code":"unique","type":"percent","validity_type":"always","begin_date":null,"end_date":null,"percent_discount":5,"maximum_use":null,"discount_amounts":null}'
4354
)
4455
);
4556
$this->add(
4657
new HttpRequest(
4758
'PUT',
48-
'https://api.fapi.cz/discount-codes/2645',
59+
'https://api.fapi.cz/discount-codes/7148',
4960
[
5061
'Host' => ['api.fapi.cz'],
5162
'Content-Type' => ['application/json'],
5263
'Accept' => ['application/json'],
53-
'Authorization' => ['Basic dGVzdDFAc2xpc2Noa2EuY3o6cGkxMjB3ck95ek5sYjdwNGlRd1RPMXZjSw=='],
64+
'Authorization' => [
65+
'Basic c2xpc2Noa2FqLTIwMTktMTEtMjZAZ21haWwuY29tOm5XSHlwSlMwWEpaQjZlM2RXbFBPVUxtUTQ=',
66+
],
5467
]
5568
),
5669
new HttpResponse(
5770
200,
5871
[
59-
'Date' => ['Sat, 17 Nov 2018 10:11:28 GMT'],
72+
'Date' => ['Thu, 26 Mar 2020 07:16:39 GMT'],
6073
'Content-Type' => ['application/json'],
61-
'Transfer-Encoding' => ['chunked'],
74+
'Content-Length' => ['214'],
6275
'Connection' => ['keep-alive'],
63-
'Set-Cookie' => [
64-
'AWSALB=6kg8TDcIycHJ1hHEXQ9tAhWAz0+Dz8arff0qmK0YBsylQSL+K41Gyja1JZsr3H5AItuqhh/CW6L5GmpudayFrZauobzJNoxDpJZ63Qz13R3SFJSfVB6XhefBRgGV; Expires=Sat, 24 Nov 2018 10:11:28 GMT; Path=/',
65-
],
66-
'Server' => ['nginx/1.14.0'],
76+
'Server' => ['nginx/1.16.1'],
6777
'X-Powered-By' => ['Nette Framework'],
68-
'X-Origin-Instance' => ['prd-fapi-web2'],
69-
'X-Content-Type-Options' => ['nosniff'],
70-
'X-Frame-Options' => ['sameorigin'],
78+
'X-NewRelic-App-Data' => [
79+
'PxQOV1BaCxACVldQAQEBREgTYVYAMhEDXhFZAUxRW1xvSngCRQhcDDgZVhEPPxdFAThOBl5CVAkRX0IeAQkHB0M+FxlRXA5pAkgAPGpRHls5HEpDSlMWAwBUUVIbARlWVwQOAE5UUlYcQApXAAAGAARXC1kEWFFWBQ4VTQACVEBVOQ==',
80+
],
81+
'Strict-Transport-Security' => [
82+
'max-age=63072000; includeSubDomains; preload',
83+
'max-age=63072000; includeSubDomains; preload',
84+
],
85+
'X-Content-Type-Options' => ['nosniff', 'nosniff'],
86+
'X-Frame-Options' => ['sameorigin', 'sameorigin'],
87+
'X-Origin-Instance' => ['web3.prod.fapi.cloud', 'web1.prod.fapi.cloud'],
88+
'Access-Control-Allow-Origin' => ['*', '*'],
89+
'Access-Control-Allow-Headers' => [
90+
'Origin, X-Requested-With, Content-Type, Accept',
91+
'Origin, X-Requested-With, Content-Type, Accept',
92+
],
7193
],
72-
'{"id":2645,"name":"new name","code":"newUniqCode","type":"percent","validity_type":"range","percent_discount":10,"begin_date":"2017-01-01","end_date":null}'
94+
'{"id":7148,"user_id":11812,"name":"new name","code":"newUniqCode","type":"percent","validity_type":"range","begin_date":"2017-01-01","end_date":null,"percent_discount":10,"maximum_use":null,"discount_amounts":null}'
7395
)
7496
);
7597
$this->add(
7698
new HttpRequest(
7799
'GET',
78-
'https://api.fapi.cz/discount-codes/2645',
100+
'https://api.fapi.cz/discount-codes/7148',
79101
[
80102
'Host' => ['api.fapi.cz'],
81103
'Content-Type' => ['application/json'],
82104
'Accept' => ['application/json'],
83-
'Authorization' => ['Basic dGVzdDFAc2xpc2Noa2EuY3o6cGkxMjB3ck95ek5sYjdwNGlRd1RPMXZjSw=='],
105+
'Authorization' => [
106+
'Basic c2xpc2Noa2FqLTIwMTktMTEtMjZAZ21haWwuY29tOm5XSHlwSlMwWEpaQjZlM2RXbFBPVUxtUTQ=',
107+
],
84108
]
85109
),
86110
new HttpResponse(
87111
200,
88112
[
89-
'Date' => ['Sat, 17 Nov 2018 10:11:28 GMT'],
113+
'Date' => ['Thu, 26 Mar 2020 07:16:39 GMT'],
90114
'Content-Type' => ['application/json'],
91-
'Transfer-Encoding' => ['chunked'],
115+
'Content-Length' => ['214'],
92116
'Connection' => ['keep-alive'],
93-
'Set-Cookie' => [
94-
'AWSALB=tgo0A1BdaWYC1gtdZqIjKxsOk+dqNJGLRfLdzO8/R2R1xuYkSDnEEUmZ0VY1It7pY7vNxPwuimo83tVGmqJTVl4FQzhfG5wkkSFhxBJb0f+OaYOy/SI4WIGxp+O/; Expires=Sat, 24 Nov 2018 10:11:28 GMT; Path=/',
117+
'Server' => ['nginx/1.16.1'],
118+
'X-Powered-By' => ['Nette Framework'],
119+
'X-NewRelic-App-Data' => [
120+
'PxQOV1BaCxACVldQAQEBREgTYVYAMhEDXhFZAUxRW1xvSngCRQhcDDgZVhEPPxdFAThOBl5CVAkRX0IeAQkHB0M+FxlRXA5pAkgAPGpRHls5HEpDSlMWAwBUUVIbARlWVgYABk5UUlYcQFxSXQECBwVSC1kHWQMAUwAVTQACVEBVOQ==',
95121
],
96-
'Server' => ['nginx/1.14.0'],
122+
'Strict-Transport-Security' => [
123+
'max-age=63072000; includeSubDomains; preload',
124+
'max-age=63072000; includeSubDomains; preload',
125+
],
126+
'X-Content-Type-Options' => ['nosniff', 'nosniff'],
127+
'X-Frame-Options' => ['sameorigin', 'sameorigin'],
128+
'X-Origin-Instance' => ['web3.prod.fapi.cloud', 'web1.prod.fapi.cloud'],
129+
'Access-Control-Allow-Origin' => ['*', '*'],
130+
'Access-Control-Allow-Headers' => [
131+
'Origin, X-Requested-With, Content-Type, Accept',
132+
'Origin, X-Requested-With, Content-Type, Accept',
133+
],
134+
],
135+
'{"id":7148,"user_id":11812,"name":"new name","code":"newUniqCode","type":"percent","validity_type":"range","begin_date":"2017-01-01","end_date":null,"percent_discount":10,"maximum_use":null,"discount_amounts":null}'
136+
)
137+
);
138+
$this->add(
139+
new HttpRequest(
140+
'GET',
141+
'https://api.fapi.cz/discount-codes/is-valid?code=newUniqCode&form=form-path',
142+
[
143+
'Host' => ['api.fapi.cz'],
144+
'Content-Type' => ['application/json'],
145+
'Accept' => ['application/json'],
146+
'Authorization' => [
147+
'Basic c2xpc2Noa2FqLTIwMTktMTEtMjZAZ21haWwuY29tOm5XSHlwSlMwWEpaQjZlM2RXbFBPVUxtUTQ=',
148+
],
149+
]
150+
),
151+
new HttpResponse(
152+
200,
153+
[
154+
'Date' => ['Thu, 26 Mar 2020 07:16:39 GMT'],
155+
'Content-Type' => ['application/json'],
156+
'Content-Length' => ['20'],
157+
'Connection' => ['keep-alive'],
158+
'Server' => ['nginx/1.16.1'],
97159
'X-Powered-By' => ['Nette Framework'],
98-
'X-Origin-Instance' => ['prd-fapi-web5'],
99-
'X-Content-Type-Options' => ['nosniff'],
100-
'X-Frame-Options' => ['sameorigin'],
160+
'X-NewRelic-App-Data' => [
161+
'PxQOV1BaCxACVldQAQEBREgTYVYAMhEDXhFZAUxRW1xvSngCRQhcDDgZVhEPPxdFAThOBl5CVAkRX0IeAQkHB0M+FwtLFUJTXwxdQx1RHVJUBgdRSlMWAwJSVVMbAwdKRgUGAVFXW1MAB1tRWgANAVBHFQdQDUAHOQ==',
162+
],
163+
'Strict-Transport-Security' => [
164+
'max-age=63072000; includeSubDomains; preload',
165+
'max-age=63072000; includeSubDomains; preload',
166+
],
167+
'X-Content-Type-Options' => ['nosniff', 'nosniff'],
168+
'X-Frame-Options' => ['sameorigin', 'sameorigin'],
169+
'X-Origin-Instance' => ['web3.prod.fapi.cloud', 'web1.prod.fapi.cloud'],
170+
'Access-Control-Allow-Origin' => ['*', '*'],
171+
'Access-Control-Allow-Headers' => [
172+
'Origin, X-Requested-With, Content-Type, Accept',
173+
'Origin, X-Requested-With, Content-Type, Accept',
174+
],
101175
],
102-
'{"id":2645,"name":"new name","code":"newUniqCode","type":"percent","validity_type":"range","percent_discount":10,"begin_date":"2017-01-01","end_date":null,"used_count":0}'
176+
'{"applicable":false}'
103177
)
104178
);
105179
$this->add(
@@ -110,54 +184,76 @@ public function __construct()
110184
'Host' => ['api.fapi.cz'],
111185
'Content-Type' => ['application/json'],
112186
'Accept' => ['application/json'],
113-
'Authorization' => ['Basic dGVzdDFAc2xpc2Noa2EuY3o6cGkxMjB3ck95ek5sYjdwNGlRd1RPMXZjSw=='],
187+
'Authorization' => [
188+
'Basic c2xpc2Noa2FqLTIwMTktMTEtMjZAZ21haWwuY29tOm5XSHlwSlMwWEpaQjZlM2RXbFBPVUxtUTQ=',
189+
],
114190
]
115191
),
116192
new HttpResponse(
117193
200,
118194
[
119-
'Date' => ['Sat, 17 Nov 2018 10:11:28 GMT'],
195+
'Date' => ['Thu, 26 Mar 2020 07:16:39 GMT'],
120196
'Content-Type' => ['application/json'],
121-
'Transfer-Encoding' => ['chunked'],
197+
'Content-Length' => ['235'],
122198
'Connection' => ['keep-alive'],
123-
'Set-Cookie' => [
124-
'AWSALB=ndqyNPdrEx3ZswrIIIUDqKJKMH0OMV5CRHRw+yd9sPSaAvXgKkocFyBSfv7zxdNiDFtTzZ42Xb/mMTquCd2fowEisD7NM8WuRnuV9cHfjmt4KGBy8JEr+TioVTHx; Expires=Sat, 24 Nov 2018 10:11:28 GMT; Path=/',
125-
],
126-
'Server' => ['nginx/1.14.0'],
199+
'Server' => ['nginx/1.16.1'],
127200
'X-Powered-By' => ['Nette Framework'],
128-
'X-Origin-Instance' => ['prd-fapi-web2'],
129-
'X-Content-Type-Options' => ['nosniff'],
130-
'X-Frame-Options' => ['sameorigin'],
201+
'X-NewRelic-App-Data' => [
202+
'PxQOV1BaCxACVldQAQEBREgTYVYAMhEDXhFZAUxRW1xvSngCRQhcDDgZVhEPPxdFAThOBl5CVAkRX0IeAQkHB0NAFFIWCAQCA1UVUR9RAVFTAxtTVVYUEQEGV1YCVA4FXVJUAVQFAVYSTl4DVEtRbw==',
203+
],
204+
'Strict-Transport-Security' => [
205+
'max-age=63072000; includeSubDomains; preload',
206+
'max-age=63072000; includeSubDomains; preload',
207+
],
208+
'X-Content-Type-Options' => ['nosniff', 'nosniff'],
209+
'X-Frame-Options' => ['sameorigin', 'sameorigin'],
210+
'X-Origin-Instance' => ['web1.prod.fapi.cloud', 'web1.prod.fapi.cloud'],
211+
'Access-Control-Allow-Origin' => ['*', '*'],
212+
'Access-Control-Allow-Headers' => [
213+
'Origin, X-Requested-With, Content-Type, Accept',
214+
'Origin, X-Requested-With, Content-Type, Accept',
215+
],
131216
],
132-
'{"discount_codes":[{"id":2645,"name":"new name","code":"newUniqCode","type":"percent","validity_type":"range","percent_discount":10,"begin_date":"2017-01-01","end_date":null,"used_count":0}]}'
217+
'{"discount_codes":[{"id":7148,"user_id":11812,"name":"new name","code":"newUniqCode","type":"percent","validity_type":"range","begin_date":"2017-01-01","end_date":null,"percent_discount":10,"maximum_use":null,"discount_amounts":null}]}'
133218
)
134219
);
135220
$this->add(
136221
new HttpRequest(
137222
'DELETE',
138-
'https://api.fapi.cz/discount-codes/2645',
223+
'https://api.fapi.cz/discount-codes/7148',
139224
[
140225
'Host' => ['api.fapi.cz'],
141226
'Content-Type' => ['application/json'],
142227
'Accept' => ['application/json'],
143-
'Authorization' => ['Basic dGVzdDFAc2xpc2Noa2EuY3o6cGkxMjB3ck95ek5sYjdwNGlRd1RPMXZjSw=='],
228+
'Authorization' => [
229+
'Basic c2xpc2Noa2FqLTIwMTktMTEtMjZAZ21haWwuY29tOm5XSHlwSlMwWEpaQjZlM2RXbFBPVUxtUTQ=',
230+
],
144231
]
145232
),
146233
new HttpResponse(
147234
200,
148235
[
149-
'Date' => ['Sat, 17 Nov 2018 10:11:28 GMT'],
236+
'Date' => ['Thu, 26 Mar 2020 07:16:39 GMT'],
150237
'Content-Type' => ['application/json'],
151-
'Transfer-Encoding' => ['chunked'],
238+
'Content-Length' => ['20'],
152239
'Connection' => ['keep-alive'],
153-
'Set-Cookie' => [
154-
'AWSALB=cpu7kpe3tQIqRN4cpMyv6YrSJoVGwdKAO9v+hbMPjBPKF0D+HSDKp1apdbW0I8H36NgoFWLwMjnz8ZuGyG+bID8xy5SsardKNuk0XfsgBMj3OCdP8aHEVBMrE82K; Expires=Sat, 24 Nov 2018 10:11:28 GMT; Path=/',
155-
],
156-
'Server' => ['nginx/1.14.0'],
240+
'Server' => ['nginx/1.16.1'],
157241
'X-Powered-By' => ['Nette Framework'],
158-
'X-Origin-Instance' => ['prd-fapi-web5'],
159-
'X-Content-Type-Options' => ['nosniff'],
160-
'X-Frame-Options' => ['sameorigin'],
242+
'X-NewRelic-App-Data' => [
243+
'PxQOV1BaCxACVldQAQEBREgTYVYAMhEDXhFZAUxRW1xvSngCRQhcDDgZVhEPPxdFAThOBl5CVAkRX0IeAQkHB0M+FxlRXA5pAkgAPGpRHls5HEpDSlMWAwBUUVIbARlWVwIGBE5UU04SVFsHXAsCUQFVClIDUApQBRQbBwcPS1Zt',
244+
],
245+
'Strict-Transport-Security' => [
246+
'max-age=63072000; includeSubDomains; preload',
247+
'max-age=63072000; includeSubDomains; preload',
248+
],
249+
'X-Content-Type-Options' => ['nosniff', 'nosniff'],
250+
'X-Frame-Options' => ['sameorigin', 'sameorigin'],
251+
'X-Origin-Instance' => ['web1.prod.fapi.cloud', 'web3.prod.fapi.cloud'],
252+
'Access-Control-Allow-Origin' => ['*', '*'],
253+
'Access-Control-Allow-Headers' => [
254+
'Origin, X-Requested-With, Content-Type, Accept',
255+
'Origin, X-Requested-With, Content-Type, Accept',
256+
],
161257
],
162258
'{"status":"success"}'
163259
)

0 commit comments

Comments
 (0)