1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OnFleet\Tests; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Message\Response; |
6
|
|
|
use GuzzleHttp\Stream\Stream; |
7
|
|
|
use OnFleet\Administrator; |
8
|
|
|
use OnFleet\Client; |
9
|
|
|
use OnFleet\Destination; |
10
|
|
|
use OnFleet\Hub; |
11
|
|
|
use OnFleet\Organization; |
12
|
|
|
use OnFleet\Recipient; |
13
|
|
|
use OnFleet\Task; |
14
|
|
|
use OnFleet\Team; |
15
|
|
|
use OnFleet\Webhook; |
16
|
|
|
use OnFleet\Worker; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class ClientTest |
20
|
|
|
* @package OnFleet\Tests |
21
|
|
|
* @covers OnFleet\Client |
22
|
|
|
*/ |
23
|
|
|
class ClientTest extends ApiTestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @covers OnFleet\Client::getMyOrganization |
27
|
|
|
* @covers OnFleet\Organization |
28
|
|
|
*/ |
29
|
|
|
public function testGettingMyOrganizationReturnsOrganization() |
30
|
|
|
{ |
31
|
|
|
// Arrange |
32
|
|
|
$this->mockedResponses->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
33
|
|
|
{ |
34
|
|
|
"id": "yAM*fDkztrT3gUcz9mNDgNOL", |
35
|
|
|
"timeCreated": 1454634415000, |
36
|
|
|
"timeLastModified": 1455048510514, |
37
|
|
|
"name": "Onfleet Fine Eateries", |
38
|
|
|
"email": "[email protected]", |
39
|
|
|
"image": "5cc28fc91d7bc5846c6ce9c1", |
40
|
|
|
"timezone": "America/Los_Angeles", |
41
|
|
|
"country": "US", |
42
|
|
|
"delegatees": [ |
43
|
|
|
"cBrUjKvQQgdRp~s1qvQNLpK*" |
44
|
|
|
] |
45
|
|
|
}'))); |
46
|
|
|
|
47
|
|
|
// Act |
48
|
|
|
$organization = $this->client->getMyOrganization(); |
49
|
|
|
|
50
|
|
|
// Assert |
51
|
|
|
$this->assertRequestIsGet('organization'); |
52
|
|
|
|
53
|
|
|
$this->assertInstanceOf(Organization::class, $organization); |
54
|
|
|
$this->assertEquals('yAM*fDkztrT3gUcz9mNDgNOL', $organization->getId()); |
55
|
|
|
$this->assertEquals(\DateTime::createFromFormat('U', 1454634415), $organization->getTimeCreated()); |
56
|
|
|
$this->assertEquals(\DateTime::createFromFormat('U', 1455048510), $organization->getTimeLastModified()); |
57
|
|
|
|
58
|
|
|
$expectedDelegatees = [ |
59
|
|
|
'cBrUjKvQQgdRp~s1qvQNLpK*' |
60
|
|
|
]; |
61
|
|
|
$this->assertEquals($expectedDelegatees, $organization->getDelegatees()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @covers OnFleet\Client::getOrganization |
66
|
|
|
* @covers OnFleet\Organization |
67
|
|
|
*/ |
68
|
|
|
public function testGettingDelegateeOrganizationByIdReturnsOrganization() |
69
|
|
|
{ |
70
|
|
|
// Arrange |
71
|
|
|
$this->mockedResponses->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
72
|
|
|
{ |
73
|
|
|
"id": "cBrUjKvQQgdRp~s1qvQNLpK*", |
74
|
|
|
"name": "Onfleet Engineering", |
75
|
|
|
"email": "[email protected]", |
76
|
|
|
"timezone": "America/Los_Angeles", |
77
|
|
|
"country": "US" |
78
|
|
|
}'))); |
79
|
|
|
|
80
|
|
|
// Act |
81
|
|
|
$organization = $this->client->getOrganization('cBrUjKvQQgdRp~s1qvQNLpK*'); |
82
|
|
|
|
83
|
|
|
// Assert |
84
|
|
|
$this->assertRequestIsGet('organizations/cBrUjKvQQgdRp~s1qvQNLpK*'); |
85
|
|
|
|
86
|
|
|
$this->assertInstanceOf(Organization::class, $organization); |
87
|
|
|
$this->assertEquals('cBrUjKvQQgdRp~s1qvQNLpK*', $organization->getId()); |
88
|
|
|
$this->assertEquals('[email protected]', $organization->getEmail()); |
89
|
|
|
$this->assertEquals('America/Los_Angeles', $organization->getTimezone()); |
90
|
|
|
$this->assertEquals('US', $organization->getCountry()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @covers OnFleet\Client::createAdministrator |
95
|
|
|
* @covers OnFleet\Administrator |
96
|
|
|
*/ |
97
|
|
|
public function testCreatingAdministratorCreatesAndReturnsAdministrator() |
98
|
|
|
{ |
99
|
|
|
// Arrange |
100
|
|
|
$this->mockedResponses |
101
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory('{ |
102
|
|
|
"id": "8AxaiKwMd~np7I*YP2NfukBE", |
103
|
|
|
"timeCreated": 1455156651000, |
104
|
|
|
"timeLastModified": 1455156651779, |
105
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
106
|
|
|
"email": "[email protected]", |
107
|
|
|
"type": "standard", |
108
|
|
|
"name": "Admin Dispatcher", |
109
|
|
|
"isActive": false, |
110
|
|
|
"metadata": [] |
111
|
|
|
}'))); |
112
|
|
|
|
113
|
|
|
$adminData = [ |
114
|
|
|
'name' => 'Admin Dispatcher', |
115
|
|
|
'email' => '[email protected]', |
116
|
|
|
]; |
117
|
|
|
|
118
|
|
|
// Act |
119
|
|
|
$administrator = $this->client->createAdministrator($adminData); |
120
|
|
|
|
121
|
|
|
// Assert |
122
|
|
|
$this->assertRequestIsPost('admins', $adminData); |
123
|
|
|
|
124
|
|
|
$this->assertInstanceOf(Administrator::class, $administrator); |
125
|
|
|
$this->assertEquals('yAM*fDkztrT3gUcz9mNDgNOL', $administrator->getOrganization()); |
126
|
|
|
$this->assertEquals('[email protected]', $administrator->getEmail()); |
127
|
|
|
$this->assertEquals('Admin Dispatcher', $administrator->getName()); |
128
|
|
|
$this->assertEquals('standard', $administrator->getType()); |
129
|
|
|
$this->assertFalse($administrator->isActive()); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @covers OnFleet\Client::getAdministrators |
134
|
|
|
* @covers OnFleet\Administrator |
135
|
|
|
*/ |
136
|
|
|
public function testGettingAdministratorsReturnsArrayOfAdministrators() |
137
|
|
|
{ |
138
|
|
|
$this->mockedResponses |
139
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
140
|
|
|
[ |
141
|
|
|
{ |
142
|
|
|
"id": "8AxaiKwMd~np7I*YP2NfukBE", |
143
|
|
|
"timeCreated": 1455156651000, |
144
|
|
|
"timeLastModified": 1455156651779, |
145
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
146
|
|
|
"email": "[email protected]", |
147
|
|
|
"type": "super", |
148
|
|
|
"name": "Super Admin", |
149
|
|
|
"isActive": true, |
150
|
|
|
"metadata": [] |
151
|
|
|
}, |
152
|
|
|
{ |
153
|
|
|
"id": "8AxaiKwMd~np7I*YP2NfukBE", |
154
|
|
|
"timeCreated": 1455156651000, |
155
|
|
|
"timeLastModified": 1455156651779, |
156
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
157
|
|
|
"email": "[email protected]", |
158
|
|
|
"type": "standard", |
159
|
|
|
"name": "Dispatcher Admin", |
160
|
|
|
"isActive": false, |
161
|
|
|
"metadata": [] |
162
|
|
|
} |
163
|
|
|
] |
164
|
|
|
'))); |
165
|
|
|
|
166
|
|
|
$administrators = $this->client->getAdministrators(); |
167
|
|
|
|
168
|
|
|
$this->assertRequestIsGet('admins'); |
169
|
|
|
|
170
|
|
|
$this->assertCount(2, $administrators); |
171
|
|
|
$administrator = $administrators[0]; |
172
|
|
|
$this->assertEquals('8AxaiKwMd~np7I*YP2NfukBE', $administrator->getId()); |
173
|
|
|
$this->assertEquals('super', $administrator->getType()); |
174
|
|
|
$this->assertTrue($administrator->isActive()); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @covers OnFleet\Client::createWorker |
179
|
|
|
* @covers OnFleet\Worker |
180
|
|
|
*/ |
181
|
|
|
public function testCreatingWorkerCreatesAndReturnsWorker() |
182
|
|
|
{ |
183
|
|
|
// Arrange |
184
|
|
|
$this->mockedResponses |
185
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
186
|
|
|
{ |
187
|
|
|
"id": "sFtvhYK2l26zS0imptJJdC2q", |
188
|
|
|
"timeCreated": 1455156653000, |
189
|
|
|
"timeLastModified": 1455156653214, |
190
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
191
|
|
|
"name": "Worker Workowsky", |
192
|
|
|
"phone": "+16173428853", |
193
|
|
|
"activeTask": null, |
194
|
|
|
"tasks": [], |
195
|
|
|
"onDuty": false, |
196
|
|
|
"timeLastSeen": null, |
197
|
|
|
"delayTime": null, |
198
|
|
|
"teams": [ |
199
|
|
|
"nz1nG1Hpx9EHjQCJsT2VAs~o" |
200
|
|
|
], |
201
|
|
|
"metadata": [], |
202
|
|
|
"vehicle": { |
203
|
|
|
"id": "tN1HjcvygQWvz5FRR1JAxwL8", |
204
|
|
|
"type": "CAR", |
205
|
|
|
"description": "Tesla Model 3", |
206
|
|
|
"licensePlate": "FKNS9A", |
207
|
|
|
"color": "purple" |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
'))); |
211
|
|
|
|
212
|
|
|
$data = [ |
213
|
|
|
'name' => 'Worker Workowsky', |
214
|
|
|
'phone' => '+16173428853', |
215
|
|
|
'teams' => [ |
216
|
|
|
'nz1nG1Hpx9EHjQCJsT2VAs~o' |
217
|
|
|
] |
218
|
|
|
]; |
219
|
|
|
|
220
|
|
|
// Act |
221
|
|
|
$worker = $this->client->createWorker($data); |
222
|
|
|
|
223
|
|
|
// Assert |
224
|
|
|
$this->assertRequestIsPost('workers', $data); |
225
|
|
|
|
226
|
|
|
$this->assertInstanceOf(Worker::class, $worker); |
227
|
|
|
$this->assertEquals('sFtvhYK2l26zS0imptJJdC2q', $worker->getId()); |
228
|
|
|
$this->assertEquals('Worker Workowsky', $worker->getName()); |
229
|
|
|
$this->assertEquals('+16173428853', $worker->getPhone()); |
230
|
|
|
$this->assertEquals([ |
231
|
|
|
'nz1nG1Hpx9EHjQCJsT2VAs~o' |
232
|
|
|
], $worker->getTeams()); |
233
|
|
|
$this->assertEquals('Tesla Model 3', $worker->getVehicle()['description']); |
234
|
|
|
$this->assertFalse($worker->isOnDuty()); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @covers OnFleet\Client::getWorkers |
239
|
|
|
* @covers OnFleet\Worker |
240
|
|
|
*/ |
241
|
|
|
public function testGettingWorkersReturnsArrayOfWorkers() |
242
|
|
|
{ |
243
|
|
|
$this->mockedResponses |
244
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
245
|
|
|
[ |
246
|
|
|
{ |
247
|
|
|
"id": "h*wSb*apKlDkUFnuLTtjPke7", |
248
|
|
|
"timeCreated": 1455049674000, |
249
|
|
|
"timeLastModified": 1455156646529, |
250
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
251
|
|
|
"name": "Andoni", |
252
|
|
|
"phone": "+14155558442", |
253
|
|
|
"activeTask": null, |
254
|
|
|
"tasks": [ |
255
|
|
|
"11z1BbsQUZFHD1XAd~emDDeK" |
256
|
|
|
], |
257
|
|
|
"onDuty": true, |
258
|
|
|
"timeLastSeen": 1455156644323, |
259
|
|
|
"delayTime": null, |
260
|
|
|
"teams": [ |
261
|
|
|
"R4P7jhuzaIZ4cHHZE1ghmTtB" |
262
|
|
|
], |
263
|
|
|
"metadata": [ |
264
|
|
|
{ |
265
|
|
|
"name": "nickname", |
266
|
|
|
"type": "string", |
267
|
|
|
"value": "Puffy", |
268
|
|
|
"visibility": [ |
269
|
|
|
"api" |
270
|
|
|
] |
271
|
|
|
}, |
272
|
|
|
{ |
273
|
|
|
"name": "otherDetails", |
274
|
|
|
"type": "object", |
275
|
|
|
"value": { |
276
|
|
|
"availability": { |
277
|
|
|
"mon": "10:00", |
278
|
|
|
"sat": "16:20", |
279
|
|
|
"wed": "13:30" |
280
|
|
|
}, |
281
|
|
|
"premiumInsurance": false, |
282
|
|
|
"trunkSize": 9.5 |
283
|
|
|
}, |
284
|
|
|
"visibility": [ |
285
|
|
|
"api" |
286
|
|
|
] |
287
|
|
|
} |
288
|
|
|
], |
289
|
|
|
"location": [ |
290
|
|
|
-122.4015496466794, |
291
|
|
|
37.77629837661284 |
292
|
|
|
], |
293
|
|
|
"vehicle": null |
294
|
|
|
}, |
295
|
|
|
{ |
296
|
|
|
"id": "1LjhGUWdxFbvdsTAAXs0TFos", |
297
|
|
|
"timeCreated": 1455049755000, |
298
|
|
|
"timeLastModified": 1455072352267, |
299
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
300
|
|
|
"name": "Yevgeny", |
301
|
|
|
"phone": "+14155552299", |
302
|
|
|
"activeTask": null, |
303
|
|
|
"tasks": [ |
304
|
|
|
"*0tnJcly~vSI~9uHz*ICHXTw", |
305
|
|
|
"PauBfRH8gQCjtMLaPe97G8Jf" |
306
|
|
|
], |
307
|
|
|
"onDuty": true, |
308
|
|
|
"timeLastSeen": 1455156649007, |
309
|
|
|
"delayTime": null, |
310
|
|
|
"teams": [ |
311
|
|
|
"9dyuPqHt6kDK5JKHFhE0xihh", |
312
|
|
|
"yKpCnWprM1Rvp3NGGlVa5TMa", |
313
|
|
|
"fwflFNVvrK~4t0m5hKFIxBUl" |
314
|
|
|
], |
315
|
|
|
"metadata": [], |
316
|
|
|
"location": [ |
317
|
|
|
-122.4016366, |
318
|
|
|
37.7764098 |
319
|
|
|
], |
320
|
|
|
"vehicle": { |
321
|
|
|
"id": "ArBoHNxS4B76AiBKoIawY9OS", |
322
|
|
|
"type": "CAR", |
323
|
|
|
"description": "Lada Niva", |
324
|
|
|
"licensePlate": "23KJ129", |
325
|
|
|
"color": "Red" |
326
|
|
|
} |
327
|
|
|
} |
328
|
|
|
] |
329
|
|
|
'))); |
330
|
|
|
|
331
|
|
|
$workers = $this->client->getWorkers(); |
332
|
|
|
|
333
|
|
|
$this->assertRequestIsGet('workers'); |
334
|
|
|
|
335
|
|
|
$this->assertCount(2, $workers); |
336
|
|
|
$worker = $workers[0]; |
337
|
|
|
$this->assertEquals('h*wSb*apKlDkUFnuLTtjPke7', $worker->getId()); |
338
|
|
|
$this->assertTrue($worker->isOnDuty()); |
339
|
|
|
$this->assertFalse($worker->getNormalizedMetadata()['otherDetails']['premiumInsurance']); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* @covers OnFleet\Client::getWorker |
344
|
|
|
* @covers OnFleet\Worker |
345
|
|
|
*/ |
346
|
|
|
public function testGettingWorkerByIdReturnsWorker() |
347
|
|
|
{ |
348
|
|
|
$this->mockedResponses |
349
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
350
|
|
|
{ |
351
|
|
|
"id": "1LjhGUWdxFbvdsTAAXs0TFos", |
352
|
|
|
"timeCreated": 1455049755000, |
353
|
|
|
"timeLastModified": 1455072352267, |
354
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
355
|
|
|
"name": "Yevgeny", |
356
|
|
|
"phone": "+14155552299", |
357
|
|
|
"activeTask": null, |
358
|
|
|
"tasks": [ |
359
|
|
|
"*0tnJcly~vSI~9uHz*ICHXTw", |
360
|
|
|
"PauBfRH8gQCjtMLaPe97G8Jf" |
361
|
|
|
], |
362
|
|
|
"onDuty": true, |
363
|
|
|
"timeLastSeen": 1455156649007, |
364
|
|
|
"delayTime": null, |
365
|
|
|
"teams": [ |
366
|
|
|
"9dyuPqHt6kDK5JKHFhE0xihh", |
367
|
|
|
"yKpCnWprM1Rvp3NGGlVa5TMa", |
368
|
|
|
"fwflFNVvrK~4t0m5hKFIxBUl" |
369
|
|
|
], |
370
|
|
|
"metadata": [], |
371
|
|
|
"location": [ |
372
|
|
|
-122.4016366, |
373
|
|
|
37.7764098 |
374
|
|
|
], |
375
|
|
|
"vehicle": { |
376
|
|
|
"id": "ArBoHNxS4B76AiBKoIawY9OS", |
377
|
|
|
"type": "CAR", |
378
|
|
|
"description": "Lada Niva", |
379
|
|
|
"licensePlate": "23KJ129", |
380
|
|
|
"color": "Red" |
381
|
|
|
} |
382
|
|
|
} |
383
|
|
|
'))); |
384
|
|
|
|
385
|
|
|
$worker = $this->client->getWorker('1LjhGUWdxFbvdsTAAXs0TFos'); |
386
|
|
|
|
387
|
|
|
$this->assertRequestIsGet('workers/1LjhGUWdxFbvdsTAAXs0TFos?analytics=false'); |
388
|
|
|
$this->assertInstanceOf(Worker::class, $worker); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* @covers OnFleet\Client::getHubs |
393
|
|
|
* @covers OnFleet\Hub |
394
|
|
|
*/ |
395
|
|
|
public function testGettingHubsReturnsArrayOfHubs() |
396
|
|
|
{ |
397
|
|
|
$this->mockedResponses |
398
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
399
|
|
|
[ |
400
|
|
|
{ |
401
|
|
|
"id": "E4s6bwGpOZp6pSU3Hz*2ngFA", |
402
|
|
|
"name": "SF North", |
403
|
|
|
"location": [ |
404
|
|
|
-122.44002499999999, |
405
|
|
|
37.801826 |
406
|
|
|
], |
407
|
|
|
"address": { |
408
|
|
|
"number": "3415", |
409
|
|
|
"street": "Pierce Street", |
410
|
|
|
"city": "San Francisco", |
411
|
|
|
"state": "California", |
412
|
|
|
"country": "United States", |
413
|
|
|
"postalCode": "94123" |
414
|
|
|
} |
415
|
|
|
}, |
416
|
|
|
{ |
417
|
|
|
"id": "tKxSfU7psqDQEBVn5e2VQ~*O", |
418
|
|
|
"name": "SF South", |
419
|
|
|
"location": [ |
420
|
|
|
-122.44337999999999, |
421
|
|
|
37.70883 |
422
|
|
|
], |
423
|
|
|
"address": { |
424
|
|
|
"number": "335", |
425
|
|
|
"street": "Hanover Street", |
426
|
|
|
"city": "San Francisco", |
427
|
|
|
"state": "California", |
428
|
|
|
"country": "United States", |
429
|
|
|
"postalCode": "94112" |
430
|
|
|
} |
431
|
|
|
} |
432
|
|
|
] |
433
|
|
|
'))); |
434
|
|
|
|
435
|
|
|
$hubs = $this->client->getHubs(); |
436
|
|
|
|
437
|
|
|
$this->assertRequestIsGet('hubs'); |
438
|
|
|
|
439
|
|
|
$this->assertCount(2, $hubs); |
440
|
|
|
$hub = $hubs[0]; |
441
|
|
|
$this->assertInstanceOf(Hub::class, $hub); |
442
|
|
|
$this->assertEquals('94123', $hub->getAddress()['postalCode']); |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* @covers OnFleet\Client::createTeam |
447
|
|
|
* @covers OnFleet\Team |
448
|
|
|
*/ |
449
|
|
|
public function testCreatingTeamCreatesAndReturnsTeam() |
450
|
|
|
{ |
451
|
|
|
$this->mockedResponses |
452
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
453
|
|
|
{ |
454
|
|
|
"id": "teamiKwMd~np7I*YP2NfukBE", |
455
|
|
|
"name": "Team", |
456
|
|
|
"workers": [ |
457
|
|
|
"sFtvhYK2l26zS0imptJJdC2q", |
458
|
|
|
"h*wSb*apKlDkUFnuLTtjPke7" |
459
|
|
|
], |
460
|
|
|
"managers": [ |
461
|
|
|
"8AxaiKwMd~np7I*YP2NfukBE" |
462
|
|
|
], |
463
|
|
|
"hub": "E4s6bwGpOZp6pSU3Hz*2ngFA", |
464
|
|
|
"timeCreated": 1455156651000, |
465
|
|
|
"timeLastModified": 1455156651779 |
466
|
|
|
} |
467
|
|
|
'))); |
468
|
|
|
|
469
|
|
|
$data = [ |
470
|
|
|
'name' => 'Team', |
471
|
|
|
'workers' => [ |
472
|
|
|
'sFtvhYK2l26zS0imptJJdC2q', |
473
|
|
|
'h*wSb*apKlDkUFnuLTtjPke7', |
474
|
|
|
], |
475
|
|
|
'managers' => [ |
476
|
|
|
'8AxaiKwMd~np7I*YP2NfukBE', |
477
|
|
|
], |
478
|
|
|
'hub' => 'E4s6bwGpOZp6pSU3Hz*2ngFA', |
479
|
|
|
]; |
480
|
|
|
$team = $this->client->createTeam($data); |
481
|
|
|
|
482
|
|
|
$this->assertRequestIsPost('teams', $data); |
483
|
|
|
|
484
|
|
|
$this->assertInstanceOf(Team::class, $team); |
485
|
|
|
$this->assertEquals('Team', $team->getName()); |
486
|
|
|
$this->assertEquals('E4s6bwGpOZp6pSU3Hz*2ngFA', $team->getHub()); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
/** |
490
|
|
|
* @covers OnFleet\Client::getTeams |
491
|
|
|
* @covers OnFleet\Team |
492
|
|
|
*/ |
493
|
|
|
public function testGettingTeamsReturnsArrayOfTeams() |
494
|
|
|
{ |
495
|
|
|
$this->mockedResponses |
496
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
497
|
|
|
[ |
498
|
|
|
{ |
499
|
|
|
"id": "teamiKwMd~np7I*YP2NfukBE", |
500
|
|
|
"name": "Team", |
501
|
|
|
"workers": [ |
502
|
|
|
"sFtvhYK2l26zS0imptJJdC2q", |
503
|
|
|
"h*wSb*apKlDkUFnuLTtjPke7" |
504
|
|
|
], |
505
|
|
|
"managers": [ |
506
|
|
|
"8AxaiKwMd~np7I*YP2NfukBE" |
507
|
|
|
], |
508
|
|
|
"hub": "E4s6bwGpOZp6pSU3Hz*2ngFA", |
509
|
|
|
"timeCreated": 1455156651000, |
510
|
|
|
"timeLastModified": 1455156651779 |
511
|
|
|
} |
512
|
|
|
] |
513
|
|
|
'))); |
514
|
|
|
|
515
|
|
|
$teams = $this->client->getTeams(); |
516
|
|
|
|
517
|
|
|
$this->assertRequestIsGet('teams'); |
518
|
|
|
|
519
|
|
|
$this->assertCount(1, $teams); |
520
|
|
|
$team = $teams[0]; |
521
|
|
|
$this->assertEquals('teamiKwMd~np7I*YP2NfukBE', $team->getId()); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* @covers OnFleet\Client::getTeam |
526
|
|
|
* @covers OnFleet\Team |
527
|
|
|
*/ |
528
|
|
|
public function testGettingTeamByIdReturnsTeam() |
529
|
|
|
{ |
530
|
|
|
$this->mockedResponses |
531
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
532
|
|
|
{ |
533
|
|
|
"id": "teamiKwMd~np7I*YP2NfukBE", |
534
|
|
|
"name": "Team", |
535
|
|
|
"workers": [ |
536
|
|
|
"sFtvhYK2l26zS0imptJJdC2q", |
537
|
|
|
"h*wSb*apKlDkUFnuLTtjPke7" |
538
|
|
|
], |
539
|
|
|
"managers": [ |
540
|
|
|
"8AxaiKwMd~np7I*YP2NfukBE" |
541
|
|
|
], |
542
|
|
|
"hub": "E4s6bwGpOZp6pSU3Hz*2ngFA", |
543
|
|
|
"timeCreated": 1455156651000, |
544
|
|
|
"timeLastModified": 1455156651779 |
545
|
|
|
} |
546
|
|
|
'))); |
547
|
|
|
|
548
|
|
|
$team = $this->client->getTeam('teamiKwMd~np7I*YP2NfukBE'); |
549
|
|
|
|
550
|
|
|
$this->assertRequestIsGet('teams/teamiKwMd~np7I*YP2NfukBE'); |
551
|
|
|
$this->assertInstanceOf(Team::class, $team); |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/** |
555
|
|
|
* @covers OnFleet\Client::createDestination |
556
|
|
|
* @covers OnFleet\Destination |
557
|
|
|
*/ |
558
|
|
|
public function testCreatingDestinationReturnsDestination() |
559
|
|
|
{ |
560
|
|
|
$this->mockedResponses |
561
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
562
|
|
|
{ |
563
|
|
|
"id": "JLn6ZoYGZWn2wB2HaR9glsqB", |
564
|
|
|
"timeCreated": 1455156663000, |
565
|
|
|
"timeLastModified": 1455156663896, |
566
|
|
|
"location": [ |
567
|
|
|
-122.3965731, |
568
|
|
|
37.7875728 |
569
|
|
|
], |
570
|
|
|
"address": { |
571
|
|
|
"apartment": "5th Floor", |
572
|
|
|
"state": "California", |
573
|
|
|
"postalCode": "94105", |
574
|
|
|
"country": "United States", |
575
|
|
|
"city": "San Francisco", |
576
|
|
|
"street": "Howard Street", |
577
|
|
|
"number": "543" |
578
|
|
|
}, |
579
|
|
|
"notes": "Don\'t forget to check out the epic rooftop.", |
580
|
|
|
"metadata": [] |
581
|
|
|
} |
582
|
|
|
'))); |
583
|
|
|
|
584
|
|
|
$data = [ |
585
|
|
|
'address' => [ |
586
|
|
|
'number' => '23', |
587
|
|
|
'street' => 'Howard Street', |
588
|
|
|
'apartment' => '5th Floor', |
589
|
|
|
'city' => 'San Francisco', |
590
|
|
|
'country' => 'United States', |
591
|
|
|
'state' => 'California', |
592
|
|
|
'postalCode' => '94105', |
593
|
|
|
], |
594
|
|
|
'notes' => 'Don\'t forget to check out the epic rooftop.', |
595
|
|
|
'location' => [ |
596
|
|
|
-122.3965731, |
597
|
|
|
37.7875728, |
598
|
|
|
] |
599
|
|
|
]; |
600
|
|
|
$destination = $this->client->createDestination($data); |
601
|
|
|
|
602
|
|
|
$this->assertRequestIsPost('destinations', $data); |
603
|
|
|
$this->assertInstanceOf(Destination::class, $destination); |
604
|
|
|
$this->assertEquals('JLn6ZoYGZWn2wB2HaR9glsqB', $destination->getId()); |
605
|
|
|
$this->assertEquals('Don\'t forget to check out the epic rooftop.', $destination->getNotes()); |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
/** |
609
|
|
|
* @covers OnFleet\Client::getDestination |
610
|
|
|
* @covers OnFleet\Destination |
611
|
|
|
*/ |
612
|
|
|
public function testGettingDestinationByIdReturnsDestination() |
613
|
|
|
{ |
614
|
|
|
$this->mockedResponses |
615
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
616
|
|
|
{ |
617
|
|
|
"id": "JLn6ZoYGZWn2wB2HaR9glsqB", |
618
|
|
|
"timeCreated": 1455156663000, |
619
|
|
|
"timeLastModified": 1455156663896, |
620
|
|
|
"location": [ |
621
|
|
|
-122.3965731, |
622
|
|
|
37.7875728 |
623
|
|
|
], |
624
|
|
|
"address": { |
625
|
|
|
"apartment": "5th Floor", |
626
|
|
|
"state": "California", |
627
|
|
|
"postalCode": "94105", |
628
|
|
|
"country": "United States", |
629
|
|
|
"city": "San Francisco", |
630
|
|
|
"street": "Howard Street", |
631
|
|
|
"number": "543" |
632
|
|
|
}, |
633
|
|
|
"notes": "Don\'t forget to check out the epic rooftop.", |
634
|
|
|
"metadata": [] |
635
|
|
|
} |
636
|
|
|
'))); |
637
|
|
|
|
638
|
|
|
$destination = $this->client->getDestination('JLn6ZoYGZWn2wB2HaR9glsqB'); |
639
|
|
|
|
640
|
|
|
$this->assertRequestIsGet('destinations/JLn6ZoYGZWn2wB2HaR9glsqB'); |
641
|
|
|
$this->assertInstanceOf(Destination::class, $destination); |
642
|
|
|
$this->assertEquals('JLn6ZoYGZWn2wB2HaR9glsqB', $destination->getId()); |
643
|
|
|
$this->assertEquals([ |
644
|
|
|
-122.3965731, |
645
|
|
|
37.7875728 |
646
|
|
|
], $destination->getLocation()); |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
/** |
650
|
|
|
* @covers OnFleet\Client::createRecipient |
651
|
|
|
* @covers OnFleet\Recipient |
652
|
|
|
*/ |
653
|
|
|
public function testCreatingRecipientCreatesAndReturnsRecipient() |
654
|
|
|
{ |
655
|
|
|
$this->mockedResponses |
656
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
657
|
|
|
{ |
658
|
|
|
"id": "VVLx5OdKvw0dRSjT2rGOc6Y*", |
659
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
660
|
|
|
"timeCreated": 1455156665000, |
661
|
|
|
"timeLastModified": 1455156665390, |
662
|
|
|
"name": "Boris Foster", |
663
|
|
|
"phone": "+16505551133", |
664
|
|
|
"notes": "Always orders our GSC special", |
665
|
|
|
"skipSMSNotifications": false, |
666
|
|
|
"metadata": [] |
667
|
|
|
} |
668
|
|
|
'))); |
669
|
|
|
|
670
|
|
|
$data = [ |
671
|
|
|
'name' => 'Boris Foster', |
672
|
|
|
'phone' => '650-555-1133', |
673
|
|
|
'notes' => 'Always orders our GSC special' |
674
|
|
|
]; |
675
|
|
|
$recipient = $this->client->createRecipient($data); |
676
|
|
|
|
677
|
|
|
$this->assertRequestIsPost('recipients', $data); |
678
|
|
|
$this->assertInstanceOf(Recipient::class, $recipient); |
679
|
|
|
$this->assertEquals('VVLx5OdKvw0dRSjT2rGOc6Y*', $recipient->getId()); |
680
|
|
|
$this->assertEquals('Always orders our GSC special', $recipient->getNotes()); |
681
|
|
|
$this->assertEquals('+16505551133', $recipient->getPhone()); |
682
|
|
|
} |
683
|
|
|
|
684
|
|
|
/** |
685
|
|
|
* @covers OnFleet\Client::getRecipient |
686
|
|
|
* @covers OnFleet\Recipient |
687
|
|
|
*/ |
688
|
|
|
public function testGettingRecipientByIdReturnsRecipient() |
689
|
|
|
{ |
690
|
|
|
$this->mockedResponses |
691
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
692
|
|
|
{ |
693
|
|
|
"id": "VVLx5OdKvw0dRSjT2rGOc6Y*", |
694
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
695
|
|
|
"timeCreated": 1455156665000, |
696
|
|
|
"timeLastModified": 1455156665390, |
697
|
|
|
"name": "Boris Foster", |
698
|
|
|
"phone": "+16505551133", |
699
|
|
|
"notes": "Always orders our GSC special", |
700
|
|
|
"skipSMSNotifications": false, |
701
|
|
|
"metadata": [] |
702
|
|
|
} |
703
|
|
|
'))); |
704
|
|
|
|
705
|
|
|
$recipient = $this->client->getRecipient('VVLx5OdKvw0dRSjT2rGOc6Y*'); |
706
|
|
|
|
707
|
|
|
$this->assertRequestIsGet('recipients/VVLx5OdKvw0dRSjT2rGOc6Y*'); |
708
|
|
|
$this->assertInstanceOf(Recipient::class, $recipient); |
709
|
|
|
$this->assertEquals('VVLx5OdKvw0dRSjT2rGOc6Y*', $recipient->getId()); |
710
|
|
|
$this->assertFalse($recipient->isSMSNotificationSkipped()); |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
/** |
714
|
|
|
* @covers OnFleet\Client::getRecipientByName |
715
|
|
|
* @covers OnFleet\Recipient |
716
|
|
|
*/ |
717
|
|
|
public function testGettingRecipientByNameReturnsRecipient() |
718
|
|
|
{ |
719
|
|
|
$this->mockedResponses |
720
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
721
|
|
|
{ |
722
|
|
|
"id": "VVLx5OdKvw0dRSjT2rGOc6Y*", |
723
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
724
|
|
|
"timeCreated": 1455156665000, |
725
|
|
|
"timeLastModified": 1455156665390, |
726
|
|
|
"name": "Boris Foster", |
727
|
|
|
"phone": "+16505551133", |
728
|
|
|
"notes": "Always orders our GSC special", |
729
|
|
|
"skipSMSNotifications": false, |
730
|
|
|
"metadata": [] |
731
|
|
|
} |
732
|
|
|
'))); |
733
|
|
|
|
734
|
|
|
$recipient = $this->client->getRecipientByName('Boris Foster'); |
735
|
|
|
|
736
|
|
|
$this->assertRequestIsGet('recipients/name/boris%20foster'); |
737
|
|
|
$this->assertInstanceOf(Recipient::class, $recipient); |
738
|
|
|
$this->assertEquals('VVLx5OdKvw0dRSjT2rGOc6Y*', $recipient->getId()); |
739
|
|
|
$this->assertFalse($recipient->isSMSNotificationSkipped()); |
740
|
|
|
} |
741
|
|
|
|
742
|
|
|
/** |
743
|
|
|
* @covers OnFleet\Client::getRecipientByPhone |
744
|
|
|
* @covers OnFleet\Recipient |
745
|
|
|
*/ |
746
|
|
|
public function testGettingRecipientByPhoneReturnsRecipient() |
747
|
|
|
{ |
748
|
|
|
$this->mockedResponses |
749
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
750
|
|
|
{ |
751
|
|
|
"id": "VVLx5OdKvw0dRSjT2rGOc6Y*", |
752
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
753
|
|
|
"timeCreated": 1455156665000, |
754
|
|
|
"timeLastModified": 1455156665390, |
755
|
|
|
"name": "Boris Foster", |
756
|
|
|
"phone": "+16505551133", |
757
|
|
|
"notes": "Always orders our GSC special", |
758
|
|
|
"skipSMSNotifications": false, |
759
|
|
|
"metadata": [] |
760
|
|
|
} |
761
|
|
|
'))); |
762
|
|
|
|
763
|
|
|
$recipient = $this->client->getRecipientByPhone('(650)-555-1133'); |
764
|
|
|
|
765
|
|
|
$this->assertRequestIsGet('recipients/phone/6505551133'); |
766
|
|
|
$this->assertInstanceOf(Recipient::class, $recipient); |
767
|
|
|
$this->assertEquals('VVLx5OdKvw0dRSjT2rGOc6Y*', $recipient->getId()); |
768
|
|
|
$this->assertFalse($recipient->isSMSNotificationSkipped()); |
769
|
|
|
} |
770
|
|
|
|
771
|
|
|
/** |
772
|
|
|
* @covers OnFleet\Client::createTask |
773
|
|
|
* @covers OnFleet\Task |
774
|
|
|
*/ |
775
|
|
|
public function testCreatingATaskReturnsTask() |
776
|
|
|
{ |
777
|
|
|
$this->mockedResponses |
778
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
779
|
|
|
{ |
780
|
|
|
"id": "kc8SS1tzuZ~jqjlebKGrUmpe", |
781
|
|
|
"timeCreated": 1455156667000, |
782
|
|
|
"timeLastModified": 1455156667234, |
783
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
784
|
|
|
"shortId": "8f983639", |
785
|
|
|
"trackingURL": "https://onf.lt/8f98363993", |
786
|
|
|
"worker": "1LjhGUWdxFbvdsTAAXs0TFos", |
787
|
|
|
"merchant": "yAM*fDkztrT3gUcz9mNDgNOL", |
788
|
|
|
"executor": "yAM*fDkztrT3gUcz9mNDgNOL", |
789
|
|
|
"creator": "EJmsbJgHiRLPjNVE7GEIPs7*", |
790
|
|
|
"dependencies": [], |
791
|
|
|
"state": 0, |
792
|
|
|
"completeAfter": 1455151071727, |
793
|
|
|
"completeBefore": null, |
794
|
|
|
"pickupTask": false, |
795
|
|
|
"notes": "Order 332: 24oz Stumptown Finca El Puente, 10 x Aji de Gallina Empanadas, 13-inch Lelenitas Tres Leches", |
796
|
|
|
"completionDetails": { |
797
|
|
|
"events": [], |
798
|
|
|
"time": null |
799
|
|
|
}, |
800
|
|
|
"feedback": [], |
801
|
|
|
"metadata": [], |
802
|
|
|
"overrides": { |
803
|
|
|
"recipientSkipSMSNotifications": null, |
804
|
|
|
"recipientNotes": null, |
805
|
|
|
"recipientName": null |
806
|
|
|
}, |
807
|
|
|
"container": { |
808
|
|
|
"type": "WORKER", |
809
|
|
|
"worker": "1LjhGUWdxFbvdsTAAXs0TFos" |
810
|
|
|
}, |
811
|
|
|
"recipients": [ |
812
|
|
|
{ |
813
|
|
|
"id": "G7rcM2nqblmh8vj2do1FpaOQ", |
814
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
815
|
|
|
"timeCreated": 1455156667000, |
816
|
|
|
"timeLastModified": 1455156667229, |
817
|
|
|
"name": "Blas Silkovich", |
818
|
|
|
"phone": "+16505554481", |
819
|
|
|
"notes": "Knows Neiman, VIP status.", |
820
|
|
|
"skipSMSNotifications": false, |
821
|
|
|
"metadata": [] |
822
|
|
|
} |
823
|
|
|
], |
824
|
|
|
"destination": { |
825
|
|
|
"id": "zrVXZi5aDzOZlAghZaLfGAfA", |
826
|
|
|
"timeCreated": 1455156667000, |
827
|
|
|
"timeLastModified": 1455156667220, |
828
|
|
|
"location": [ |
829
|
|
|
-122.4438337, |
830
|
|
|
37.7940329 |
831
|
|
|
], |
832
|
|
|
"address": { |
833
|
|
|
"apartment": "", |
834
|
|
|
"state": "California", |
835
|
|
|
"postalCode": "94123", |
836
|
|
|
"country": "United States", |
837
|
|
|
"city": "San Francisco", |
838
|
|
|
"street": "Vallejo Street", |
839
|
|
|
"number": "2829" |
840
|
|
|
}, |
841
|
|
|
"notes": "Small green door by garage door has pin pad, enter *4821*", |
842
|
|
|
"metadata": [] |
843
|
|
|
}, |
844
|
|
|
"didAutoAssign": true |
845
|
|
|
} |
846
|
|
|
'))); |
847
|
|
|
|
848
|
|
|
$data = [ |
849
|
|
|
'destination' => 'zrVXZi5aDzOZlAghZaLfGAfA', |
850
|
|
|
'recipients' => [ |
851
|
|
|
'G7rcM2nqblmh8vj2do1FpaOQ' |
852
|
|
|
], |
853
|
|
|
'merchant' => 'cBrUjKvQQgdRp~s1qvQNLpK*', |
854
|
|
|
'executor' => 'cBrUjKvQQgdRp~s1qvQNLpK*', |
855
|
|
|
'autoAssign' => [ |
856
|
|
|
'mode' => 'load', |
857
|
|
|
], |
858
|
|
|
]; |
859
|
|
|
$task = $this->client->createTask($data); |
860
|
|
|
|
861
|
|
|
$this->assertRequestIsPost('tasks', $data); |
862
|
|
|
$this->assertInstanceOf(Task::class, $task); |
863
|
|
|
$this->assertTrue($task->isAutoAssigned()); |
864
|
|
|
$this->assertEquals('1LjhGUWdxFbvdsTAAXs0TFos', $task->getWorker()); |
865
|
|
|
$this->assertEquals(0, $task->getState()); |
866
|
|
|
} |
867
|
|
|
|
868
|
|
|
/** |
869
|
|
|
* @covers OnFleet\Client::getTasks |
870
|
|
|
* @covers OnFleet\Task |
871
|
|
|
*/ |
872
|
|
|
public function testGettingTasksReturnsArrayOfTasks() |
873
|
|
|
{ |
874
|
|
|
$this->mockedResponses |
875
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
876
|
|
|
{ |
877
|
|
|
"lastId": "tPMO~h03sOIqFbnhqaOXgUsd", |
878
|
|
|
"tasks": [ |
879
|
|
|
{ |
880
|
|
|
"id": "11z1BbsQUZFHD1XAd~emDDeK", |
881
|
|
|
"timeCreated": 1455072025000, |
882
|
|
|
"timeLastModified": 1455072025278, |
883
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
884
|
|
|
"shortId": "31aac0a5", |
885
|
|
|
"trackingURL": "https://onf.lt/31aac0a5c", |
886
|
|
|
"worker": "h*wSb*apKlDkUFnuLTtjPke7", |
887
|
|
|
"merchant": "yAM*fDkztrT3gUcz9mNDgNOL", |
888
|
|
|
"executor": "yAM*fDkztrT3gUcz9mNDgNOL", |
889
|
|
|
"creator": "EJmsbJgHiRLPjNVE7GEIPs7*", |
890
|
|
|
"dependencies": [], |
891
|
|
|
"state": 1, |
892
|
|
|
"completeAfter": null, |
893
|
|
|
"completeBefore": null, |
894
|
|
|
"pickupTask": false, |
895
|
|
|
"notes": "", |
896
|
|
|
"completionDetails": { |
897
|
|
|
"events": [], |
898
|
|
|
"time": null |
899
|
|
|
}, |
900
|
|
|
"feedback": [], |
901
|
|
|
"metadata": [], |
902
|
|
|
"overrides": {}, |
903
|
|
|
"container": { |
904
|
|
|
"type": "WORKER", |
905
|
|
|
"worker": "h*wSb*apKlDkUFnuLTtjPke7" |
906
|
|
|
}, |
907
|
|
|
"recipients": [ |
908
|
|
|
{ |
909
|
|
|
"id": "xX87G1gSkeLvGXlHn2tn0~iB", |
910
|
|
|
"organization": "yAM*fDkztrT3gUcz9mNDgNOL", |
911
|
|
|
"timeCreated": 1455072004000, |
912
|
|
|
"timeLastModified": 1455072025272, |
913
|
|
|
"name": "Blake Turing", |
914
|
|
|
"phone": "+16505552811", |
915
|
|
|
"notes": "", |
916
|
|
|
"skipSMSNotifications": false, |
917
|
|
|
"metadata": [] |
918
|
|
|
} |
919
|
|
|
], |
920
|
|
|
"destination": { |
921
|
|
|
"id": "pfT5L1JclTdhvRnP9GQzMFuL", |
922
|
|
|
"timeCreated": 1455072025000, |
923
|
|
|
"timeLastModified": 1455072025264, |
924
|
|
|
"location": [ |
925
|
|
|
-122.41289010000003, |
926
|
|
|
37.787933 |
927
|
|
|
], |
928
|
|
|
"address": { |
929
|
|
|
"apartment": "", |
930
|
|
|
"state": "California", |
931
|
|
|
"postalCode": "94109", |
932
|
|
|
"country": "United States", |
933
|
|
|
"city": "San Francisco", |
934
|
|
|
"street": "Post Street", |
935
|
|
|
"number": "666" |
936
|
|
|
}, |
937
|
|
|
"notes": "", |
938
|
|
|
"metadata": [] |
939
|
|
|
} |
940
|
|
|
} |
941
|
|
|
] |
942
|
|
|
} |
943
|
|
|
'))); |
944
|
|
|
$from = \DateTime::createFromFormat('Y-m-d H:i:s', '2016-08-20 16:20:00'); |
945
|
|
|
$to = clone $from; |
946
|
|
|
$to->add(new \DateInterval('PT10M')); |
947
|
|
|
$lastId = null; |
948
|
|
|
|
949
|
|
|
$tasks = $this->client->getTasks($from, $to, $lastId); |
|
|
|
|
950
|
|
|
|
951
|
|
|
$this->assertRequestIsGet('tasks/all?from=1471710000000&to=1471710600000'); |
952
|
|
|
$this->assertCount(1, $tasks); |
953
|
|
|
$this->assertEquals('tPMO~h03sOIqFbnhqaOXgUsd', $lastId); |
954
|
|
|
} |
955
|
|
|
|
956
|
|
|
/** |
957
|
|
|
* @covers OnFleet\Client::getTask |
958
|
|
|
* @covers OnFleet\Task |
959
|
|
|
*/ |
960
|
|
|
public function testGettingTaskByIdReturnsTask() |
961
|
|
|
{ |
962
|
|
|
$this->mockedResponses |
963
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
964
|
|
|
{ |
965
|
|
|
"id": "11z1BbsQUZFHD1XAd~emDDeK" |
966
|
|
|
} |
967
|
|
|
'))); |
968
|
|
|
|
969
|
|
|
$task = $this->client->getTask('11z1BbsQUZFHD1XAd~emDDeK'); |
970
|
|
|
|
971
|
|
|
$this->assertRequestIsGet('tasks/11z1BbsQUZFHD1XAd~emDDeK'); |
972
|
|
|
$this->assertInstanceOf(Task::class, $task); |
973
|
|
|
$this->assertEquals('11z1BbsQUZFHD1XAd~emDDeK', $task->getId()); |
974
|
|
|
} |
975
|
|
|
|
976
|
|
|
/** |
977
|
|
|
* @covers OnFleet\Client::getTaskByShortId |
978
|
|
|
* @covers OnFleet\Task |
979
|
|
|
*/ |
980
|
|
|
public function testGettingTaskByShortIdReturnsTask() |
981
|
|
|
{ |
982
|
|
|
$this->mockedResponses |
983
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
984
|
|
|
{ |
985
|
|
|
"id": "11z1BbsQUZFHD1XAd~emDDeK", |
986
|
|
|
"shortId": "31aac0a5" |
987
|
|
|
} |
988
|
|
|
'))); |
989
|
|
|
|
990
|
|
|
$task = $this->client->getTaskByShortId('31aac0a5'); |
991
|
|
|
|
992
|
|
|
$this->assertRequestIsGet('tasks/shortId/31aac0a5'); |
993
|
|
|
$this->assertInstanceOf(Task::class, $task); |
994
|
|
|
$this->assertEquals('11z1BbsQUZFHD1XAd~emDDeK', $task->getId()); |
995
|
|
|
$this->assertEquals('31aac0a5', $task->getShortId()); |
996
|
|
|
} |
997
|
|
|
|
998
|
|
|
/** |
999
|
|
|
* @covers OnFleet\Client::setOrganizationTasks |
1000
|
|
|
*/ |
1001
|
|
|
public function testSettingOrganizationTasks() |
1002
|
|
|
{ |
1003
|
|
|
$this->mockedResponses |
1004
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'])); |
1005
|
|
|
|
1006
|
|
|
$taskIds = [ |
1007
|
|
|
'11z1BbsQUZFHD1XAd~emDDeK', |
1008
|
|
|
'kc8SS1tzuZ~jqjlebKGrUmpe' |
1009
|
|
|
]; |
1010
|
|
|
$this->client->setOrganizationTasks($taskIds, 'yAM*fDkztrT3gUcz9mNDgNOL'); |
1011
|
|
|
|
1012
|
|
|
$this->assertRequestIsPut('containers/organizations/yAM*fDkztrT3gUcz9mNDgNOL', [ |
1013
|
|
|
'tasks' => $taskIds |
1014
|
|
|
]); |
1015
|
|
|
} |
1016
|
|
|
|
1017
|
|
|
/** |
1018
|
|
|
* @covers OnFleet\Client::setTeamTasks |
1019
|
|
|
*/ |
1020
|
|
|
public function testSettingTeamTasks() |
1021
|
|
|
{ |
1022
|
|
|
$this->mockedResponses |
1023
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'])); |
1024
|
|
|
|
1025
|
|
|
$taskIds = [ |
1026
|
|
|
'11z1BbsQUZFHD1XAd~emDDeK', |
1027
|
|
|
'kc8SS1tzuZ~jqjlebKGrUmpe' |
1028
|
|
|
]; |
1029
|
|
|
$this->client->setTeamTasks($taskIds, 'E4s6bwGpOZp6pSU3Hz*2ngFA'); |
1030
|
|
|
|
1031
|
|
|
$this->assertRequestIsPut('containers/teams/E4s6bwGpOZp6pSU3Hz*2ngFA', [ |
1032
|
|
|
'tasks' => $taskIds |
1033
|
|
|
]); |
1034
|
|
|
} |
1035
|
|
|
|
1036
|
|
|
/** |
1037
|
|
|
* @covers OnFleet\Client::setWorkerTasks |
1038
|
|
|
*/ |
1039
|
|
|
public function testSettingWorkerTasks() |
1040
|
|
|
{ |
1041
|
|
|
$this->mockedResponses |
1042
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'])); |
1043
|
|
|
|
1044
|
|
|
$taskIds = [ |
1045
|
|
|
'11z1BbsQUZFHD1XAd~emDDeK', |
1046
|
|
|
'kc8SS1tzuZ~jqjlebKGrUmpe' |
1047
|
|
|
]; |
1048
|
|
|
$this->client->setWorkerTasks($taskIds, 'h*wSb*apKlDkUFnuLTtjPke7'); |
1049
|
|
|
|
1050
|
|
|
$this->assertRequestIsPut('containers/workers/h*wSb*apKlDkUFnuLTtjPke7', [ |
1051
|
|
|
'tasks' => $taskIds |
1052
|
|
|
]); |
1053
|
|
|
} |
1054
|
|
|
|
1055
|
|
|
/** |
1056
|
|
|
* @covers OnFleet\Client::addTasksToOrganization |
1057
|
|
|
*/ |
1058
|
|
|
public function testAddingTasksToOrganization() |
1059
|
|
|
{ |
1060
|
|
|
$this->mockedResponses |
1061
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'])); |
1062
|
|
|
|
1063
|
|
|
$taskIds = [ |
1064
|
|
|
'11z1BbsQUZFHD1XAd~emDDeK', |
1065
|
|
|
'kc8SS1tzuZ~jqjlebKGrUmpe' |
1066
|
|
|
]; |
1067
|
|
|
$this->client->addTasksToOrganization($taskIds, 'yAM*fDkztrT3gUcz9mNDgNOL'); |
1068
|
|
|
|
1069
|
|
|
$this->assertRequestIsPut('containers/organizations/yAM*fDkztrT3gUcz9mNDgNOL', [ |
1070
|
|
|
'tasks' => [ |
1071
|
|
|
-1, |
1072
|
|
|
'11z1BbsQUZFHD1XAd~emDDeK', |
1073
|
|
|
'kc8SS1tzuZ~jqjlebKGrUmpe' |
1074
|
|
|
] |
1075
|
|
|
]); |
1076
|
|
|
} |
1077
|
|
|
|
1078
|
|
|
/** |
1079
|
|
|
* @covers OnFleet\Client::addTasksToTeam |
1080
|
|
|
*/ |
1081
|
|
|
public function testAddingTasksToTeam() |
1082
|
|
|
{ |
1083
|
|
|
$this->mockedResponses |
1084
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'])); |
1085
|
|
|
|
1086
|
|
|
$taskIds = [ |
1087
|
|
|
'11z1BbsQUZFHD1XAd~emDDeK', |
1088
|
|
|
'kc8SS1tzuZ~jqjlebKGrUmpe' |
1089
|
|
|
]; |
1090
|
|
|
$this->client->addTasksToTeam($taskIds, 'E4s6bwGpOZp6pSU3Hz*2ngFA'); |
1091
|
|
|
|
1092
|
|
|
$this->assertRequestIsPut('containers/teams/E4s6bwGpOZp6pSU3Hz*2ngFA', [ |
1093
|
|
|
'tasks' => [ |
1094
|
|
|
-1, |
1095
|
|
|
'11z1BbsQUZFHD1XAd~emDDeK', |
1096
|
|
|
'kc8SS1tzuZ~jqjlebKGrUmpe' |
1097
|
|
|
] |
1098
|
|
|
]); |
1099
|
|
|
} |
1100
|
|
|
|
1101
|
|
|
/** |
1102
|
|
|
* @covers OnFleet\Client::addTasksToWorker |
1103
|
|
|
*/ |
1104
|
|
|
public function testAddingTasksToWorker() |
1105
|
|
|
{ |
1106
|
|
|
$this->mockedResponses |
1107
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'])); |
1108
|
|
|
|
1109
|
|
|
$taskIds = [ |
1110
|
|
|
'11z1BbsQUZFHD1XAd~emDDeK', |
1111
|
|
|
'kc8SS1tzuZ~jqjlebKGrUmpe' |
1112
|
|
|
]; |
1113
|
|
|
$this->client->addTasksToWorker($taskIds, 'h*wSb*apKlDkUFnuLTtjPke7'); |
1114
|
|
|
|
1115
|
|
|
$this->assertRequestIsPut('containers/workers/h*wSb*apKlDkUFnuLTtjPke7', [ |
1116
|
|
|
'tasks' => [ |
1117
|
|
|
-1, |
1118
|
|
|
'11z1BbsQUZFHD1XAd~emDDeK', |
1119
|
|
|
'kc8SS1tzuZ~jqjlebKGrUmpe' |
1120
|
|
|
] |
1121
|
|
|
]); |
1122
|
|
|
} |
1123
|
|
|
|
1124
|
|
|
/** |
1125
|
|
|
* @covers OnFleet\Client::createWebhook |
1126
|
|
|
* @covers OnFleet\Webhook |
1127
|
|
|
*/ |
1128
|
|
|
public function testCreatingWebhookReturnsWebhook() |
1129
|
|
|
{ |
1130
|
|
|
$this->mockedResponses |
1131
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
1132
|
|
|
{ |
1133
|
|
|
"id": "9zqMxI79mRcHpXE111nILiPn", |
1134
|
|
|
"count": 0, |
1135
|
|
|
"url": "http://requestb.in/11sl22k1", |
1136
|
|
|
"trigger": 6 |
1137
|
|
|
} |
1138
|
|
|
'))); |
1139
|
|
|
|
1140
|
|
|
$webhook = $this->client->createWebhook('http://requestb.in/11sl22k1', Webhook::TRIGGER_TASK_CREATED); |
1141
|
|
|
|
1142
|
|
|
$this->assertRequestIsPost('webhooks', [ |
1143
|
|
|
'url' => 'http://requestb.in/11sl22k1', |
1144
|
|
|
'trigger' => 6 |
1145
|
|
|
]); |
1146
|
|
|
$this->assertInstanceOf(Webhook::class, $webhook); |
1147
|
|
|
$this->assertEquals('http://requestb.in/11sl22k1', $webhook->getUrl()); |
1148
|
|
|
$this->assertEquals(6, $webhook->getTrigger()); |
1149
|
|
|
} |
1150
|
|
|
/** |
1151
|
|
|
* @covers OnFleet\Client::getWebhooks |
1152
|
|
|
* @covers OnFleet\Webhook |
1153
|
|
|
*/ |
1154
|
|
|
public function testGettingWebhookReturnsArrayOfWebhooks() |
1155
|
|
|
{ |
1156
|
|
|
$this->mockedResponses |
1157
|
|
|
->addResponse(new Response(200, ['Content-type' => 'application/json'], Stream::factory(' |
1158
|
|
|
[ |
1159
|
|
|
{ |
1160
|
|
|
"id": "9zqMxI79mRcHpXE111nILiPn", |
1161
|
|
|
"count": 0, |
1162
|
|
|
"url": "http://requestb.in/11sl22k1", |
1163
|
|
|
"trigger": 6 |
1164
|
|
|
}, |
1165
|
|
|
{ |
1166
|
|
|
"id": "9zqMxI79mRcHpXE111nILiPn", |
1167
|
|
|
"count": 9, |
1168
|
|
|
"url": "http://requestb.in/11sl22k1", |
1169
|
|
|
"trigger": 2 |
1170
|
|
|
} |
1171
|
|
|
] |
1172
|
|
|
'))); |
1173
|
|
|
|
1174
|
|
|
$webhooks = $this->client->getWebhooks(); |
1175
|
|
|
|
1176
|
|
|
$this->assertRequestIsGet('webhooks'); |
1177
|
|
|
$this->assertCount(2, $webhooks); |
1178
|
|
|
$webhook = $webhooks[1]; |
1179
|
|
|
$this->assertInstanceOf(Webhook::class, $webhook); |
1180
|
|
|
$this->assertEquals('http://requestb.in/11sl22k1', $webhook->getUrl()); |
1181
|
|
|
$this->assertEquals('9zqMxI79mRcHpXE111nILiPn', $webhook->getId()); |
1182
|
|
|
$this->assertEquals(9, $webhook->getCount()); |
1183
|
|
|
$this->assertEquals(2, $webhook->getTrigger()); |
1184
|
|
|
} |
1185
|
|
|
} |
1186
|
|
|
|
This check looks for type mismatches where the missing type is
false
. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTime
object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalse
before passing on the value to another function or method that may not be able to handle afalse
.