Socket
Socket
Sign inDemoInstall

dispatch-node-sdk

Package Overview
Dependencies
Maintainers
4
Versions
148
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dispatch-node-sdk - npm Package Compare versions

Comparing version 3.8.0 to 3.8.1

9

dist/lib/index.js

@@ -6,3 +6,3 @@ 'use strict';

});
exports.UnprocessableEntityError = exports.UnauthorizedError = exports.timezoneMap = exports.RawClient = exports.NotFoundError = exports.inWorkHours = exports.getCurrentTimeInTimezone = exports.generateUUID = exports.ForbiddenError = exports.AUTH_MODE_NONE = exports.AUTH_MODE_HMAC = exports.AUTH_MODE_BEARER = exports.AppointmentHelpers = exports.APIError = exports.Analytics = undefined;
exports.endpoints = exports.UnprocessableEntityError = exports.UnauthorizedError = exports.timezoneMap = exports.RawClient = exports.NotFoundError = exports.inWorkHours = exports.getCurrentTimeInTimezone = exports.generateUUID = exports.ForbiddenError = exports.AUTH_MODE_NONE = exports.AUTH_MODE_HMAC = exports.AUTH_MODE_BEARER = exports.AppointmentHelpers = exports.APIError = exports.Analytics = undefined;

@@ -35,2 +35,6 @@ var _analytics = require('./analytics');

var _endpoints = require('./endpoints');
var endpoints = _interopRequireWildcard(_endpoints);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

@@ -55,2 +59,3 @@

exports.UnauthorizedError = _errors.UnauthorizedError;
exports.UnprocessableEntityError = _errors.UnprocessableEntityError;
exports.UnprocessableEntityError = _errors.UnprocessableEntityError;
exports.endpoints = endpoints;

@@ -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');
});
});
});

@@ -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 @@

@@ -15,2 +15,3 @@ import Analytics from './analytics';

import { inWorkHours } from './workHours';
import * as endpoints from './endpoints';

@@ -34,2 +35,3 @@ export default Dispatch;

UnprocessableEntityError,
endpoints,
};
{
"name": "dispatch-node-sdk",
"version": "3.8.0",
"version": "3.8.1",
"description": "High- and low-level libraries for interacting with the Dispatch API",

@@ -13,3 +13,3 @@ "main": "dist/lib/index.js",

"mocha": "mocha --compilers js:babel-core/register --recursive 'lib/**/*.tests.js'",
"prepublish": "npm run test && npm run build",
"prepublish": "npm run build",
"test": "npm run lint && npm run mocha",

@@ -16,0 +16,0 @@ "test:cover": "istanbul cover _mocha -- --compilers js:babel-core/register --recursive 'lib/**/*.tests.js'",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc