From 88e3e3a9b2930d0b9372e845ee52962cb08c74c7 Mon Sep 17 00:00:00 2001 From: Fan Long Date: Thu, 20 May 2021 03:53:23 +0800 Subject: [PATCH] Add end point: getWorkerEta (#40) * Add end point: getWorkerEta * Update npm version --- README.fr.md | 2 +- README.md | 2 +- README.zh-tw.md | 2 +- lib/resources/Teams.js | 5 +++++ package.json | 2 +- test/response.js | 22 ++++++++++++++++++++++ test/test.js | 18 +++++++++++++++++- 7 files changed, 48 insertions(+), 5 deletions(-) diff --git a/README.fr.md b/README.fr.md index 8198f3d..9e05e55 100644 --- a/README.fr.md +++ b/README.fr.md @@ -96,7 +96,7 @@ L'URL de base de l'API Onfleet est `https://onfleet.com/api/v2`, voici les opér | [Organization](https://docs.onfleet.com/reference#organizations) | get(), get(id) | x | insertTask(id, obj) | x | | [Recipients](https://docs.onfleet.com/reference#recipients) | get(id), get(name, 'name'), get(phone, 'phone') | create(obj), matchMetadata(obj) | update(id, obj) | x | | [Tasks](https://docs.onfleet.com/reference#tasks) | get(query), get(id), get(shortId, 'shortId') | create(obj), clone(id), forceComplete(id), batch(obj), autoAssign(obj), matchMetadata(obj) | update(id, obj) | deleteOne(id) | -| [Teams](https://docs.onfleet.com/reference#teams) | get(), get(id) | create(obj), autoDispatch(id, obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) | +| [Teams](https://docs.onfleet.com/reference#teams) | get(), get(id), getWorkerEta(id, obj) | create(obj), autoDispatch(id, obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) | | [Webhooks](https://docs.onfleet.com/reference#webhooks) | get() | create(obj) | x | deleteOne(id) | | [Workers](https://docs.onfleet.com/reference#workers) | get(), get(query), get(id), getByLocation(obj), getSchedule(id) | create(obj), setSchedule(id, obj), matchMetadata(obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) | diff --git a/README.md b/README.md index cb77a12..80956e4 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ The base URL for the Onfleet API is `https://onfleet.com/api/v2`, here are the s | [Organization](https://docs.onfleet.com/reference#organizations) | get(), get(id) | x | insertTask(id, obj) | x | | [Recipients](https://docs.onfleet.com/reference#recipients) | get(id), get(name, 'name'), get(phone, 'phone') | create(obj), matchMetadata(obj) | update(id, obj) | x | | [Tasks](https://docs.onfleet.com/reference#tasks) | get(query), get(id), get(shortId, 'shortId') | create(obj), clone(id), forceComplete(id), batch(obj), autoAssign(obj), matchMetadata(obj) | update(id, obj) | deleteOne(id) | -| [Teams](https://docs.onfleet.com/reference#teams) | get(), get(id) | create(obj), autoDispatch(id, obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) | +| [Teams](https://docs.onfleet.com/reference#teams) | get(), get(id), getWorkerEta(id, obj) | create(obj), autoDispatch(id, obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) | | [Webhooks](https://docs.onfleet.com/reference#webhooks) | get() | create(obj) | x | deleteOne(id) | | [Workers](https://docs.onfleet.com/reference#workers) | get(), get(query), get(id), getByLocation(obj), getSchedule(id) | create(obj), setSchedule(id, obj), matchMetadata(obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) | diff --git a/README.zh-tw.md b/README.zh-tw.md index ac41a43..019adc2 100644 --- a/README.zh-tw.md +++ b/README.zh-tw.md @@ -99,7 +99,7 @@ Onfleet應用程式介面的基本URL為 `https://onfleet.com/api/v2`,下面 | [Organization](https://docs.onfleet.com/reference#organizations) | get(), get(id) | x | insertTask(id, obj) | x | | [Recipients](https://docs.onfleet.com/reference#recipients) | get(id), get(name, 'name'), get(phone, 'phone') | create(obj), matchMetadata(obj) | update(id, obj) | x | | [Tasks](https://docs.onfleet.com/reference#tasks) | get(query), get(id), get(shortId, 'shortId') | create(obj), clone(id), forceComplete(id), batch(obj), autoAssign(obj), matchMetadata(obj) | update(id, obj) | deleteOne(id) | -| [Teams](https://docs.onfleet.com/reference#teams) | get(), get(id) | create(obj), autoDispatch(id, obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) | +| [Teams](https://docs.onfleet.com/reference#teams) | get(), get(id), getWorkerEta(id, obj) | create(obj), autoDispatch(id, obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) | | [Webhooks](https://docs.onfleet.com/reference#webhooks) | get() | create(obj) | x | deleteOne(id) | | [Workers](https://docs.onfleet.com/reference#workers) | get(), get(query), get(id), getByLocation(obj), getSchedule(id) | create(obj), setSchedule(id, obj), matchMetadata(obj) | update(id, obj), insertTask(id, obj) | deleteOne(id) | diff --git a/lib/resources/Teams.js b/lib/resources/Teams.js index 1682a6e..fdf228f 100644 --- a/lib/resources/Teams.js +++ b/lib/resources/Teams.js @@ -34,6 +34,11 @@ class Teams extends Resource { path: '/teams/:teamId/dispatch', method: 'POST', }, + getWorkerEta: { + path: '/teams/:teamId/estimate', + method: 'GET', + queryParams: true, + }, }); } } diff --git a/package.json b/package.json index 78147e2..627b12f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@onfleet/node-onfleet", - "version": "1.2.2", + "version": "1.2.3", "description": "Official client library for accessing the Onfleet API", "main": "index.js", "scripts": { diff --git a/test/response.js b/test/response.js index f34f14a..0e6ed9b 100644 --- a/test/response.js +++ b/test/response.js @@ -94,6 +94,28 @@ module.exports = { ], hub: 'tKxSfU7psqDQEBVn5e2VQ~*O', }, + getWorkerEta: { + workerId: '56BsmZRWAKgGGG9g0xDczl6u', + vehicle: 'CAR', + steps: [ + { + location: [101.5929671, 3.1484824], + travelTime: 1738, + distance: 21333, + serviceTime: 120, + arrivalTime: 1621339297, + completionTime: 1621341129, + }, + { + location: [101.627378, 3.1403995], + travelTime: 645, + distance: 6348, + serviceTime: 120, + arrivalTime: 1621341774, + completionTime: 1621341894, + }, + ], + }, forceComplete: { status: 200, completionDetails: { diff --git a/test/test.js b/test/test.js index cfd1f6a..260873c 100644 --- a/test/test.js +++ b/test/test.js @@ -22,6 +22,11 @@ const newTeam = { ], hub: 'tKxSfU7psqDQEBVn5e2VQ~*O', }; +const etaDetail = { + dropoffLocation: '101.627378,3.1403995', + pickupLocation: '101.5929671,3.1484824', + pickupTime: '1620965258', +}; const completionDetail = { completionDetails: { success: true, @@ -82,10 +87,13 @@ describe('HTTP Request testing', () => { nock(baseUrl) .get(uri => uri.includes('recipients')) .reply(200, response.getRecipients); - // We use the team endpoint to test createOne() + // We use the team endpoint to test createOne() and getWorkerEta() nock(baseUrl) .post(uri => uri.includes('teams')) .reply(200, response.createTeams); + nock(baseUrl) + .get(uri => uri.includes('teams')) + .reply(200, response.getWorkerEta); // We use the task endpoint to test forceComplete() nock(baseUrl) .post(uri => uri.includes('complete')) @@ -156,6 +164,14 @@ describe('HTTP Request testing', () => { assert.equal(res.name, 'Onfleet Team'); }); }); + it('Get function - worker eta of team', () => { + return onfleet.teams.getWorkerEta('SxD9Ran6pOfnUDgfTecTsgXd', etaDetail) + .then((res) => { + // Expect an object gets returned + expect(typeof res).to.equal('object'); + assert.equal(res.steps[0].arrivalTime, 1621339297); + }); + }); it('Force complete a task', () => { return onfleet.tasks.forceComplete('6Fe3qqFZ0DDwsM86zBlHJtlJ', completionDetail) .then((res) => {