dispatch-node-sdk
Advanced tools
Comparing version 0.0.39 to 0.0.40
@@ -226,2 +226,17 @@ import _ from 'underscore'; | ||
/** | ||
* Creates a new user and organization using the signup endpoint. | ||
* | ||
* DISP-4285: Add error processing for showing tooltips on frontend | ||
* | ||
* @param {Object} userInfo User data | ||
* @param {Object} organizationInfo Organization data | ||
*/ | ||
signUp(userInfo, organizationInfo) { | ||
return this.getAppClient().then(client => client.post('/v1/signup', { | ||
user: userInfo, | ||
organization: organizationInfo, | ||
})); | ||
} | ||
/** | ||
* Log the user in with their phone number and verification code | ||
@@ -228,0 +243,0 @@ * |
@@ -14,2 +14,4 @@ import nock from 'nock'; | ||
const testRefreshToken = 'this is the refresh token'; | ||
const dispatchUrl = 'https://api.dispatch.me'; | ||
const devDispatchUrl = 'https://api-dev.dispatch.me'; | ||
@@ -22,3 +24,3 @@ describe('client SDK', () => { | ||
it('should log in with email password', (done) => { | ||
const req = nock('https://api.dispatch.me').post('/oauth/token', { | ||
const req = nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'password', | ||
@@ -48,3 +50,3 @@ username: testEmail, | ||
it('should request verification code', (done) => { | ||
const bearerTokenReq = nock('https://api.dispatch.me').post('/oauth/token', { | ||
const bearerTokenReq = nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'client_credentials', | ||
@@ -58,3 +60,3 @@ client_id: testClientID, | ||
const req = nock('https://api.dispatch.me').post(`/v1/phone_numbers/${testPhoneNumber}/verification_codes`).reply(200, { | ||
const req = nock(dispatchUrl).post(`/v1/phone_numbers/${testPhoneNumber}/verification_codes`).reply(200, { | ||
message: 'Verification code requested', | ||
@@ -73,3 +75,3 @@ }); | ||
it('should log in with verification code', (done) => { | ||
const bearerTokenReq = nock('https://api.dispatch.me').post('/oauth/token', { | ||
const bearerTokenReq = nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'client_credentials', | ||
@@ -82,3 +84,3 @@ client_id: testClientID, | ||
}); | ||
const req = nock('https://api.dispatch.me').get(`/v1/phone_numbers/${testPhoneNumber}/verification_codes/${testVerificationCode}`).reply(200, { | ||
const req = nock(dispatchUrl).get(`/v1/phone_numbers/${testPhoneNumber}/verification_codes/${testVerificationCode}`).reply(200, { | ||
access_token: testBearerToken, | ||
@@ -99,3 +101,3 @@ refresh_token: testRefreshToken, | ||
it('should log in with auth token', done => { | ||
const req = nock('https://api.dispatch.me').post('/v1/auth_tokens/12345/exchange').reply(200, { | ||
const req = nock(dispatchUrl).post('/v1/auth_tokens/12345/exchange').reply(200, { | ||
access_token: testBearerToken, | ||
@@ -118,3 +120,3 @@ refresh_token: testRefreshToken, | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock('https://api.dispatch.me').get('/v1/jobs').reply(200, { | ||
nock(dispatchUrl).get('/v1/jobs').reply(200, { | ||
jobs: [ | ||
@@ -142,6 +144,6 @@ { | ||
it('should return meta data with getCollectionMeta', done => { | ||
const client = new Dispatch(testClientID, testClientSecret, 'https://api-dev.dispatch.me'); | ||
const client = new Dispatch(testClientID, testClientSecret, devDispatchUrl); | ||
const query = { limit: 1, offset: 0 }; | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
nock('https://api-dev.dispatch.me').get('/v1/customers?limit=1&offset=0').reply(200, { | ||
nock(devDispatchUrl).get('/v1/customers?limit=1&offset=0').reply(200, { | ||
customers: [{ | ||
@@ -179,6 +181,6 @@ id: 6394, | ||
it('should return meta data as an object (if !meta props are more than 1) with getCollectionMeta', done => { | ||
const client = new Dispatch(testClientID, testClientSecret, 'https://api-dev.dispatch.me'); | ||
const client = new Dispatch(testClientID, testClientSecret, devDispatchUrl); | ||
const query = { limit: 1, offset: 0 }; | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
nock('https://api-dev.dispatch.me').get('/v1/customers?limit=1&offset=0').reply(200, { | ||
nock(devDispatchUrl).get('/v1/customers?limit=1&offset=0').reply(200, { | ||
customers: [{ | ||
@@ -231,3 +233,3 @@ id: 6394, | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock('https://api.dispatch.me').get('/v1/jobs').reply(200, { | ||
nock(dispatchUrl).get('/v1/jobs').reply(200, { | ||
jobs: [ | ||
@@ -254,3 +256,3 @@ { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock('https://api.dispatch.me').get('/v1/jobs?filter[id_eq]=1').reply(200, { | ||
nock(dispatchUrl).get('/v1/jobs?filter[id_eq]=1').reply(200, { | ||
jobs: [ | ||
@@ -275,8 +277,8 @@ { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock('https://api.dispatch.me').get('/').times(1).reply(401); | ||
nock('https://api.dispatch.me').get('/').times(1).reply(200, { | ||
nock(dispatchUrl).get('/').times(1).reply(401); | ||
nock(dispatchUrl).get('/').times(1).reply(200, { | ||
foo: 'bar', | ||
}); | ||
nock('https://api.dispatch.me').post('/oauth/token', { | ||
nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'refresh_token', | ||
@@ -303,8 +305,8 @@ refresh_token: testRefreshToken, | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock('https://api.dispatch.me').get('/').times(1).reply(401); | ||
nock('https://api.dispatch.me').get('/').times(1).reply(200, { | ||
nock(dispatchUrl).get('/').times(1).reply(401); | ||
nock(dispatchUrl).get('/').times(1).reply(200, { | ||
foo: 'bar', | ||
}); | ||
nock('https://api.dispatch.me').post('/oauth/token', { | ||
nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'refresh_token', | ||
@@ -341,3 +343,3 @@ refresh_token: testRefreshToken, | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock('https://api.dispatch.me').get('/').times(1).reply(function reply() { | ||
nock(dispatchUrl).get('/').times(1).reply(function reply() { | ||
expect(this.req.headers['x-transaction-id']).toExist(); | ||
@@ -347,3 +349,3 @@ done(); | ||
nock('https://api.dispatch.me').post('/oauth/token', { | ||
nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'refresh_token', | ||
@@ -365,3 +367,3 @@ refresh_token: testRefreshToken, | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock('https://api.dispatch.me').get('/').times(1).reply(function reply() { | ||
nock(dispatchUrl).get('/').times(1).reply(function reply() { | ||
expect(this.req.headers['x-analytics-tags']).toEqual('foo:bar,bar:foo'); | ||
@@ -371,3 +373,3 @@ done(); | ||
nock('https://api.dispatch.me').post('/oauth/token', { | ||
nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'refresh_token', | ||
@@ -389,3 +391,3 @@ refresh_token: testRefreshToken, | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
nock('https://api.dispatch.me').get('/').times(1).reply(function reply() { | ||
nock(dispatchUrl).get('/').times(1).reply(function reply() { | ||
expect(this.req.headers['x-analytics-tags']).toEqual('baz:bing,foo:bar,bar:foo'); | ||
@@ -395,3 +397,3 @@ done(); | ||
nock('https://api.dispatch.me').post('/oauth/token', { | ||
nock(dispatchUrl).post('/oauth/token', { | ||
grant_type: 'refresh_token', | ||
@@ -624,2 +626,61 @@ 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!', | ||
}); | ||
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: {}, | ||
}, | ||
}); | ||
client.signUp({}, {}).then(response => { | ||
expect(response.organization instanceof UnprocessableEntityError).toEqual(true); | ||
expect(response.user).toEqual(null); | ||
req.done(); | ||
bearerTokenReq.done(); | ||
done(); | ||
}).catch(done()); | ||
}); | ||
}); | ||
}); |
@@ -115,3 +115,9 @@ import * as endpoints from '../endpoints'; | ||
}, | ||
update: (jobProperties) => { | ||
return client | ||
.doAuthenticatedRequest('PATCH', `${endpoints.JOBS}/${id}`, jobProperties) | ||
.then(response => response.job); | ||
}, | ||
}); | ||
} |
@@ -205,2 +205,16 @@ import expect from 'expect'; | ||
}); | ||
describe('update', () => { | ||
it('should make a PATCH request with job properties to be updated', () => { | ||
const client = new Dispatch(testClientID, testClientSecret); | ||
const jobProperties = { status: 'cancelled' }; | ||
const scope = nock('https://api.dispatch.me') | ||
.patch(`${endpoints.JOBS}/123`, jobProperties) | ||
.reply(200); | ||
client.setBearerToken(testBearerToken, testRefreshToken); | ||
client.entities.job(123).update(jobProperties); | ||
expect(scope.isDone()).toEqual(true); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "dispatch-node-sdk", | ||
"version": "0.0.39", | ||
"version": "0.0.40", | ||
"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
176505
4556