dispatch-node-sdk
Advanced tools
Comparing version 2.15.0 to 2.16.0
@@ -20,3 +20,3 @@ 'use strict'; | ||
bookNewOffer: function bookNewOffer(offerData) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var accountId = offerData.accountId; | ||
@@ -23,0 +23,0 @@ var data = offerData.data; |
@@ -59,3 +59,3 @@ 'use strict'; | ||
value: function setForEntity(entityType, entityID, config) { | ||
var overwrite = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3]; | ||
var overwrite = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
@@ -62,0 +62,0 @@ return this.client.doAuthenticatedRequest('POST', '/config/' + entityType + '/' + entityID, { |
@@ -127,3 +127,3 @@ 'use strict'; | ||
function Dispatch(clientID, clientSecret) { | ||
var host = arguments.length <= 2 || arguments[2] === undefined ? 'https://api.dispatch.me' : arguments[2]; | ||
var host = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'https://api.dispatch.me'; | ||
@@ -497,3 +497,3 @@ _classCallCheck(this, Dispatch); | ||
var refreshToken = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; | ||
var refreshToken = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
@@ -521,4 +521,4 @@ return this.getNoAuthClient().post('/oauth/token', { | ||
value: function getCollection(endpoint) { | ||
var filter = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; | ||
var opts = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var filter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
@@ -551,3 +551,3 @@ var fullPath = endpoint; | ||
value: function getCollectionWithMeta(endpoint) { | ||
var filter = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; | ||
var filter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
@@ -579,3 +579,3 @@ return this.getCollection(endpoint, filter, { raw: true }).then(function (response) { | ||
value: function appendAnalyticsHeaders() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -613,4 +613,4 @@ var analytics = Object.assign({}, this.session, options.analytics); | ||
var body = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
@@ -673,3 +673,3 @@ var req = new _request2.default(method, endpoint, body, this.appendAnalyticsHeaders(options)); | ||
value: function uploadFile(file, name) { | ||
var type = arguments.length <= 2 || arguments[2] === undefined ? 'square_photo' : arguments[2]; | ||
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'square_photo'; | ||
var options = arguments[3]; | ||
@@ -696,3 +696,3 @@ | ||
value: function setSession() { | ||
var sessionVars = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var sessionVars = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -730,3 +730,3 @@ this.session = sessionVars; | ||
function getMatchedWords() { | ||
var result = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var result = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -762,3 +762,3 @@ var matches = result._highlightResult || {}; // eslint-disable-line no-underscore-dangle | ||
function arraysToStrings(obj) { | ||
var skipProps = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var skipProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
@@ -845,3 +845,3 @@ Object.getOwnPropertyNames(obj || {}).forEach(function (prop) { | ||
var appointmentInfo = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; | ||
var appointmentInfo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
@@ -848,0 +848,0 @@ var returnData = { |
@@ -18,3 +18,3 @@ 'use strict'; | ||
sendNotification: function sendNotification(appointmentProperties) { | ||
var headerOptions = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var headerOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -21,0 +21,0 @@ return client.doAuthenticatedRequest('PATCH', endpoints.APPOINTMENTS + '/' + id + '/notify', appointmentProperties, headerOptions); |
@@ -36,4 +36,4 @@ 'use strict'; | ||
value: function get() { | ||
var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -45,3 +45,3 @@ return this.client.getCollection(this.endpoint, query, opts); | ||
value: function getWithMeta() { | ||
var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -58,3 +58,3 @@ return this.client.getCollectionWithMeta(this.endpoint, query); | ||
value: function create(data) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -76,3 +76,3 @@ return this.client.doAuthenticatedRequest('POST', this.endpoint, data, options).then(function (response) { | ||
value: function update(id, data) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
@@ -79,0 +79,0 @@ return this.client.doAuthenticatedRequest('PATCH', this.getSingleEndpoint(id), data, options).then(function (response) { |
@@ -11,2 +11,6 @@ 'use strict'; | ||
var _underscore = require('underscore'); | ||
var _underscore2 = _interopRequireDefault(_underscore); | ||
var _endpoints = require('../endpoints'); | ||
@@ -18,2 +22,4 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -69,47 +75,53 @@ * Get the billing documents by doc type for a specific job. | ||
function actOnOffer(client, id, action) { | ||
var body = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var options = arguments.length <= 4 || arguments[4] === undefined ? {} : arguments[4]; | ||
var body = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; | ||
return client.entities.jobs.getOne(id).then(function (_ref2) { | ||
var uuid = _ref2.job_offer_uuid; | ||
if (action === 'accept') { | ||
// If there are orchestrator options schedule the appointment for backwards compatibility | ||
if (!_underscore2.default.isEmpty(body)) { | ||
var time = body.appointment_time; | ||
var duration = body.appointment_duration; | ||
var user_id = body.user_id; | ||
// If there is a job offer uuid associated with the job, | ||
// accept or reject the job via the job offers orchestrator. | ||
if (uuid) return client.doAuthenticatedRequest('POST', '/offers/' + uuid + '/' + action, body, options); | ||
// If there is no job offer uuid associated with the job and the action is accept, | ||
// check to see if there is a draft appointment with the same job id. | ||
// If there is an appointment, mark the job as scheduled, otherwise mark it as unscheduled. | ||
if (action === 'accept') { | ||
return client.entities.appointments.get({ filter: { job_id_eq: id, status_eq: 'draft' } }).then(function (appointments) { | ||
var promises = []; | ||
var appointment = appointments && appointments[0]; | ||
var status = appointment ? 'scheduled' : 'unscheduled'; | ||
if (time && duration) { | ||
var apptBody = { | ||
time: time, | ||
duration: duration, | ||
user_id: user_id, | ||
status: 'scheduled' | ||
}; | ||
if (appointment) { | ||
promises.push(client.doAuthenticatedRequest('PATCH', endpoints.APPOINTMENTS + '/' + appointment.id, { status: status }, options)); | ||
} | ||
promises.push(client.doAuthenticatedRequest('PATCH', endpoints.JOBS + '/' + id, { status: status }, options)); | ||
return Promise.all(promises).then(function () { | ||
// Mimic the response of the job offers orchestrator. | ||
return { status: status }; | ||
return client.doAuthenticatedRequest('POST', endpoints.APPOINTMENTS, apptBody, options).then(function () { | ||
return { status: 'scheduled' }; | ||
}); | ||
}); | ||
} | ||
} | ||
// If there is no job offer uuid associated with the job and the action is reject, | ||
// set the status of the job to rejected and append the status message. | ||
if (action === 'reject') { | ||
return client.doAuthenticatedRequest('PATCH', endpoints.JOBS + '/' + id, _extends({}, body, { | ||
status: 'rejected' | ||
}), options).then(function () { | ||
// Mimic the response of the job offers orchestrator. | ||
return { status: 'rejected' }; | ||
// Now perform Derek's logic | ||
return client.entities.appointments.get({ filter: { job_id_eq: id, status_eq: 'draft' } }).then(function (appointments) { | ||
var appointment = appointments && appointments[0]; | ||
if (appointment) { | ||
// We get the job status update events we need to passively accept just by patching the appointment | ||
return client.doAuthenticatedRequest('PATCH', endpoints.APPOINTMENTS + '/' + appointment.id, { status: 'scheduled' }, options).then(function () { | ||
return { status: 'scheduled' }; | ||
}); | ||
} | ||
return client.doAuthenticatedRequest('PATCH', endpoints.JOBS + '/' + id, { status: 'unscheduled' }, options).then(function () { | ||
return { status: 'unscheduled' }; | ||
}); | ||
} | ||
}); | ||
} | ||
return Promise.reject(new Error(action + ' is not an accepted action for a job offer.')); | ||
}); | ||
if (action === 'reject') { | ||
return client.doAuthenticatedRequest('PATCH', endpoints.JOBS + '/' + id, _extends({}, body, { | ||
status: 'rejected' | ||
}), options).then(function () { | ||
// Mimic the response of the job offers orchestrator. | ||
return { status: 'rejected' }; | ||
}); | ||
} | ||
return Promise.reject(new Error(action + ' is not an accepted action for a job offer.')); | ||
} | ||
@@ -185,3 +197,3 @@ | ||
createAppointment: function createAppointment() { | ||
var data = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments[1]; | ||
@@ -197,3 +209,3 @@ | ||
getAppointments: function getAppointments() { | ||
var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -228,3 +240,3 @@ if (query.filter) { | ||
getSurveys: function getSurveys() { | ||
var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -245,3 +257,3 @@ var DEFAULT_QUERY = { | ||
update: function update(jobProperties) { | ||
var headerOptions = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var headerOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -248,0 +260,0 @@ return client.doAuthenticatedRequest('PATCH', endpoints.JOBS + '/' + id, jobProperties, headerOptions).then(function (response) { |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -10,0 +10,0 @@ exports.default = organizationMethods; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -10,0 +10,0 @@ exports.default = userMethods; |
@@ -56,3 +56,3 @@ 'use strict'; | ||
value: function addForEntity(entityType, entityID, name) { | ||
var config = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
@@ -59,0 +59,0 @@ var body = _extends({ |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -10,0 +10,0 @@ exports.stringify = stringify; |
@@ -88,3 +88,3 @@ 'use strict'; | ||
value: function get(endpoint) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -96,3 +96,3 @@ return this.doRequest('GET', endpoint, null, options); | ||
value: function post(endpoint, body) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
@@ -104,3 +104,3 @@ return this.doRequest('POST', endpoint, body, options); | ||
value: function put(endpoint, body) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
@@ -112,3 +112,3 @@ return this.doRequest('PUT', endpoint, body, options); | ||
value: function patch(endpoint, body) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
@@ -120,3 +120,3 @@ return this.doRequest('PATCH', endpoint, body, options); | ||
value: function _delete(endpoint) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -128,4 +128,4 @@ return this.doRequest('DELETE', endpoint, null, options); | ||
value: function doRequest(method, endpoint) { | ||
var body = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
@@ -132,0 +132,0 @@ var url = this.host + endpoint; |
@@ -13,4 +13,4 @@ "use strict"; | ||
function Request(method, endpoint) { | ||
var body = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
@@ -17,0 +17,0 @@ _classCallCheck(this, Request); |
@@ -0,1 +1,3 @@ | ||
import _ from 'underscore'; | ||
import * as endpoints from '../endpoints'; | ||
@@ -50,43 +52,51 @@ | ||
function actOnOffer(client, id, action, body = {}, options = {}) { | ||
return client.entities.jobs.getOne(id).then(({ job_offer_uuid: uuid }) => { | ||
// If there is a job offer uuid associated with the job, | ||
// accept or reject the job via the job offers orchestrator. | ||
if (uuid) return client.doAuthenticatedRequest('POST', `/offers/${uuid}/${action}`, body, options); | ||
if (action === 'accept') { | ||
// If there are orchestrator options schedule the appointment for backwards compatibility | ||
if (!_.isEmpty(body)) { | ||
const { appointment_time: time, appointment_duration: duration, user_id } = body; | ||
// If there is no job offer uuid associated with the job and the action is accept, | ||
// check to see if there is a draft appointment with the same job id. | ||
// If there is an appointment, mark the job as scheduled, otherwise mark it as unscheduled. | ||
if (action === 'accept') { | ||
return client.entities.appointments.get({ filter: { job_id_eq: id, status_eq: 'draft' } }).then(appointments => { | ||
const promises = []; | ||
const appointment = appointments && appointments[0]; | ||
const status = appointment ? 'scheduled' : 'unscheduled'; | ||
if (time && duration) { | ||
const apptBody = { | ||
time, | ||
duration, | ||
user_id, | ||
status: 'scheduled', | ||
}; | ||
if (appointment) { | ||
promises.push(client.doAuthenticatedRequest('PATCH', `${endpoints.APPOINTMENTS}/${appointment.id}`, { status }, options)); | ||
} | ||
return client.doAuthenticatedRequest('POST', endpoints.APPOINTMENTS, apptBody, options) | ||
.then(() => { | ||
return { status: 'scheduled' }; | ||
}); | ||
} | ||
} | ||
promises.push(client.doAuthenticatedRequest('PATCH', `${endpoints.JOBS}/${id}`, { status }, options)); | ||
// Now perform Derek's logic | ||
return client.entities.appointments.get({ filter: { job_id_eq: id, status_eq: 'draft' } }).then(appointments => { | ||
const appointment = appointments && appointments[0]; | ||
if (appointment) { | ||
// We get the job status update events we need to passively accept just by patching the appointment | ||
return client.doAuthenticatedRequest('PATCH', `${endpoints.APPOINTMENTS}/${appointment.id}`, { status: 'scheduled' }, options) | ||
.then(() => { | ||
return { status: 'scheduled' }; | ||
}); | ||
} | ||
return Promise.all(promises).then(() => { | ||
// Mimic the response of the job offers orchestrator. | ||
return { status }; | ||
return client.doAuthenticatedRequest('PATCH', `${endpoints.JOBS}/${id}`, { status: 'unscheduled' }, options) | ||
.then(() => { | ||
return { status: 'unscheduled' }; | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
// If there is no job offer uuid associated with the job and the action is reject, | ||
// set the status of the job to rejected and append the status message. | ||
if (action === 'reject') { | ||
return client.doAuthenticatedRequest('PATCH', `${endpoints.JOBS}/${id}`, { | ||
...body, | ||
status: 'rejected', | ||
}, options).then(() => { | ||
// Mimic the response of the job offers orchestrator. | ||
return { status: 'rejected' }; | ||
}); | ||
} | ||
if (action === 'reject') { | ||
return client.doAuthenticatedRequest('PATCH', `${endpoints.JOBS}/${id}`, { | ||
...body, | ||
status: 'rejected', | ||
}, options).then(() => { | ||
// Mimic the response of the job offers orchestrator. | ||
return { status: 'rejected' }; | ||
}); | ||
} | ||
return Promise.reject(new Error(`${action} is not an accepted action for a job offer.`)); | ||
}); | ||
return Promise.reject(new Error(`${action} is not an accepted action for a job offer.`)); | ||
} | ||
@@ -93,0 +103,0 @@ |
@@ -337,143 +337,74 @@ import expect from 'expect'; | ||
describe('offer actions', () => { | ||
it('should accept the job via the job offers orchestrator if there is a job_offer_uuid', done => { | ||
const testJob = { | ||
id: 123, | ||
organization_id: 456, | ||
job_offer_uuid: 'test', | ||
}; | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
describe('accepting', () => { | ||
it('should patch job to unscheduled if accepting offer', () => { | ||
const appointmentGetRequest = nock('https://api.dispatch.me') | ||
.get(`${endpoints.APPOINTMENTS}?filter[job_id_eq]=123&filter[status_eq]=draft`) | ||
.reply(200, { appointments: [] }); | ||
const jobPatchRequest = nock('https://api.dispatch.me') | ||
.patch(`${endpoints.JOBS}/123`, { status: 'unscheduled' }) | ||
.reply(200, { status: 'unscheduled' }); | ||
const jobGetRequest = nock('https://api.dispatch.me') | ||
.get(`${endpoints.JOBS}?filter[id_eq]=123`) | ||
.reply(200, { jobs: [testJob] }); | ||
const offersPostRequest = nock('https://api.dispatch.me') | ||
.post('/offers/test/accept') | ||
.reply(200, { status: 'accepted' }); | ||
client.entities.job(123).accept().then(response => { | ||
expect(jobGetRequest.isDone()).toEqual(true); | ||
expect(offersPostRequest.isDone()).toEqual(true); | ||
expect(response.status).toEqual('accepted'); | ||
done(); | ||
client.entities.job(123).accept().then(response => { | ||
expect(appointmentGetRequest.isDone()).toEqual(true); | ||
expect(jobPatchRequest.isDone()).toEqual(true); | ||
expect(response.status).toEqual('unscheduled'); | ||
}); | ||
}); | ||
}); | ||
it('should set the job status to unscheduled via the core API if there is not a job_offer_uuid and no associated appointments', done => { | ||
const testJob = { | ||
id: 123, | ||
organization_id: 456, | ||
job_offer_uuid: null, | ||
}; | ||
it('should schedule appointment if accepting with orchestrator request body', () => { | ||
const body = { | ||
time: 'someiso', | ||
duration: 7200, | ||
}; | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
const apptPostRequest = nock('https://api.dispatch.me') | ||
.post(`${endpoints.APPOINTMENTS}`) | ||
.reply(200, { id: 555, status: 'scheduled' }); | ||
const jobGetRequest = nock('https://api.dispatch.me') | ||
.get(`${endpoints.JOBS}?filter[id_eq]=123`) | ||
.reply(200, { jobs: [testJob] }); | ||
const appointmentGetRequest = nock('https://api.dispatch.me') | ||
.get(`${endpoints.APPOINTMENTS}?filter[job_id_eq]=123&filter[status_eq]=draft`) | ||
.reply(200, { appointments: [] }); | ||
const jobPatchRequest = nock('https://api.dispatch.me') | ||
.patch(`${endpoints.JOBS}/123`, { status: 'unscheduled' }) | ||
.reply(200, { status: 'unscheduled' }); | ||
client.entities.job(123).accept().then(response => { | ||
expect(jobGetRequest.isDone()).toEqual(true); | ||
expect(appointmentGetRequest.isDone()).toEqual(true); | ||
expect(jobPatchRequest.isDone()).toEqual(true); | ||
expect(response.status).toEqual('unscheduled'); | ||
done(); | ||
client.entities.job(123).accept(null, body).then(response => { | ||
expect(apptPostRequest.isDone()).toEqual(true); | ||
expect(response.status).toEqual('scheduled'); | ||
}); | ||
}); | ||
}); | ||
it('should set the job status to scheduled and the associated appointment status to scheduled via the core API if there is not a job_offer_uuid', done => { | ||
const testJob = { | ||
id: 123, | ||
organization_id: 456, | ||
job_offer_uuid: null, | ||
}; | ||
it('should patch draft appointment if there are any on the offer', () => { | ||
const appointmentGetRequest = nock('https://api.dispatch.me') | ||
.get(`${endpoints.APPOINTMENTS}?filter[job_id_eq]=123&filter[status_eq]=draft`) | ||
.reply(200, { appointments: [{ id: 555, status: 'draft' }] }); | ||
const apptPatchRequest = nock('https://api.dispatch.me') | ||
.patch(`${endpoints.APPOINTMENTS}/555`, { status: 'scheduled' }) | ||
.reply(200, { status: 'scheduled' }); | ||
const testAppointment = { | ||
id: 678, | ||
organization_id: 456, | ||
job_id: 123, | ||
status: 'draft', | ||
}; | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
const jobGetRequest = nock('https://api.dispatch.me') | ||
.get(`${endpoints.JOBS}?filter[id_eq]=123`) | ||
.reply(200, { jobs: [testJob] }); | ||
const appointmentGetRequest = nock('https://api.dispatch.me') | ||
.get(`${endpoints.APPOINTMENTS}?filter[job_id_eq]=123&filter[status_eq]=draft`) | ||
.reply(200, { appointments: [testAppointment] }); | ||
const jobPatchRequest = nock('https://api.dispatch.me') | ||
.patch(`${endpoints.JOBS}/123`, { status: 'scheduled' }) | ||
.reply(200, { status: 'scheduled' }); | ||
const appointmentPatchRequest = nock('https://api.dispatch.me') | ||
.patch(`${endpoints.APPOINTMENTS}/678`, { status: 'scheduled' }) | ||
.reply(200, { status: 'scheduled' }); | ||
client.entities.job(123).accept().then(response => { | ||
expect(jobGetRequest.isDone()).toEqual(true); | ||
expect(appointmentGetRequest.isDone()).toEqual(true); | ||
expect(jobPatchRequest.isDone()).toEqual(true); | ||
expect(appointmentPatchRequest.isDone()).toEqual(true); | ||
expect(response.status).toEqual('scheduled'); | ||
done(); | ||
client.entities.job(123).accept().then(response => { | ||
expect(appointmentGetRequest.isDone()).toEqual(true); | ||
expect(apptPatchRequest.isDone()).toEqual(true); | ||
expect(response.status).toEqual('scheduled'); | ||
}); | ||
}); | ||
}); | ||
it('should reject the job via the job offers orchestrator if there is a job_offer_uuid', done => { | ||
const testJob = { | ||
id: 123, | ||
organization_id: 456, | ||
job_offer_uuid: 'test', | ||
}; | ||
describe('rejecting', () => { | ||
it('with status message should patch job to rejected', () => { | ||
const jobPatchRequest = nock('https://api.dispatch.me') | ||
.patch(`${endpoints.JOBS}/123`, { status: 'rejected' }) | ||
.reply(200, { status: 'rejected' }); | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
const jobGetRequest = nock('https://api.dispatch.me') | ||
.get(`${endpoints.JOBS}?filter[id_eq]=123`) | ||
.reply(200, { jobs: [testJob] }); | ||
const offersPostRequest = nock('https://api.dispatch.me') | ||
.post('/offers/test/reject', { status_message: 'wrong_trade' }) | ||
.reply(200, { status: 'rejected' }); | ||
client.entities.job(123).reject('wrong_trade').then(response => { | ||
expect(jobGetRequest.isDone()).toEqual(true); | ||
expect(offersPostRequest.isDone()).toEqual(true); | ||
expect(response.status).toEqual('rejected'); | ||
done(); | ||
client.entities.job(123).reject('uhh').then(response => { | ||
expect(jobPatchRequest.isDone()).toEqual(true); | ||
expect(response.status).toEqual('scheduled'); | ||
}); | ||
}); | ||
}); | ||
it('should reject the job via the core API if there is not a job_offer_uuid', done => { | ||
const testJob = { | ||
id: 123, | ||
organization_id: 456, | ||
job_offer_uuid: null, | ||
}; | ||
it('without status message should patch job to rejected', () => { | ||
const jobPatchRequest = nock('https://api.dispatch.me') | ||
.patch(`${endpoints.JOBS}/123`, { status: 'rejected' }) | ||
.reply(200, { status: 'rejected' }); | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
const jobGetRequest = nock('https://api.dispatch.me') | ||
.get(`${endpoints.JOBS}?filter[id_eq]=123`) | ||
.reply(200, { jobs: [testJob] }); | ||
const jobPatchRequest = nock('https://api.dispatch.me') | ||
.patch(`${endpoints.JOBS}/123`, { status: 'rejected', status_message: 'wrong_trade' }) | ||
.reply(200, { status: 'rejected' }); | ||
client.entities.job(123).reject('wrong_trade').then(response => { | ||
expect(jobGetRequest.isDone()).toEqual(true); | ||
expect(jobPatchRequest.isDone()).toEqual(true); | ||
expect(response.status).toEqual('rejected'); | ||
done(); | ||
client.entities.job(123).reject().then(response => { | ||
expect(jobPatchRequest.isDone()).toEqual(true); | ||
expect(response.status).toEqual('scheduled'); | ||
}); | ||
}); | ||
@@ -480,0 +411,0 @@ }); |
{ | ||
"name": "dispatch-node-sdk", | ||
"version": "2.15.0", | ||
"version": "2.16.0", | ||
"description": "High- and low-level libraries for interacting with the Dispatch API", | ||
@@ -5,0 +5,0 @@ "main": "dist/lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
278489
6961
2