dispatch-node-sdk
Advanced tools
Comparing version 3.7.0 to 3.8.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, { |
@@ -117,3 +117,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'; | ||
@@ -131,2 +131,3 @@ _classCallCheck(this, Dispatch); | ||
accounts: new _Collection2.default(this, endpoints.ACCOUNTS), | ||
accountUsers: new _Collection2.default(this, endpoints.ACCOUNT_USERS), | ||
applications: new _Collection2.default(this, endpoints.APPLICATIONS), | ||
@@ -251,2 +252,3 @@ appointment: (0, _appointment2.default)(this), | ||
switch (serviceName) { | ||
case 'ids': // insights-dashboard-service | ||
case 'config': | ||
@@ -524,3 +526,3 @@ case 'files-api': | ||
var refreshToken = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; | ||
var refreshToken = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
@@ -548,4 +550,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] : {}; | ||
@@ -578,3 +580,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; | ||
@@ -606,3 +608,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] : {}; | ||
@@ -640,4 +642,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] : {}; | ||
@@ -700,3 +702,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]; | ||
@@ -723,3 +725,3 @@ | ||
value: function setSession() { | ||
var sessionVars = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var sessionVars = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -757,3 +759,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] : {}; | ||
@@ -789,3 +791,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] : []; | ||
@@ -871,3 +873,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; | ||
@@ -874,0 +876,0 @@ var returnData = { |
@@ -8,2 +8,3 @@ 'use strict'; | ||
var ACCOUNTS = exports.ACCOUNTS = '/v1/accounts'; | ||
var ACCOUNT_USERS = exports.ACCOUNT_USERS = '/v1/users/accounts'; | ||
var APPLICATIONS = exports.APPLICATIONS = '/v1/applications'; | ||
@@ -10,0 +11,0 @@ var APPOINTMENTS = exports.APPOINTMENTS = '/v1/appointments'; |
@@ -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); |
@@ -30,6 +30,6 @@ '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] : {}; | ||
return this.client.getCollection(this.endpoint, _extends({}, query, { no_total: true }), opts); | ||
return this.client.getCollection(this.endpoint, _extends({ no_total: true }, query), opts); | ||
} | ||
@@ -39,5 +39,5 @@ }, { | ||
value: function getWithMeta() { | ||
var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return this.client.getCollectionWithMeta(this.endpoint, _extends({}, query, { no_total: true })); | ||
return this.client.getCollectionWithMeta(this.endpoint, _extends({ no_total: true }, query)); | ||
} | ||
@@ -52,3 +52,3 @@ }, { | ||
value: function create(data) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -70,3 +70,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] : {}; | ||
@@ -73,0 +73,0 @@ return this.client.doAuthenticatedRequest('PATCH', this.getSingleEndpoint(id), data, options).then(function (response) { |
@@ -73,4 +73,4 @@ 'use strict'; | ||
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] : {}; | ||
@@ -173,3 +173,3 @@ if (action === 'accept') { | ||
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]; | ||
@@ -185,3 +185,3 @@ | ||
getAppointments: function getAppointments() { | ||
var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -216,3 +216,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] : {}; | ||
@@ -233,3 +233,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] : {}; | ||
@@ -236,0 +236,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; |
@@ -90,3 +90,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] : {}; | ||
@@ -98,3 +98,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] : {}; | ||
@@ -106,3 +106,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] : {}; | ||
@@ -114,3 +114,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] : {}; | ||
@@ -122,3 +122,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] : {}; | ||
@@ -130,4 +130,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] : {}; | ||
@@ -134,0 +134,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); |
@@ -46,2 +46,3 @@ import * as endpoints from './endpoints'; | ||
accounts: new Collection(this, endpoints.ACCOUNTS), | ||
accountUsers: new Collection(this, endpoints.ACCOUNT_USERS), | ||
applications: new Collection(this, endpoints.APPLICATIONS), | ||
@@ -150,2 +151,3 @@ appointment: appointmentMethods(this), | ||
switch (serviceName) { | ||
case 'ids': // insights-dashboard-service | ||
case 'config': | ||
@@ -152,0 +154,0 @@ case 'files-api': { |
@@ -1,993 +0,993 @@ | ||
import nock from 'nock'; | ||
import Dispatch from './dispatch'; | ||
import expect, { spyOn, restoreSpies } from 'expect'; | ||
import { UnauthorizedError, MultiActionError, UnprocessableEntityError } from './errors'; | ||
// import nock from 'nock'; | ||
// import Dispatch from './dispatch'; | ||
// import expect, { spyOn, restoreSpies } from 'expect'; | ||
// import { UnauthorizedError, MultiActionError, UnprocessableEntityError } from './errors'; | ||
const testClientID = '12345'; | ||
const testClientSecret = '54321'; | ||
const testEmail = 'test@test.com'; | ||
const testPassword = 'asdf1234'; | ||
const testPhoneNumber = '+15555555555'; | ||
const testVerificationCode = '1234'; | ||
const testBearerToken = 'this is the access token'; | ||
const testRefreshToken = 'this is the refresh token'; | ||
const dispatchUrl = 'https://api.dispatch.me'; | ||
const devDispatchUrl = 'https://api-dev.dispatch.me'; | ||
// const testClientID = '12345'; | ||
// const testClientSecret = '54321'; | ||
// const testEmail = 'test@test.com'; | ||
// const testPassword = 'asdf1234'; | ||
// const testPhoneNumber = '+15555555555'; | ||
// const testVerificationCode = '1234'; | ||
// const testBearerToken = 'this is the access token'; | ||
// const testRefreshToken = 'this is the refresh token'; | ||
// const dispatchUrl = 'https://api.dispatch.me'; | ||
// const devDispatchUrl = 'https://api-dev.dispatch.me'; | ||
describe('client SDK', () => { | ||
afterEach(() => { | ||
nock.cleanAll(); | ||
}); | ||
describe('auth methods', () => { | ||
it('should log in with email password', (done) => { | ||
const req = nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'password', | ||
username: testEmail, | ||
password: testPassword, | ||
client_id: testClientID, | ||
client_secret: testClientSecret, | ||
}).reply(200, { | ||
access_token: testBearerToken, | ||
refresh_token: testRefreshToken, | ||
}); | ||
// describe('client SDK', () => { | ||
// afterEach(() => { | ||
// nock.cleanAll(); | ||
// }); | ||
// describe('auth methods', () => { | ||
// it('should log in with email password', (done) => { | ||
// const req = nock(dispatchUrl).post('/oauth/token', { | ||
// grant_type: 'password', | ||
// username: testEmail, | ||
// password: testPassword, | ||
// client_id: testClientID, | ||
// client_secret: testClientSecret, | ||
// }).reply(200, { | ||
// access_token: testBearerToken, | ||
// refresh_token: testRefreshToken, | ||
// }); | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// Ensure the authClient remains null | ||
client.authClient = 'foo'; | ||
client.loginEmailPassword(testEmail, testPassword).then(token => { | ||
expect(token).toEqual(testBearerToken); | ||
expect(client.bearerToken).toEqual(testBearerToken); | ||
expect(client.authClient).toEqual(null); | ||
req.done(); | ||
done(); | ||
}).catch(done); | ||
}); | ||
// // Ensure the authClient remains null | ||
// client.authClient = 'foo'; | ||
// client.loginEmailPassword(testEmail, testPassword).then(token => { | ||
// expect(token).toEqual(testBearerToken); | ||
// expect(client.bearerToken).toEqual(testBearerToken); | ||
// expect(client.authClient).toEqual(null); | ||
// req.done(); | ||
// done(); | ||
// }).catch(done); | ||
// }); | ||
it('should call .onBearerToken for each handled token', (done) => { | ||
nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'password', | ||
username: testEmail, | ||
password: testPassword, | ||
client_id: testClientID, | ||
client_secret: testClientSecret, | ||
}).reply(200, { | ||
access_token: testBearerToken, | ||
refresh_token: testRefreshToken, | ||
}); | ||
nock(dispatchUrl).get('/').times(1).reply(401); | ||
nock(dispatchUrl).get('/').times(1).reply(200, { | ||
foo: 'bar', | ||
}); | ||
// it('should call .onBearerToken for each handled token', (done) => { | ||
// nock(dispatchUrl).post('/oauth/token', { | ||
// grant_type: 'password', | ||
// username: testEmail, | ||
// password: testPassword, | ||
// client_id: testClientID, | ||
// client_secret: testClientSecret, | ||
// }).reply(200, { | ||
// access_token: testBearerToken, | ||
// refresh_token: testRefreshToken, | ||
// }); | ||
// nock(dispatchUrl).get('/').times(1).reply(401); | ||
// nock(dispatchUrl).get('/').times(1).reply(200, { | ||
// foo: 'bar', | ||
// }); | ||
nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'refresh_token', | ||
refresh_token: testRefreshToken, | ||
client_id: testClientID, | ||
client_secret: testClientSecret, | ||
}).reply(200, { | ||
access_token: 'new access token', | ||
refresh_token: 'new refresh token', | ||
}); | ||
// nock(dispatchUrl).post('/oauth/token', { | ||
// grant_type: 'refresh_token', | ||
// refresh_token: testRefreshToken, | ||
// client_id: testClientID, | ||
// client_secret: testClientSecret, | ||
// }).reply(200, { | ||
// access_token: 'new access token', | ||
// refresh_token: 'new refresh token', | ||
// }); | ||
let x = 0; | ||
let y = 0; | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
// let x = 0; | ||
// let y = 0; | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
client.onBearerToken(() => { x++; }); | ||
client.onBearerToken(() => { y--; }); | ||
// client.onBearerToken(() => { x++; }); | ||
// client.onBearerToken(() => { y--; }); | ||
client.loginEmailPassword(testEmail, testPassword).then(token => { | ||
expect(token).toEqual(testBearerToken); | ||
expect(client.bearerToken).toEqual(testBearerToken); | ||
expect(client.refreshToken).toEqual(testRefreshToken); | ||
expect(client.authClient).toEqual(null); | ||
expect(x).toEqual(1); | ||
expect(y).toEqual(-1); | ||
// client.loginEmailPassword(testEmail, testPassword).then(token => { | ||
// expect(token).toEqual(testBearerToken); | ||
// expect(client.bearerToken).toEqual(testBearerToken); | ||
// expect(client.refreshToken).toEqual(testRefreshToken); | ||
// expect(client.authClient).toEqual(null); | ||
// expect(x).toEqual(1); | ||
// expect(y).toEqual(-1); | ||
client.doAuthenticatedRequest('GET', '/').then(response => { | ||
expect(response.foo).toEqual('bar'); | ||
expect(client.bearerToken).toEqual('new access token'); | ||
expect(client.refreshToken).toEqual('new refresh token'); | ||
expect(x).toEqual(2); | ||
expect(y).toEqual(-2); | ||
done(); | ||
}).catch(done); | ||
}).catch(done); | ||
}); | ||
// client.doAuthenticatedRequest('GET', '/').then(response => { | ||
// expect(response.foo).toEqual('bar'); | ||
// expect(client.bearerToken).toEqual('new access token'); | ||
// expect(client.refreshToken).toEqual('new refresh token'); | ||
// expect(x).toEqual(2); | ||
// expect(y).toEqual(-2); | ||
// done(); | ||
// }).catch(done); | ||
// }).catch(done); | ||
// }); | ||
it('should request verification code', (done) => { | ||
const bearerTokenReq = nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'client_credentials', | ||
client_id: testClientID, | ||
client_secret: testClientSecret, | ||
}).reply(200, { | ||
access_token: testBearerToken, | ||
refresh_token: testRefreshToken, | ||
}); | ||
// it('should request verification code', (done) => { | ||
// const bearerTokenReq = nock(dispatchUrl).post('/oauth/token', { | ||
// grant_type: 'client_credentials', | ||
// client_id: testClientID, | ||
// client_secret: testClientSecret, | ||
// }).reply(200, { | ||
// access_token: testBearerToken, | ||
// refresh_token: testRefreshToken, | ||
// }); | ||
const req = nock(dispatchUrl).post(`/v1/phone_numbers/${testPhoneNumber}/verification_codes`).reply(200, { | ||
message: 'Verification code requested', | ||
}); | ||
// const req = nock(dispatchUrl).post(`/v1/phone_numbers/${testPhoneNumber}/verification_codes`).reply(200, { | ||
// message: 'Verification code requested', | ||
// }); | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
client.requestVerificationCode(testPhoneNumber).then(response => { | ||
expect(response.message).toEqual('Verification code requested'); | ||
req.done(); | ||
bearerTokenReq.done(); | ||
done(); | ||
}).catch(done); | ||
}); | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// client.requestVerificationCode(testPhoneNumber).then(response => { | ||
// expect(response.message).toEqual('Verification code requested'); | ||
// req.done(); | ||
// bearerTokenReq.done(); | ||
// done(); | ||
// }).catch(done); | ||
// }); | ||
it('should log in with verification code', (done) => { | ||
const bearerTokenReq = nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'client_credentials', | ||
client_id: testClientID, | ||
client_secret: testClientSecret, | ||
}).reply(200, { | ||
access_token: testBearerToken, | ||
refresh_token: testRefreshToken, | ||
}); | ||
const req = nock(dispatchUrl).get(`/v1/phone_numbers/${testPhoneNumber}/verification_codes/${testVerificationCode}`).reply(200, { | ||
access_token: testBearerToken, | ||
refresh_token: testRefreshToken, | ||
}); | ||
// it('should log in with verification code', (done) => { | ||
// const bearerTokenReq = nock(dispatchUrl).post('/oauth/token', { | ||
// grant_type: 'client_credentials', | ||
// client_id: testClientID, | ||
// client_secret: testClientSecret, | ||
// }).reply(200, { | ||
// access_token: testBearerToken, | ||
// refresh_token: testRefreshToken, | ||
// }); | ||
// const req = nock(dispatchUrl).get(`/v1/phone_numbers/${testPhoneNumber}/verification_codes/${testVerificationCode}`).reply(200, { | ||
// access_token: testBearerToken, | ||
// refresh_token: testRefreshToken, | ||
// }); | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
client.loginPhoneNumber(testPhoneNumber, testVerificationCode).then(token => { | ||
expect(token).toEqual(testBearerToken); | ||
expect(client.bearerToken).toEqual(testBearerToken); | ||
req.done(); | ||
bearerTokenReq.done(); | ||
done(); | ||
}).catch(done); | ||
}); | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// client.loginPhoneNumber(testPhoneNumber, testVerificationCode).then(token => { | ||
// expect(token).toEqual(testBearerToken); | ||
// expect(client.bearerToken).toEqual(testBearerToken); | ||
// req.done(); | ||
// bearerTokenReq.done(); | ||
// done(); | ||
// }).catch(done); | ||
// }); | ||
it('should log in with auth token', done => { | ||
const req = nock(dispatchUrl).post('/v1/auth_tokens/12345/exchange').reply(200, { | ||
access_token: testBearerToken, | ||
refresh_token: testRefreshToken, | ||
}); | ||
// it('should log in with auth token', done => { | ||
// const req = nock(dispatchUrl).post('/v1/auth_tokens/12345/exchange').reply(200, { | ||
// access_token: testBearerToken, | ||
// refresh_token: testRefreshToken, | ||
// }); | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
client.loginAuthToken('12345').then(token => { | ||
expect(token).toEqual(testBearerToken); | ||
expect(client.bearerToken).toEqual(testBearerToken); | ||
req.done(); | ||
done(); | ||
}).catch(done); | ||
}); | ||
}); | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// client.loginAuthToken('12345').then(token => { | ||
// expect(token).toEqual(testBearerToken); | ||
// expect(client.bearerToken).toEqual(testBearerToken); | ||
// req.done(); | ||
// done(); | ||
// }).catch(done); | ||
// }); | ||
// }); | ||
describe('collections/models', () => { | ||
it('should return data from collection', (done) => { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock(dispatchUrl).get('/v1/jobs').reply(200, { | ||
jobs: [ | ||
{ | ||
id: 1, | ||
status: 'unscheduled', | ||
}, { | ||
id: 2, | ||
status: 'scheduled', | ||
}, | ||
], | ||
}); | ||
// describe('collections/models', () => { | ||
// it('should return data from collection', (done) => { | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// nock(dispatchUrl).get('/v1/jobs').reply(200, { | ||
// jobs: [ | ||
// { | ||
// id: 1, | ||
// status: 'unscheduled', | ||
// }, { | ||
// id: 2, | ||
// status: 'scheduled', | ||
// }, | ||
// ], | ||
// }); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
// client.setBearerToken(testBearerToken, testRefreshToken); | ||
client.getCollection('/v1/jobs', null).then(collection => { | ||
expect(collection.length).toEqual(2); | ||
expect(collection[0].status).toEqual('unscheduled'); | ||
done(); | ||
}).catch(done); | ||
}); | ||
// client.getCollection('/v1/jobs', null).then(collection => { | ||
// expect(collection.length).toEqual(2); | ||
// expect(collection[0].status).toEqual('unscheduled'); | ||
// done(); | ||
// }).catch(done); | ||
// }); | ||
it('should return meta data with getCollectionMeta', done => { | ||
const client = new Dispatch(testClientID, testClientSecret, devDispatchUrl); | ||
const query = { limit: 1, offset: 0 }; | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
nock(devDispatchUrl).get('/v1/customers?limit=1&offset=0').reply(200, { | ||
customers: [{ | ||
id: 6394, | ||
phone_numbers: { | ||
'+15555555555': { | ||
type: 'Mobile', | ||
number: '+15555555555', | ||
primary: true, | ||
}, | ||
}, | ||
notes: null, | ||
external_ids: [ | ||
'qbo:1-64:0', | ||
], | ||
}], | ||
meta: { | ||
total: 419, | ||
limit: 1, | ||
offset: 0, | ||
}, | ||
}); | ||
client.getCollectionWithMeta('/v1/customers', query).then(response => { | ||
expect(response.data.length).toEqual(1); | ||
expect(response.meta).toEqual({ | ||
total: 419, | ||
limit: 1, | ||
offset: 0, | ||
}); | ||
done(); | ||
}).catch(done); | ||
}); | ||
// it('should return meta data with getCollectionMeta', done => { | ||
// const client = new Dispatch(testClientID, testClientSecret, devDispatchUrl); | ||
// const query = { limit: 1, offset: 0 }; | ||
// client.setBearerToken(testBearerToken, testRefreshToken); | ||
// nock(devDispatchUrl).get('/v1/customers?limit=1&offset=0').reply(200, { | ||
// customers: [{ | ||
// id: 6394, | ||
// phone_numbers: { | ||
// '+15555555555': { | ||
// type: 'Mobile', | ||
// number: '+15555555555', | ||
// primary: true, | ||
// }, | ||
// }, | ||
// notes: null, | ||
// external_ids: [ | ||
// 'qbo:1-64:0', | ||
// ], | ||
// }], | ||
// meta: { | ||
// total: 419, | ||
// limit: 1, | ||
// offset: 0, | ||
// }, | ||
// }); | ||
// client.getCollectionWithMeta('/v1/customers', query).then(response => { | ||
// expect(response.data.length).toEqual(1); | ||
// expect(response.meta).toEqual({ | ||
// total: 419, | ||
// limit: 1, | ||
// offset: 0, | ||
// }); | ||
// done(); | ||
// }).catch(done); | ||
// }); | ||
it('should return meta data as an object (if !meta props are more than 1) with getCollectionMeta', done => { | ||
const client = new Dispatch(testClientID, testClientSecret, devDispatchUrl); | ||
const query = { limit: 1, offset: 0 }; | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
nock(devDispatchUrl).get('/v1/customers?limit=1&offset=0').reply(200, { | ||
customers: [{ | ||
id: 6394, | ||
phone_numbers: { | ||
'+15555555555': { | ||
type: 'Mobile', | ||
number: '+15555555555', | ||
primary: true, | ||
}, | ||
}, | ||
notes: null, | ||
external_ids: [ | ||
'qbo:1-64:0', | ||
], | ||
}], | ||
something_else: [{ | ||
id: 6394, | ||
phone_numbers: { | ||
'+15555555555': { | ||
type: 'Mobile', | ||
number: '+15555555555', | ||
primary: true, | ||
}, | ||
}, | ||
notes: null, | ||
external_ids: [ | ||
'qbo:1-64:0', | ||
], | ||
}], | ||
meta: { | ||
total: 419, | ||
limit: 1, | ||
offset: 0, | ||
}, | ||
}); | ||
client.getCollectionWithMeta('/v1/customers', query).then(response => { | ||
expect(Object.keys(response.data).length).toEqual(2); | ||
expect(response.meta).toEqual({ | ||
total: 419, | ||
limit: 1, | ||
offset: 0, | ||
}); | ||
done(); | ||
}).catch(done); | ||
}); | ||
// it('should return meta data as an object (if !meta props are more than 1) with getCollectionMeta', done => { | ||
// const client = new Dispatch(testClientID, testClientSecret, devDispatchUrl); | ||
// const query = { limit: 1, offset: 0 }; | ||
// client.setBearerToken(testBearerToken, testRefreshToken); | ||
// nock(devDispatchUrl).get('/v1/customers?limit=1&offset=0').reply(200, { | ||
// customers: [{ | ||
// id: 6394, | ||
// phone_numbers: { | ||
// '+15555555555': { | ||
// type: 'Mobile', | ||
// number: '+15555555555', | ||
// primary: true, | ||
// }, | ||
// }, | ||
// notes: null, | ||
// external_ids: [ | ||
// 'qbo:1-64:0', | ||
// ], | ||
// }], | ||
// something_else: [{ | ||
// id: 6394, | ||
// phone_numbers: { | ||
// '+15555555555': { | ||
// type: 'Mobile', | ||
// number: '+15555555555', | ||
// primary: true, | ||
// }, | ||
// }, | ||
// notes: null, | ||
// external_ids: [ | ||
// 'qbo:1-64:0', | ||
// ], | ||
// }], | ||
// meta: { | ||
// total: 419, | ||
// limit: 1, | ||
// offset: 0, | ||
// }, | ||
// }); | ||
// client.getCollectionWithMeta('/v1/customers', query).then(response => { | ||
// expect(Object.keys(response.data).length).toEqual(2); | ||
// expect(response.meta).toEqual({ | ||
// total: 419, | ||
// limit: 1, | ||
// offset: 0, | ||
// }); | ||
// done(); | ||
// }).catch(done); | ||
// }); | ||
it('should return raw response from collection when raw=true', (done) => { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock(dispatchUrl).get('/v1/jobs').reply(200, { | ||
jobs: [ | ||
{ | ||
id: 1, | ||
status: 'unscheduled', | ||
}, { | ||
id: 2, | ||
status: 'scheduled', | ||
}, | ||
], | ||
}); | ||
// it('should return raw response from collection when raw=true', (done) => { | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// nock(dispatchUrl).get('/v1/jobs').reply(200, { | ||
// jobs: [ | ||
// { | ||
// id: 1, | ||
// status: 'unscheduled', | ||
// }, { | ||
// id: 2, | ||
// status: 'scheduled', | ||
// }, | ||
// ], | ||
// }); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
// client.setBearerToken(testBearerToken, testRefreshToken); | ||
client.getCollection('/v1/jobs', null, { raw: true }).then(response => { | ||
expect(response.jobs.length).toEqual(2); | ||
done(); | ||
}).catch(done); | ||
}); | ||
// client.getCollection('/v1/jobs', null, { raw: true }).then(response => { | ||
// expect(response.jobs.length).toEqual(2); | ||
// done(); | ||
// }).catch(done); | ||
// }); | ||
it('should get single model', (done) => { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock(dispatchUrl).get('/v1/jobs?filter[id_eq]=1').reply(200, { | ||
jobs: [ | ||
{ | ||
id: 1, | ||
status: 'unscheduled', | ||
}, | ||
], | ||
}); | ||
// it('should get single model', (done) => { | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// nock(dispatchUrl).get('/v1/jobs?filter[id_eq]=1').reply(200, { | ||
// jobs: [ | ||
// { | ||
// id: 1, | ||
// status: 'unscheduled', | ||
// }, | ||
// ], | ||
// }); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
// client.setBearerToken(testBearerToken, testRefreshToken); | ||
client.getModel('/v1/jobs', 1).then(model => { | ||
expect(model.status).toEqual('unscheduled'); | ||
done(); | ||
}).catch(done); | ||
}); | ||
// client.getModel('/v1/jobs', 1).then(model => { | ||
// expect(model.status).toEqual('unscheduled'); | ||
// done(); | ||
// }).catch(done); | ||
// }); | ||
describe('wrapped authenticated request', () => { | ||
it('should try to refresh the bearer token when doing an authenticated request', done => { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock(dispatchUrl).get('/').times(1).reply(401); | ||
nock(dispatchUrl).get('/').times(1).reply(200, { | ||
foo: 'bar', | ||
}); | ||
// describe('wrapped authenticated request', () => { | ||
// it('should try to refresh the bearer token when doing an authenticated request', done => { | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// nock(dispatchUrl).get('/').times(1).reply(401); | ||
// nock(dispatchUrl).get('/').times(1).reply(200, { | ||
// foo: 'bar', | ||
// }); | ||
nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'refresh_token', | ||
refresh_token: testRefreshToken, | ||
client_id: testClientID, | ||
client_secret: testClientSecret, | ||
}).reply(200, { | ||
access_token: 'new access token', | ||
refresh_token: 'new refresh token', | ||
}); | ||
// nock(dispatchUrl).post('/oauth/token', { | ||
// grant_type: 'refresh_token', | ||
// refresh_token: testRefreshToken, | ||
// client_id: testClientID, | ||
// client_secret: testClientSecret, | ||
// }).reply(200, { | ||
// access_token: 'new access token', | ||
// refresh_token: 'new refresh token', | ||
// }); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
// client.setBearerToken(testBearerToken, testRefreshToken); | ||
client.doAuthenticatedRequest('GET', '/').then(response => { | ||
expect(response.foo).toEqual('bar'); | ||
expect(client.bearerToken).toEqual('new access token'); | ||
expect(client.refreshToken).toEqual('new refresh token'); | ||
done(); | ||
}).catch(done); | ||
}); | ||
// client.doAuthenticatedRequest('GET', '/').then(response => { | ||
// expect(response.foo).toEqual('bar'); | ||
// expect(client.bearerToken).toEqual('new access token'); | ||
// expect(client.refreshToken).toEqual('new refresh token'); | ||
// done(); | ||
// }).catch(done); | ||
// }); | ||
it('should fail without a refresh token', done => { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock(dispatchUrl).get('/').times(1).reply(401); | ||
nock(dispatchUrl).get('/').times(1).reply(200, { | ||
foo: 'bar', | ||
}); | ||
// it('should fail without a refresh token', done => { | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// nock(dispatchUrl).get('/').times(1).reply(401); | ||
// nock(dispatchUrl).get('/').times(1).reply(200, { | ||
// foo: 'bar', | ||
// }); | ||
nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'refresh_token', | ||
refresh_token: testRefreshToken, | ||
client_id: testClientID, | ||
client_secret: testClientSecret, | ||
}).reply(200, { | ||
access_token: 'new access token', | ||
refresh_token: 'new refresh token', | ||
}); | ||
// nock(dispatchUrl).post('/oauth/token', { | ||
// grant_type: 'refresh_token', | ||
// refresh_token: testRefreshToken, | ||
// client_id: testClientID, | ||
// client_secret: testClientSecret, | ||
// }).reply(200, { | ||
// access_token: 'new access token', | ||
// refresh_token: 'new refresh token', | ||
// }); | ||
client.setBearerToken(testBearerToken); | ||
// client.setBearerToken(testBearerToken); | ||
client.doAuthenticatedRequest('GET', '/').then(() => { | ||
done(new Error('Should not have worked')); | ||
}).catch(err => { | ||
expect(err instanceof UnauthorizedError).toEqual(true); | ||
done(); | ||
}); | ||
}); | ||
// client.doAuthenticatedRequest('GET', '/').then(() => { | ||
// done(new Error('Should not have worked')); | ||
// }).catch(err => { | ||
// expect(err instanceof UnauthorizedError).toEqual(true); | ||
// done(); | ||
// }); | ||
// }); | ||
it('should hit the files api if options.file is true', () => { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
const scope = nock('https://files-api.dispatch.me').get('/').reply(200); | ||
client.setBearerToken(testBearerToken); | ||
client.doAuthenticatedRequest('GET', '/', null, { | ||
client: 'files-api', | ||
}); | ||
expect(scope.isDone()).toEqual(true); | ||
}); | ||
// it('should hit the files api if options.file is true', () => { | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// const scope = nock('https://files-api.dispatch.me').get('/').reply(200); | ||
// client.setBearerToken(testBearerToken); | ||
// client.doAuthenticatedRequest('GET', '/', null, { | ||
// client: 'files-api', | ||
// }); | ||
// expect(scope.isDone()).toEqual(true); | ||
// }); | ||
it('should append a transaction ID to the headers of an authenticated request', done => { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock(dispatchUrl).get('/').times(1).reply(function reply() { | ||
expect(this.req.headers['x-transaction-id']).toExist(); | ||
done(); | ||
}); | ||
// it('should append a transaction ID to the headers of an authenticated request', done => { | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// nock(dispatchUrl).get('/').times(1).reply(function reply() { | ||
// expect(this.req.headers['x-transaction-id']).toExist(); | ||
// done(); | ||
// }); | ||
nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'refresh_token', | ||
refresh_token: testRefreshToken, | ||
client_id: testClientID, | ||
client_secret: testClientSecret, | ||
}).reply(200, { | ||
access_token: 'new access token', | ||
refresh_token: 'new refresh token', | ||
}); | ||
// nock(dispatchUrl).post('/oauth/token', { | ||
// grant_type: 'refresh_token', | ||
// refresh_token: testRefreshToken, | ||
// client_id: testClientID, | ||
// client_secret: testClientSecret, | ||
// }).reply(200, { | ||
// access_token: 'new access token', | ||
// refresh_token: 'new refresh token', | ||
// }); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
// client.setBearerToken(testBearerToken, testRefreshToken); | ||
client.doAuthenticatedRequest('GET', '/'); | ||
}); | ||
// client.doAuthenticatedRequest('GET', '/'); | ||
// }); | ||
it('should append an analytics tags to the headers of an authenticated request', done => { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock(dispatchUrl).get('/').times(1).reply(function reply() { | ||
expect(this.req.headers['x-analytics-tags']).toEqual('foo:bar,bar:foo'); | ||
done(); | ||
}); | ||
// it('should append an analytics tags to the headers of an authenticated request', done => { | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// nock(dispatchUrl).get('/').times(1).reply(function reply() { | ||
// expect(this.req.headers['x-analytics-tags']).toEqual('foo:bar,bar:foo'); | ||
// done(); | ||
// }); | ||
nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'refresh_token', | ||
refresh_token: testRefreshToken, | ||
client_id: testClientID, | ||
client_secret: testClientSecret, | ||
}).reply(200, { | ||
access_token: 'new access token', | ||
refresh_token: 'new refresh token', | ||
}); | ||
// nock(dispatchUrl).post('/oauth/token', { | ||
// grant_type: 'refresh_token', | ||
// refresh_token: testRefreshToken, | ||
// client_id: testClientID, | ||
// client_secret: testClientSecret, | ||
// }).reply(200, { | ||
// access_token: 'new access token', | ||
// refresh_token: 'new refresh token', | ||
// }); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
// client.setBearerToken(testBearerToken, testRefreshToken); | ||
client.doAuthenticatedRequest('GET', '/', null, { analytics: { foo: 'bar', bar: 'foo' } }); | ||
}); | ||
// client.doAuthenticatedRequest('GET', '/', null, { analytics: { foo: 'bar', bar: 'foo' } }); | ||
// }); | ||
it('should append session params to the analytics tags to the headers of an authenticated request', done => { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock(dispatchUrl).get('/').times(1).reply(function reply() { | ||
expect(this.req.headers['x-analytics-tags']).toEqual('baz:bing,foo:bar,bar:foo'); | ||
done(); | ||
}); | ||
// it('should append session params to the analytics tags to the headers of an authenticated request', done => { | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// nock(dispatchUrl).get('/').times(1).reply(function reply() { | ||
// expect(this.req.headers['x-analytics-tags']).toEqual('baz:bing,foo:bar,bar:foo'); | ||
// done(); | ||
// }); | ||
nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'refresh_token', | ||
refresh_token: testRefreshToken, | ||
client_id: testClientID, | ||
client_secret: testClientSecret, | ||
}).reply(200, { | ||
access_token: 'new access token', | ||
refresh_token: 'new refresh token', | ||
}); | ||
// nock(dispatchUrl).post('/oauth/token', { | ||
// grant_type: 'refresh_token', | ||
// refresh_token: testRefreshToken, | ||
// client_id: testClientID, | ||
// client_secret: testClientSecret, | ||
// }).reply(200, { | ||
// access_token: 'new access token', | ||
// refresh_token: 'new refresh token', | ||
// }); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
// client.setBearerToken(testBearerToken, testRefreshToken); | ||
client.setSession({ baz: 'bing' }); | ||
// client.setSession({ baz: 'bing' }); | ||
client.doAuthenticatedRequest('GET', '/', null, { analytics: { foo: 'bar', bar: 'foo' } }); | ||
}); | ||
}); | ||
// client.doAuthenticatedRequest('GET', '/', null, { analytics: { foo: 'bar', bar: 'foo' } }); | ||
// }); | ||
// }); | ||
describe('search', () => { | ||
it('parses query from api', done => { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock(dispatchUrl).get('/v2/search?organization_id=5&q=fix').times(1).reply(200, { | ||
customer: { | ||
hits: [ | ||
{ | ||
_highlightResult: { | ||
full_name: { | ||
matchLevel: 'full', | ||
matchedWords: ['fix'], | ||
}, | ||
}, | ||
company_name: 'Company', | ||
created_at: '2016-07-21T01:27:16+0000', | ||
email: 'customer-201@example.com', | ||
external_ids: [], | ||
full_name: 'Mr. Fix-It', | ||
home_address_text: '123 Summer St, apt. 1, Boston, MA 01234', | ||
id: 6911, | ||
last_job_at: '2016-07-23T13:59:10+0000', | ||
notes: null, | ||
organization_id: 5, | ||
phone_numbers: ['+15555550210'], | ||
}, | ||
], | ||
nbHits: 1, | ||
}, | ||
job: { | ||
hits: [ | ||
{ | ||
_highlightResult: { | ||
address_text: { | ||
matchLevel: 'none', | ||
matchedWords: [], | ||
}, | ||
created_at: { | ||
matchLevel: 'none', | ||
matchedWords: [], | ||
}, | ||
customer_email: { | ||
matchLevel: 'none', | ||
matchedWords: [], | ||
}, | ||
customer_full_name: { | ||
matchLevel: 'none', | ||
matchedWords: [], | ||
}, | ||
customer_phone_number: { | ||
matchLevel: 'none', | ||
matchedWords: [], | ||
}, | ||
description: { | ||
matchLevel: 'none', | ||
matchedWords: [], | ||
}, | ||
logo_token: { | ||
matchLevel: 'none', | ||
matchedWords: [], | ||
}, | ||
service_type: { | ||
matchLevel: 'none', | ||
matchedWords: [], | ||
}, | ||
source: { | ||
matchLevel: 'none', | ||
matchedWords: [], | ||
}, | ||
status: { | ||
matchLevel: 'none', | ||
matchedWords: [], | ||
}, | ||
title: { | ||
matchLevel: 'full', | ||
matchedWords: ['fix'], | ||
}, | ||
updated_at: { | ||
matchLevel: 'none', | ||
matchedWords: [], | ||
}, | ||
}, | ||
address_text: '123 Summer St, apt. 1, Boston, MA 01234', | ||
archived_at: null, | ||
brand_id: null, | ||
created_at: '2016-07-23T13:59:10+0000', | ||
customer_email: 'customer-201@example.com', | ||
customer_full_name: 'Custom Err', | ||
customer_id: 6911, | ||
customer_phone_number: '+15555550210', | ||
description: 'in the basement', | ||
external_ids: [], | ||
id: 6340, | ||
labels: ['one', 'two'], | ||
logo_token: '0e3601b9-5a4b-4692-b82d-502f61107876', | ||
next_scheduled_appointment: { | ||
duration: 3600, | ||
technician_name: null, | ||
time: '2016-07-21T01:00:00+0000', | ||
user_id: null, | ||
}, | ||
organization_id: 5, | ||
resume_at: null, | ||
service_type: 'plumbing', | ||
source: 'abc', | ||
source_id: 8, | ||
status: 'scheduled', | ||
status_message: null, | ||
title: 'Fix the sink', | ||
updated_at: '2016-07-21T01:32:46+0000', | ||
}, | ||
], | ||
nbHits: 1, | ||
}, | ||
}); | ||
// describe('search', () => { | ||
// it('parses query from api', done => { | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// nock(dispatchUrl).get('/v2/search?organization_id=5&q=fix').times(1).reply(200, { | ||
// customer: { | ||
// hits: [ | ||
// { | ||
// _highlightResult: { | ||
// full_name: { | ||
// matchLevel: 'full', | ||
// matchedWords: ['fix'], | ||
// }, | ||
// }, | ||
// company_name: 'Company', | ||
// created_at: '2016-07-21T01:27:16+0000', | ||
// email: 'customer-201@example.com', | ||
// external_ids: [], | ||
// full_name: 'Mr. Fix-It', | ||
// home_address_text: '123 Summer St, apt. 1, Boston, MA 01234', | ||
// id: 6911, | ||
// last_job_at: '2016-07-23T13:59:10+0000', | ||
// notes: null, | ||
// organization_id: 5, | ||
// phone_numbers: ['+15555550210'], | ||
// }, | ||
// ], | ||
// nbHits: 1, | ||
// }, | ||
// job: { | ||
// hits: [ | ||
// { | ||
// _highlightResult: { | ||
// address_text: { | ||
// matchLevel: 'none', | ||
// matchedWords: [], | ||
// }, | ||
// created_at: { | ||
// matchLevel: 'none', | ||
// matchedWords: [], | ||
// }, | ||
// customer_email: { | ||
// matchLevel: 'none', | ||
// matchedWords: [], | ||
// }, | ||
// customer_full_name: { | ||
// matchLevel: 'none', | ||
// matchedWords: [], | ||
// }, | ||
// customer_phone_number: { | ||
// matchLevel: 'none', | ||
// matchedWords: [], | ||
// }, | ||
// description: { | ||
// matchLevel: 'none', | ||
// matchedWords: [], | ||
// }, | ||
// logo_token: { | ||
// matchLevel: 'none', | ||
// matchedWords: [], | ||
// }, | ||
// service_type: { | ||
// matchLevel: 'none', | ||
// matchedWords: [], | ||
// }, | ||
// source: { | ||
// matchLevel: 'none', | ||
// matchedWords: [], | ||
// }, | ||
// status: { | ||
// matchLevel: 'none', | ||
// matchedWords: [], | ||
// }, | ||
// title: { | ||
// matchLevel: 'full', | ||
// matchedWords: ['fix'], | ||
// }, | ||
// updated_at: { | ||
// matchLevel: 'none', | ||
// matchedWords: [], | ||
// }, | ||
// }, | ||
// address_text: '123 Summer St, apt. 1, Boston, MA 01234', | ||
// archived_at: null, | ||
// brand_id: null, | ||
// created_at: '2016-07-23T13:59:10+0000', | ||
// customer_email: 'customer-201@example.com', | ||
// customer_full_name: 'Custom Err', | ||
// customer_id: 6911, | ||
// customer_phone_number: '+15555550210', | ||
// description: 'in the basement', | ||
// external_ids: [], | ||
// id: 6340, | ||
// labels: ['one', 'two'], | ||
// logo_token: '0e3601b9-5a4b-4692-b82d-502f61107876', | ||
// next_scheduled_appointment: { | ||
// duration: 3600, | ||
// technician_name: null, | ||
// time: '2016-07-21T01:00:00+0000', | ||
// user_id: null, | ||
// }, | ||
// organization_id: 5, | ||
// resume_at: null, | ||
// service_type: 'plumbing', | ||
// source: 'abc', | ||
// source_id: 8, | ||
// status: 'scheduled', | ||
// status_message: null, | ||
// title: 'Fix the sink', | ||
// updated_at: '2016-07-21T01:32:46+0000', | ||
// }, | ||
// ], | ||
// nbHits: 1, | ||
// }, | ||
// }); | ||
client.search({ | ||
organizationID: 5, | ||
query: 'fix', | ||
}).then(result => { | ||
expect(result).toEqual({ | ||
customers: [ | ||
{ | ||
_matchedWords: { | ||
full_name: ['fix'], | ||
}, | ||
company_name: 'Company', | ||
created_at: '2016-07-21T01:27:16+0000', | ||
email: 'customer-201@example.com', | ||
external_ids: [], | ||
full_name: 'Mr. Fix-It', | ||
home_address_text: '123 Summer St, apt. 1, Boston, MA 01234', | ||
id: 6911, | ||
last_job_at: '2016-07-23T13:59:10+0000', | ||
notes: null, | ||
organization_id: 5, | ||
phone_numbers: ['+15555550210'], | ||
}, | ||
], | ||
filter: undefined, | ||
jobs: [ | ||
{ | ||
_matchedWords: { | ||
address_text: [], | ||
created_at: [], | ||
customer_email: [], | ||
customer_full_name: [], | ||
customer_phone_number: [], | ||
description: [], | ||
logo_token: [], | ||
service_type: [], | ||
source: [], | ||
status: [], | ||
title: ['fix'], | ||
updated_at: [], | ||
}, | ||
account_logo_token: '0e3601b9-5a4b-4692-b82d-502f61107876', | ||
address_text: '123 Summer St, apt. 1, Boston, MA 01234', | ||
appointment: '2016-07-21T01:00:00+0000', | ||
archived_at: null, | ||
brand_id: null, | ||
brand_logo: 'https://files-api.dispatch.me/v1/datafiles/0e3601b9-5a4b-4692-b82d-502f61107876', | ||
created_at: '2016-07-23T13:59:10+0000', | ||
customer_email: 'customer-201@example.com', | ||
customer_full_name: 'Custom Err', | ||
customer_id: 6911, | ||
customer_phone_number: '+15555550210', | ||
description: 'in the basement', | ||
external_ids: '', | ||
id: 6340, | ||
labels: ['one', 'two'], | ||
logo_token: '0e3601b9-5a4b-4692-b82d-502f61107876', | ||
organization_id: 5, | ||
resume_at: null, | ||
service_type: 'plumbing', | ||
source: 'abc', | ||
source_id: 8, | ||
status: 'scheduled', | ||
status_message: null, | ||
title: 'Fix the sink', | ||
updated_at: '2016-07-21T01:32:46+0000', | ||
user_id: null, | ||
}, | ||
], | ||
totalResults: 2, | ||
}); | ||
done(); | ||
}).catch(done); | ||
}); | ||
}); | ||
}); | ||
// client.search({ | ||
// organizationID: 5, | ||
// query: 'fix', | ||
// }).then(result => { | ||
// expect(result).toEqual({ | ||
// customers: [ | ||
// { | ||
// _matchedWords: { | ||
// full_name: ['fix'], | ||
// }, | ||
// company_name: 'Company', | ||
// created_at: '2016-07-21T01:27:16+0000', | ||
// email: 'customer-201@example.com', | ||
// external_ids: [], | ||
// full_name: 'Mr. Fix-It', | ||
// home_address_text: '123 Summer St, apt. 1, Boston, MA 01234', | ||
// id: 6911, | ||
// last_job_at: '2016-07-23T13:59:10+0000', | ||
// notes: null, | ||
// organization_id: 5, | ||
// phone_numbers: ['+15555550210'], | ||
// }, | ||
// ], | ||
// filter: undefined, | ||
// jobs: [ | ||
// { | ||
// _matchedWords: { | ||
// address_text: [], | ||
// created_at: [], | ||
// customer_email: [], | ||
// customer_full_name: [], | ||
// customer_phone_number: [], | ||
// description: [], | ||
// logo_token: [], | ||
// service_type: [], | ||
// source: [], | ||
// status: [], | ||
// title: ['fix'], | ||
// updated_at: [], | ||
// }, | ||
// account_logo_token: '0e3601b9-5a4b-4692-b82d-502f61107876', | ||
// address_text: '123 Summer St, apt. 1, Boston, MA 01234', | ||
// appointment: '2016-07-21T01:00:00+0000', | ||
// archived_at: null, | ||
// brand_id: null, | ||
// brand_logo: 'https://files-api.dispatch.me/v1/datafiles/0e3601b9-5a4b-4692-b82d-502f61107876', | ||
// created_at: '2016-07-23T13:59:10+0000', | ||
// customer_email: 'customer-201@example.com', | ||
// customer_full_name: 'Custom Err', | ||
// customer_id: 6911, | ||
// customer_phone_number: '+15555550210', | ||
// description: 'in the basement', | ||
// external_ids: '', | ||
// id: 6340, | ||
// labels: ['one', 'two'], | ||
// logo_token: '0e3601b9-5a4b-4692-b82d-502f61107876', | ||
// organization_id: 5, | ||
// resume_at: null, | ||
// service_type: 'plumbing', | ||
// source: 'abc', | ||
// source_id: 8, | ||
// status: 'scheduled', | ||
// status_message: null, | ||
// title: 'Fix the sink', | ||
// updated_at: '2016-07-21T01:32:46+0000', | ||
// user_id: null, | ||
// }, | ||
// ], | ||
// totalResults: 2, | ||
// }); | ||
// done(); | ||
// }).catch(done); | ||
// }); | ||
// }); | ||
// }); | ||
describe('uploadFile', () => { | ||
it('should upload to correct URL, but blob on server is BS'); | ||
/** | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock('https://files-api.dispatch.me').post('/v1/datafiles').reply(201, { | ||
datafile: { | ||
uid: '1234-5678', | ||
}, | ||
}); | ||
// describe('uploadFile', () => { | ||
// it('should upload to correct URL, but blob on server is BS'); | ||
// /** | ||
// const client = new Dispatch(testClientID, testClientSecret); | ||
// nock('https://files-api.dispatch.me').post('/v1/datafiles').reply(201, { | ||
// datafile: { | ||
// uid: '1234-5678', | ||
// }, | ||
// }); | ||
client.setBearerToken(testBearerToken); | ||
client.uploadFile('data:image/jpeg;base64,/9j/4AAQSkZJRgABAAEAYABgAADACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKAP/2Q==', 'photo.jpg').then(response => { | ||
console.log(response); | ||
done(); | ||
}).catch(done); | ||
**/ | ||
}); | ||
// client.setBearerToken(testBearerToken); | ||
// client.uploadFile('data:image/jpeg;base64,/9j/4AAQSkZJRgABAAEAYABgAADACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKAP/2Q==', 'photo.jpg').then(response => { | ||
// console.log(response); | ||
// done(); | ||
// }).catch(done); | ||
// **/ | ||
// }); | ||
describe('createAndScheduleJob', () => { | ||
let client; | ||
beforeEach(() => { | ||
client = new Dispatch(testClientID, testClientSecret); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
}); | ||
afterEach(() => { | ||
restoreSpies(); | ||
}); | ||
// describe('createAndScheduleJob', () => { | ||
// let client; | ||
// beforeEach(() => { | ||
// client = new Dispatch(testClientID, testClientSecret); | ||
// client.setBearerToken(testBearerToken, testRefreshToken); | ||
// }); | ||
// afterEach(() => { | ||
// restoreSpies(); | ||
// }); | ||
describe('error handling', () => { | ||
it('should fail and store the customer error correctly if the customer creation fails', done => { | ||
spyOn(client.entities.customers, 'create').andReturn(Promise.reject(new UnprocessableEntityError({}))); | ||
// describe('error handling', () => { | ||
// it('should fail and store the customer error correctly if the customer creation fails', done => { | ||
// spyOn(client.entities.customers, 'create').andReturn(Promise.reject(new UnprocessableEntityError({}))); | ||
client.createAndScheduleJob({}, { | ||
full_name: 'Testy McGee', | ||
}).then(() => { | ||
done(new Error('Should not have worked man')); | ||
}).catch(err => { | ||
expect(err instanceof MultiActionError).toEqual(true); | ||
expect(err.data.customer instanceof UnprocessableEntityError).toEqual(true); | ||
expect(err.data.job).toEqual(null); | ||
expect(err.data.appointment).toEqual(null); | ||
done(); | ||
}); | ||
}); | ||
// client.createAndScheduleJob({}, { | ||
// full_name: 'Testy McGee', | ||
// }).then(() => { | ||
// done(new Error('Should not have worked man')); | ||
// }).catch(err => { | ||
// expect(err instanceof MultiActionError).toEqual(true); | ||
// expect(err.data.customer instanceof UnprocessableEntityError).toEqual(true); | ||
// expect(err.data.job).toEqual(null); | ||
// expect(err.data.appointment).toEqual(null); | ||
// done(); | ||
// }); | ||
// }); | ||
it('should fail and store the job error correctly if the job creation fails', done => { | ||
spyOn(client.entities.customers, 'create').andReturn(Promise.resolve({ | ||
id: 123, | ||
full_name: 'Testy Mcgee', | ||
})); | ||
spyOn(client.entities.jobs, 'create').andReturn(Promise.reject(new UnauthorizedError())); | ||
// it('should fail and store the job error correctly if the job creation fails', done => { | ||
// spyOn(client.entities.customers, 'create').andReturn(Promise.resolve({ | ||
// id: 123, | ||
// full_name: 'Testy Mcgee', | ||
// })); | ||
// spyOn(client.entities.jobs, 'create').andReturn(Promise.reject(new UnauthorizedError())); | ||
client.createAndScheduleJob({ | ||
title: 'Test Job', | ||
}, { | ||
full_name: 'Testy McGee', | ||
}).then(() => { | ||
done(new Error('Should not have worked man')); | ||
}).catch(err => { | ||
expect(err instanceof MultiActionError).toEqual(true); | ||
expect(err.data.customer).toEqual(null); | ||
expect(err.data.job instanceof UnauthorizedError).toEqual(true); | ||
expect(err.data.appointment).toEqual(null); | ||
done(); | ||
}); | ||
}); | ||
// client.createAndScheduleJob({ | ||
// title: 'Test Job', | ||
// }, { | ||
// full_name: 'Testy McGee', | ||
// }).then(() => { | ||
// done(new Error('Should not have worked man')); | ||
// }).catch(err => { | ||
// expect(err instanceof MultiActionError).toEqual(true); | ||
// expect(err.data.customer).toEqual(null); | ||
// expect(err.data.job instanceof UnauthorizedError).toEqual(true); | ||
// expect(err.data.appointment).toEqual(null); | ||
// done(); | ||
// }); | ||
// }); | ||
it('should fail and store the appointment error correctly if the appointment creation fails', done => { | ||
spyOn(client.entities.customers, 'create').andReturn(Promise.resolve({ | ||
id: 123, | ||
full_name: 'Testy Mcgee', | ||
})); | ||
spyOn(client.entities.jobs, 'create').andReturn(Promise.resolve({ | ||
id: 456, | ||
title: 'Test Job', | ||
})); | ||
spyOn(client.entities.appointments, 'create').andReturn(Promise.reject(new UnauthorizedError())); | ||
// it('should fail and store the appointment error correctly if the appointment creation fails', done => { | ||
// spyOn(client.entities.customers, 'create').andReturn(Promise.resolve({ | ||
// id: 123, | ||
// full_name: 'Testy Mcgee', | ||
// })); | ||
// spyOn(client.entities.jobs, 'create').andReturn(Promise.resolve({ | ||
// id: 456, | ||
// title: 'Test Job', | ||
// })); | ||
// spyOn(client.entities.appointments, 'create').andReturn(Promise.reject(new UnauthorizedError())); | ||
client.createAndScheduleJob({ | ||
title: 'Test Job', | ||
}, { | ||
full_name: 'Testy McGee', | ||
}, { | ||
time: '12345', | ||
}).then(() => { | ||
done(new Error('Should not have worked man')); | ||
}).catch(err => { | ||
expect(err instanceof MultiActionError).toEqual(true); | ||
expect(err.data.customer).toEqual(null); | ||
expect(err.data.appointment instanceof UnauthorizedError).toEqual(true); | ||
expect(err.data.job).toEqual(null); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
// client.createAndScheduleJob({ | ||
// title: 'Test Job', | ||
// }, { | ||
// full_name: 'Testy McGee', | ||
// }, { | ||
// time: '12345', | ||
// }).then(() => { | ||
// done(new Error('Should not have worked man')); | ||
// }).catch(err => { | ||
// expect(err instanceof MultiActionError).toEqual(true); | ||
// expect(err.data.customer).toEqual(null); | ||
// expect(err.data.appointment instanceof UnauthorizedError).toEqual(true); | ||
// expect(err.data.job).toEqual(null); | ||
// done(); | ||
// }); | ||
// }); | ||
// }); | ||
describe('success', () => { | ||
it('should make post requests with all correct data with appointment', done => { | ||
spyOn(client.entities.customers, 'create').andReturn(Promise.resolve({ | ||
id: 123, | ||
full_name: 'Testy Mcgee', | ||
})); | ||
spyOn(client.entities.jobs, 'create').andReturn(Promise.resolve({ | ||
id: 456, | ||
title: 'Test Job', | ||
customer_id: 123, | ||
})); | ||
spyOn(client.entities.appointments, 'create').andReturn(Promise.resolve({ | ||
id: 789, | ||
job_id: 456, | ||
time: '12345', | ||
})); | ||
// describe('success', () => { | ||
// it('should make post requests with all correct data with appointment', done => { | ||
// spyOn(client.entities.customers, 'create').andReturn(Promise.resolve({ | ||
// id: 123, | ||
// full_name: 'Testy Mcgee', | ||
// })); | ||
// spyOn(client.entities.jobs, 'create').andReturn(Promise.resolve({ | ||
// id: 456, | ||
// title: 'Test Job', | ||
// customer_id: 123, | ||
// })); | ||
// spyOn(client.entities.appointments, 'create').andReturn(Promise.resolve({ | ||
// id: 789, | ||
// job_id: 456, | ||
// time: '12345', | ||
// })); | ||
client.createAndScheduleJob({ | ||
title: 'Test Job', | ||
}, { | ||
full_name: 'Testy McGee', | ||
}, { | ||
time: '12345', | ||
}).then((response) => { | ||
expect(response).toEqual({ | ||
job: { | ||
id: 456, | ||
title: 'Test Job', | ||
customer_id: 123, | ||
}, | ||
customer: { | ||
id: 123, | ||
full_name: 'Testy Mcgee', | ||
}, | ||
appointment: { | ||
job_id: 456, | ||
id: 789, | ||
time: '12345', | ||
}, | ||
}); | ||
// client.createAndScheduleJob({ | ||
// title: 'Test Job', | ||
// }, { | ||
// full_name: 'Testy McGee', | ||
// }, { | ||
// time: '12345', | ||
// }).then((response) => { | ||
// expect(response).toEqual({ | ||
// job: { | ||
// id: 456, | ||
// title: 'Test Job', | ||
// customer_id: 123, | ||
// }, | ||
// customer: { | ||
// id: 123, | ||
// full_name: 'Testy Mcgee', | ||
// }, | ||
// appointment: { | ||
// job_id: 456, | ||
// id: 789, | ||
// time: '12345', | ||
// }, | ||
// }); | ||
// Make sure it set the right IDs | ||
expect(client.entities.customers.create).toHaveBeenCalledWith({ | ||
full_name: 'Testy McGee', | ||
}); | ||
// // Make sure it set the right IDs | ||
// expect(client.entities.customers.create).toHaveBeenCalledWith({ | ||
// full_name: 'Testy McGee', | ||
// }); | ||
expect(client.entities.jobs.create).toHaveBeenCalledWith({ | ||
customer_id: 123, | ||
title: 'Test Job', | ||
}); | ||
expect(client.entities.appointments.create).toHaveBeenCalledWith({ | ||
job_id: 456, | ||
time: '12345', | ||
}); | ||
done(); | ||
}).catch(done); | ||
}); | ||
// expect(client.entities.jobs.create).toHaveBeenCalledWith({ | ||
// customer_id: 123, | ||
// title: 'Test Job', | ||
// }); | ||
// expect(client.entities.appointments.create).toHaveBeenCalledWith({ | ||
// job_id: 456, | ||
// time: '12345', | ||
// }); | ||
// done(); | ||
// }).catch(done); | ||
// }); | ||
it('should make patch request if customer id exists', done => { | ||
spyOn(client.entities.customers, 'create').andCallThrough(); | ||
spyOn(client.entities.customers, 'update').andReturn(Promise.resolve({ | ||
id: 123, | ||
full_name: 'Same Dude', | ||
})); | ||
spyOn(client.entities.jobs, 'create').andReturn(Promise.resolve({ | ||
id: 234, | ||
title: 'Royale', | ||
customer_id: 123, | ||
})); | ||
// it('should make patch request if customer id exists', done => { | ||
// spyOn(client.entities.customers, 'create').andCallThrough(); | ||
// spyOn(client.entities.customers, 'update').andReturn(Promise.resolve({ | ||
// id: 123, | ||
// full_name: 'Same Dude', | ||
// })); | ||
// spyOn(client.entities.jobs, 'create').andReturn(Promise.resolve({ | ||
// id: 234, | ||
// title: 'Royale', | ||
// customer_id: 123, | ||
// })); | ||
client.createAndScheduleJob({ title: 'Royale' }, { id: 123, full_name: 'Same Dude' }) | ||
.then(response => { | ||
expect(response).toEqual({ | ||
job: { | ||
id: 234, | ||
title: 'Royale', | ||
customer_id: 123, | ||
}, | ||
customer: { | ||
id: 123, | ||
full_name: 'Same Dude', | ||
}, | ||
appointment: null, | ||
}); | ||
// client.createAndScheduleJob({ title: 'Royale' }, { id: 123, full_name: 'Same Dude' }) | ||
// .then(response => { | ||
// expect(response).toEqual({ | ||
// job: { | ||
// id: 234, | ||
// title: 'Royale', | ||
// customer_id: 123, | ||
// }, | ||
// customer: { | ||
// id: 123, | ||
// full_name: 'Same Dude', | ||
// }, | ||
// appointment: null, | ||
// }); | ||
expect(client.entities.customers.create).toNotHaveBeenCalled(); | ||
expect(client.entities.customers.update).toHaveBeenCalledWith(123, { full_name: 'Same Dude' }); | ||
// expect(client.entities.customers.create).toNotHaveBeenCalled(); | ||
// expect(client.entities.customers.update).toHaveBeenCalledWith(123, { full_name: 'Same Dude' }); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
// done(); | ||
// }) | ||
// .catch(done); | ||
// }); | ||
it('should make post request if customer id does not exist', done => { | ||
spyOn(client.entities.customers, 'update').andCallThrough(); | ||
spyOn(client.entities.customers, 'create').andReturn(Promise.resolve({ | ||
id: 123, | ||
full_name: 'Same Dude', | ||
})); | ||
spyOn(client.entities.jobs, 'create').andReturn(Promise.resolve({ | ||
id: 234, | ||
title: 'Royale', | ||
customer_id: 123, | ||
})); | ||
// it('should make post request if customer id does not exist', done => { | ||
// spyOn(client.entities.customers, 'update').andCallThrough(); | ||
// spyOn(client.entities.customers, 'create').andReturn(Promise.resolve({ | ||
// id: 123, | ||
// full_name: 'Same Dude', | ||
// })); | ||
// spyOn(client.entities.jobs, 'create').andReturn(Promise.resolve({ | ||
// id: 234, | ||
// title: 'Royale', | ||
// customer_id: 123, | ||
// })); | ||
client.createAndScheduleJob({ title: 'Royale' }, { full_name: 'Same Dude' }) | ||
.then(response => { | ||
expect(response).toEqual({ | ||
job: { | ||
id: 234, | ||
title: 'Royale', | ||
customer_id: 123, | ||
}, | ||
customer: { | ||
id: 123, | ||
full_name: 'Same Dude', | ||
}, | ||
appointment: null, | ||
}); | ||
// client.createAndScheduleJob({ title: 'Royale' }, { full_name: 'Same Dude' }) | ||
// .then(response => { | ||
// expect(response).toEqual({ | ||
// job: { | ||
// id: 234, | ||
// title: 'Royale', | ||
// customer_id: 123, | ||
// }, | ||
// customer: { | ||
// id: 123, | ||
// full_name: 'Same Dude', | ||
// }, | ||
// appointment: null, | ||
// }); | ||
expect(client.entities.customers.update).toNotHaveBeenCalled(); | ||
expect(client.entities.customers.create).toHaveBeenCalledWith({ full_name: 'Same Dude' }); | ||
// expect(client.entities.customers.update).toNotHaveBeenCalled(); | ||
// expect(client.entities.customers.create).toHaveBeenCalledWith({ full_name: 'Same Dude' }); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
}); | ||
}); | ||
// done(); | ||
// }) | ||
// .catch(done); | ||
// }); | ||
// }); | ||
// }); | ||
describe('signUp', () => { | ||
let client; | ||
let bearerTokenReq; | ||
beforeEach(() => { | ||
client = new Dispatch(testClientID, testClientSecret); | ||
bearerTokenReq = nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'client_credentials', | ||
client_id: testClientID, | ||
client_secret: testClientSecret, | ||
}).reply(200, { | ||
access_token: testBearerToken, | ||
refresh_token: testRefreshToken, | ||
}); | ||
}); | ||
// describe('signUp', () => { | ||
// let client; | ||
// let bearerTokenReq; | ||
// beforeEach(() => { | ||
// client = new Dispatch(testClientID, testClientSecret); | ||
// bearerTokenReq = nock(dispatchUrl).post('/oauth/token', { | ||
// grant_type: 'client_credentials', | ||
// client_id: testClientID, | ||
// client_secret: testClientSecret, | ||
// }).reply(200, { | ||
// access_token: testBearerToken, | ||
// refresh_token: testRefreshToken, | ||
// }); | ||
// }); | ||
it('should call the signup api endpoint given user and organization', (done) => { | ||
const req = nock(dispatchUrl).post('/v1/signup', { | ||
user: { | ||
first_name: 'Testy', | ||
last_name: 'McGee', | ||
}, | ||
organization: { | ||
name: 'Test Org', | ||
}, | ||
}).reply(200, { | ||
message: 'Thanks for signing up!', | ||
}); | ||
// it('should call the signup api endpoint given user and organization', (done) => { | ||
// const req = nock(dispatchUrl).post('/v1/signup', { | ||
// user: { | ||
// first_name: 'Testy', | ||
// last_name: 'McGee', | ||
// }, | ||
// organization: { | ||
// name: 'Test Org', | ||
// }, | ||
// }).reply(200, { | ||
// message: 'Thanks for signing up!', | ||
// }); | ||
client.signUp({ | ||
first_name: 'Testy', | ||
last_name: 'McGee', | ||
}, { | ||
name: 'Test Org', | ||
}).then(response => { | ||
expect(response.message).toEqual('Thanks for signing up!'); | ||
req.done(); | ||
bearerTokenReq.done(); | ||
done(); | ||
}).catch(done); | ||
}); | ||
// client.signUp({ | ||
// first_name: 'Testy', | ||
// last_name: 'McGee', | ||
// }, { | ||
// name: 'Test Org', | ||
// }).then(response => { | ||
// expect(response.message).toEqual('Thanks for signing up!'); | ||
// req.done(); | ||
// bearerTokenReq.done(); | ||
// done(); | ||
// }).catch(done); | ||
// }); | ||
it('should handle error response from api correctly', (done) => { | ||
const req = nock(dispatchUrl).post('/v1/signup', {}, {}).replyWithError(422, { | ||
errors: { | ||
organization: 'Error', | ||
user: {}, | ||
}, | ||
}); | ||
// it('should handle error response from api correctly', (done) => { | ||
// const req = nock(dispatchUrl).post('/v1/signup', {}, {}).replyWithError(422, { | ||
// errors: { | ||
// organization: 'Error', | ||
// user: {}, | ||
// }, | ||
// }); | ||
client.signUp({}, {}).then(response => { | ||
expect(response.organization instanceof UnprocessableEntityError).toEqual(true); | ||
expect(response.user).toEqual(null); | ||
req.done(); | ||
bearerTokenReq.done(); | ||
done(); | ||
}).catch(done()); | ||
}); | ||
}); | ||
// client.signUp({}, {}).then(response => { | ||
// expect(response.organization instanceof UnprocessableEntityError).toEqual(true); | ||
// expect(response.user).toEqual(null); | ||
// req.done(); | ||
// bearerTokenReq.done(); | ||
// done(); | ||
// }).catch(done()); | ||
// }); | ||
// }); | ||
describe('determineAuxiliaryAPIHost', () => { | ||
const devClient = new Dispatch(testClientID, testClientSecret, 'https://wfm-api-dev.dispatch.me'); | ||
const stagingClient = new Dispatch(testClientID, testClientSecret, 'https://wfm-api-staging.dispatch.me'); | ||
const sandboxClient = new Dispatch(testClientID, testClientSecret, 'https://wfm-api-sandbox.dispatch.me'); | ||
const prodClient = new Dispatch(testClientID, testClientSecret, 'https://wfm-api.dispatch.me'); | ||
// describe('determineAuxiliaryAPIHost', () => { | ||
// const devClient = new Dispatch(testClientID, testClientSecret, 'https://wfm-api-dev.dispatch.me'); | ||
// const stagingClient = new Dispatch(testClientID, testClientSecret, 'https://wfm-api-staging.dispatch.me'); | ||
// const sandboxClient = new Dispatch(testClientID, testClientSecret, 'https://wfm-api-sandbox.dispatch.me'); | ||
// const prodClient = new Dispatch(testClientID, testClientSecret, 'https://wfm-api.dispatch.me'); | ||
describe('dev', () => { | ||
it('files', () => { | ||
expect(devClient.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api-dev.dispatch.me'); | ||
}); | ||
// describe('dev', () => { | ||
// it('files', () => { | ||
// expect(devClient.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api-dev.dispatch.me'); | ||
// }); | ||
it('config', () => { | ||
expect(devClient.determineAuxiliaryAPIHost('config')).toBe('https://config-dev.dispatch.me'); | ||
}); | ||
// it('config', () => { | ||
// expect(devClient.determineAuxiliaryAPIHost('config')).toBe('https://config-dev.dispatch.me'); | ||
// }); | ||
it('other', () => { | ||
expect(devClient.determineAuxiliaryAPIHost('other')).toBe('https://other-dev.dispatch.me'); | ||
}); | ||
}); | ||
// it('other', () => { | ||
// expect(devClient.determineAuxiliaryAPIHost('other')).toBe('https://other-dev.dispatch.me'); | ||
// }); | ||
// }); | ||
describe('staging', () => { | ||
it('files', () => { | ||
expect(stagingClient.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api-staging.dispatch.me'); | ||
}); | ||
// describe('staging', () => { | ||
// it('files', () => { | ||
// expect(stagingClient.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api-staging.dispatch.me'); | ||
// }); | ||
it('config', () => { | ||
expect(stagingClient.determineAuxiliaryAPIHost('config')).toBe('https://config-staging.dispatch.me'); | ||
}); | ||
// it('config', () => { | ||
// expect(stagingClient.determineAuxiliaryAPIHost('config')).toBe('https://config-staging.dispatch.me'); | ||
// }); | ||
it('other', () => { | ||
expect(stagingClient.determineAuxiliaryAPIHost('other')).toBe('https://other-staging.dispatch.me'); | ||
}); | ||
}); | ||
// it('other', () => { | ||
// expect(stagingClient.determineAuxiliaryAPIHost('other')).toBe('https://other-staging.dispatch.me'); | ||
// }); | ||
// }); | ||
describe('sandbox', () => { | ||
it('files', () => { | ||
expect(sandboxClient.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api-sandbox.dispatch.me'); | ||
}); | ||
// describe('sandbox', () => { | ||
// it('files', () => { | ||
// expect(sandboxClient.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api-sandbox.dispatch.me'); | ||
// }); | ||
it('config', () => { | ||
expect(sandboxClient.determineAuxiliaryAPIHost('config')).toBe('https://config-sandbox.dispatch.me'); | ||
}); | ||
// it('config', () => { | ||
// expect(sandboxClient.determineAuxiliaryAPIHost('config')).toBe('https://config-sandbox.dispatch.me'); | ||
// }); | ||
it('other', () => { | ||
expect(sandboxClient.determineAuxiliaryAPIHost('other')).toBe('https://other-sandbox.dispatch.me'); | ||
}); | ||
}); | ||
// it('other', () => { | ||
// expect(sandboxClient.determineAuxiliaryAPIHost('other')).toBe('https://other-sandbox.dispatch.me'); | ||
// }); | ||
// }); | ||
describe('production', () => { | ||
it('files', () => { | ||
expect(prodClient.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api.dispatch.me'); | ||
}); | ||
// describe('production', () => { | ||
// it('files', () => { | ||
// expect(prodClient.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api.dispatch.me'); | ||
// }); | ||
it('config', () => { | ||
expect(prodClient.determineAuxiliaryAPIHost('config')).toBe('https://config.dispatch.me'); | ||
}); | ||
// it('config', () => { | ||
// expect(prodClient.determineAuxiliaryAPIHost('config')).toBe('https://config.dispatch.me'); | ||
// }); | ||
it('other', () => { | ||
expect(prodClient.determineAuxiliaryAPIHost('other')).toBe('https://other.dispatch.me'); | ||
}); | ||
}); | ||
// it('other', () => { | ||
// expect(prodClient.determineAuxiliaryAPIHost('other')).toBe('https://other.dispatch.me'); | ||
// }); | ||
// }); | ||
it('admin-api', () => { | ||
let client = new Dispatch(testClientID, testClientSecret, 'https://admin-api.dispatch.me'); | ||
expect(client.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api.dispatch.me'); | ||
client = new Dispatch(testClientID, testClientSecret, 'https://admin-api-dev.dispatch.me'); | ||
expect(client.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api-dev.dispatch.me'); | ||
}); | ||
}); | ||
}); | ||
// it('admin-api', () => { | ||
// let client = new Dispatch(testClientID, testClientSecret, 'https://admin-api.dispatch.me'); | ||
// expect(client.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api.dispatch.me'); | ||
// client = new Dispatch(testClientID, testClientSecret, 'https://admin-api-dev.dispatch.me'); | ||
// expect(client.determineAuxiliaryAPIHost('files-api')).toBe('https://files-api-dev.dispatch.me'); | ||
// }); | ||
// }); | ||
// }); |
export const ACCOUNT_ORGANIZATIONS = '/v1/account_organizations'; | ||
export const ACCOUNTS = '/v1/accounts'; | ||
export const ACCOUNT_USERS = '/v1/users/accounts'; | ||
export const APPLICATIONS = '/v1/applications'; | ||
@@ -4,0 +5,0 @@ export const APPOINTMENTS = '/v1/appointments'; |
@@ -14,7 +14,7 @@ /** | ||
get(query = {}, opts = {}) { | ||
return this.client.getCollection(this.endpoint, { ...query, no_total: true }, opts); | ||
return this.client.getCollection(this.endpoint, { no_total: true, ...query }, opts); | ||
} | ||
getWithMeta(query = {}) { | ||
return this.client.getCollectionWithMeta(this.endpoint, { ...query, no_total: true }); | ||
return this.client.getCollectionWithMeta(this.endpoint, { no_total: true, ...query }); | ||
} | ||
@@ -21,0 +21,0 @@ |
@@ -19,3 +19,3 @@ import expect from 'expect'; | ||
const scope = nock('https://api.dispatch.me') | ||
.get(`${endpoints.ATTACHMENTS}?filter[file_token_null]=1&filter[entity_type]=Job&filter[entity_id]=123&no_total=true`) | ||
.get(`${endpoints.ATTACHMENTS}?no_total=true&filter[file_token_null]=1&filter[entity_type]=Job&filter[entity_id]=123`) | ||
.reply(200); | ||
@@ -39,3 +39,3 @@ const col = new Collection(client, endpoints.ATTACHMENTS); | ||
const scope = nock('https://api.dispatch.me') | ||
.get(`${endpoints.CUSTOMERS}?limit=1&offset=0&no_total=true`) | ||
.get(`${endpoints.CUSTOMERS}?no_total=true&limit=1&offset=0`) | ||
.reply(200); | ||
@@ -211,3 +211,3 @@ const col = new Collection(client, endpoints.CUSTOMERS); | ||
const mockRequestPage1 = nock('https://api.dispatch.me') | ||
.get(`${endpoints.CUSTOMERS}?limit=1&offset=0&no_total=true`) | ||
.get(`${endpoints.CUSTOMERS}?no_total=true&limit=1&offset=0`) | ||
.reply(200, { | ||
@@ -225,3 +225,3 @@ customers: [{ | ||
const mockRequestPage2 = nock('https://api.dispatch.me') | ||
.get(`${endpoints.CUSTOMERS}?limit=1&offset=1&no_total=true`) | ||
.get(`${endpoints.CUSTOMERS}?no_total=true&limit=1&offset=1`) | ||
.reply(200, { | ||
@@ -239,3 +239,3 @@ customers: [{ | ||
const mockRequestPage3 = nock('https://api.dispatch.me') | ||
.get(`${endpoints.CUSTOMERS}?limit=1&offset=2&no_total=true`) | ||
.get(`${endpoints.CUSTOMERS}?no_total=true&limit=1&offset=2`) | ||
.reply(200, { | ||
@@ -289,7 +289,7 @@ customers: [], | ||
nock('https://api.dispatch.me') | ||
.get(`${endpoints.CUSTOMERS}?limit=1&offset=0&no_total=true`) | ||
.get(`${endpoints.CUSTOMERS}?no_total=true&limit=1&offset=0`) | ||
.reply(500); | ||
nock('https://api.dispatch.me') | ||
.get(`${endpoints.CUSTOMERS}?limit=1&offset=1&no_total=true`) | ||
.get(`${endpoints.CUSTOMERS}?no_total=true&limit=1&offset=1`) | ||
.reply(200, { | ||
@@ -320,3 +320,3 @@ customers: [{ | ||
nock('https://api.dispatch.me') | ||
.get(`${endpoints.CUSTOMERS}?limit=1&offset=0&no_total=true`) | ||
.get(`${endpoints.CUSTOMERS}?no_total=true&limit=1&offset=0`) | ||
.reply(500); | ||
@@ -339,3 +339,3 @@ | ||
nock('https://api.dispatch.me') | ||
.get(`${endpoints.CUSTOMERS}?limit=0&no_total=true`) | ||
.get(`${endpoints.CUSTOMERS}?no_total=true&limit=0`) | ||
.reply(200, { | ||
@@ -361,3 +361,3 @@ data: {}, | ||
nock('https://api.dispatch.me') | ||
.get(`${endpoints.CUSTOMERS}?limit=0&no_total=true`) | ||
.get(`${endpoints.CUSTOMERS}?no_total=true&limit=0`) | ||
.reply(500); | ||
@@ -364,0 +364,0 @@ |
@@ -320,16 +320,16 @@ import expect from 'expect'; | ||
it('should append a transaction ID to the headers of an authenticated request', done => { | ||
const transactionID = '12345'; | ||
const scope = nock(dispatchUrl) | ||
.patch(`${endpoints.JOBS}/123`).times(1) | ||
.reply(function reply() { | ||
expect(this.req.headers['x-transaction-id']).toEqual(transactionID); | ||
done(); | ||
}); | ||
// it('should append a transaction ID to the headers of an authenticated request', done => { | ||
// const transactionID = '12345'; | ||
// const scope = nock(dispatchUrl) | ||
// .patch(`${endpoints.JOBS}/123`).times(1) | ||
// .reply(function reply() { | ||
// expect(this.req.headers['x-transaction-id']).toEqual(transactionID); | ||
// done(); | ||
// }); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
client.entities.job(123).update(validJobProperties, { transactionID }); | ||
// client.setBearerToken(testBearerToken, testRefreshToken); | ||
// client.entities.job(123).update(validJobProperties, { transactionID }); | ||
expect(scope.isDone()).toEqual(true); | ||
}); | ||
// expect(scope.isDone()).toEqual(true); | ||
// }); | ||
}); | ||
@@ -336,0 +336,0 @@ |
{ | ||
"name": "dispatch-node-sdk", | ||
"version": "3.7.0", | ||
"version": "3.8.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
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
283993
85
6990