Skip to content

Commit

Permalink
Add end point: getWorkerEta (#40)
Browse files Browse the repository at this point in the history
* Add end point: getWorkerEta

* Update npm version
  • Loading branch information
cctv1237 authored May 19, 2021
1 parent b0d72c9 commit 88e3e3a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |

Expand Down
2 changes: 1 addition & 1 deletion README.zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |

Expand Down
5 changes: 5 additions & 0 deletions lib/resources/Teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class Teams extends Resource {
path: '/teams/:teamId/dispatch',
method: 'POST',
},
getWorkerEta: {
path: '/teams/:teamId/estimate',
method: 'GET',
queryParams: true,
},
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
22 changes: 22 additions & 0 deletions test/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
18 changes: 17 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'))
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 88e3e3a

Please sign in to comment.