-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
296 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
tests/lib/client/decision/createByAccountIdAndUserId-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
const _ = require('lodash'); | ||
const should = require('should'); | ||
const sinon = require('sinon'); | ||
|
||
let siftScience; | ||
let v3HttpClient; | ||
let sandbox; | ||
|
||
before(() => { | ||
siftScience = require('../../../../lib'); | ||
v3HttpClient = require('../../../../lib/client/v3HttpClient'); | ||
|
||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
describe('lib', () => { | ||
describe('client', () => { | ||
describe('decisions', () => { | ||
describe('createByAccountIdAndUserId', () => { | ||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
const key = '123'; | ||
let siftScienceClient; | ||
|
||
before('create siftScienceClient', () => { | ||
siftScienceClient = siftScience.init(key); | ||
}); | ||
|
||
describe('when called without accountId', () => { | ||
let accountId = null; | ||
|
||
it('should reject with an error', () => { | ||
return siftScienceClient.decisions.createByAccountIdAndUserId(accountId) | ||
.then(should.not.exist) | ||
.catch(err => { | ||
should.exist(err); | ||
err.should.be.instanceOf(Error); | ||
err.message.should.equal('accountId is required'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when called without userId', () => { | ||
let accountId = '123'; | ||
let userId = null; | ||
|
||
it('should reject with an error', () => { | ||
return siftScienceClient.decisions.createByAccountIdAndUserId(accountId, userId) | ||
.then(should.not.exist) | ||
.catch(err => { | ||
should.exist(err); | ||
err.should.be.instanceOf(Error); | ||
err.message.should.equal('userId is required'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when called with an accountId and userId', () => { | ||
let accountId = '123'; | ||
let userId = '123'; | ||
let data = {}; | ||
let response = { | ||
data: {} | ||
}; | ||
|
||
let postStub; | ||
|
||
before('stub v3HttpClient.post()', () => { | ||
postStub = sandbox.stub(v3HttpClient, 'post') | ||
.returns(Promise.resolve(response)); | ||
}); | ||
|
||
it('should call v3HttpClient.post()', () => { | ||
return siftScienceClient.decisions.createByAccountIdAndUserId(accountId, userId, data) | ||
.then(result => { | ||
should.exist(result); | ||
result.should.deepEqual(response.data); | ||
|
||
postStub.callCount.should.equal(1); | ||
postStub.args[0][0].should.equal(`/accounts/${accountId}/users/${userId}/decisions`); | ||
postStub.args[0][1].should.deepEqual(data); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when called with params', () => { | ||
let accountId = '123'; | ||
let userId = '123'; | ||
let data = {}; | ||
let params = { | ||
foo: 'bar' | ||
}; | ||
let response = { | ||
data: {} | ||
}; | ||
|
||
let postStub; | ||
|
||
before('stub v3HttpClient.post()', () => { | ||
postStub = sandbox.stub(v3HttpClient, 'post') | ||
.returns(Promise.resolve(response)); | ||
}); | ||
|
||
it('should call v3HttpClient.post()', () => { | ||
return siftScienceClient.decisions.createByAccountIdAndUserId(accountId, userId, data, params) | ||
.then(result => { | ||
should.exist(result); | ||
result.should.deepEqual(response.data); | ||
|
||
postStub.callCount.should.equal(1); | ||
postStub.args[0][0].should.equal(`/accounts/${accountId}/users/${userId}/decisions`); | ||
postStub.args[0][1].should.deepEqual(_.extend(data, { | ||
$api_key: key | ||
})); | ||
postStub.args[0][2].should.deepEqual(params); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
const should = require('should'); | ||
const sinon = require('sinon'); | ||
|
||
let siftScience; | ||
let v3HttpClient; | ||
let sandbox; | ||
|
||
before(() => { | ||
siftScience = require('../../../../lib'); | ||
v3HttpClient = require('../../../../lib/client/v3HttpClient'); | ||
|
||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
describe('lib', () => { | ||
describe('client', () => { | ||
describe('decisions', () => { | ||
describe('listByAccountId', () => { | ||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
const key = '123'; | ||
let siftScienceClient; | ||
|
||
before('create siftScienceClient', () => { | ||
siftScienceClient = siftScience.init(key); | ||
}); | ||
|
||
describe('when called without accountId', () => { | ||
let accountId = null; | ||
|
||
it('should reject with an error', () => { | ||
return siftScienceClient.decisions.listByAccountId(accountId) | ||
.then(should.not.exist) | ||
.catch(err => { | ||
should.exist(err); | ||
err.should.be.instanceOf(Error); | ||
err.message.should.equal('accountId is required'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when called with an accountId', () => { | ||
let accountId = '123'; | ||
let response = { | ||
data: {} | ||
}; | ||
|
||
let getStub; | ||
|
||
before('stub v3HttpClient.get()', () => { | ||
getStub = sandbox.stub(v3HttpClient, 'get') | ||
.returns(Promise.resolve(response)); | ||
}); | ||
|
||
it('should call v3HttpClient.get()', () => { | ||
return siftScienceClient.decisions.listByAccountId(accountId) | ||
.then(result => { | ||
should.exist(result); | ||
result.should.deepEqual(response.data); | ||
|
||
getStub.callCount.should.equal(1); | ||
getStub.args[0][0].should.equal(`/accounts/${accountId}/decisions`); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when called with params', () => { | ||
let accountId = '123'; | ||
let params = { | ||
foo: 'bar' | ||
}; | ||
let response = { | ||
data: {} | ||
}; | ||
|
||
let getStub; | ||
|
||
before('stub v3HttpClient.get()', () => { | ||
getStub = sandbox.stub(v3HttpClient, 'get') | ||
.returns(Promise.resolve(response)); | ||
}); | ||
|
||
it('should call v3HttpClient.get()', () => { | ||
return siftScienceClient.decisions.listByAccountId(accountId, params) | ||
.then(result => { | ||
should.exist(result); | ||
result.should.deepEqual(response.data); | ||
|
||
getStub.callCount.should.equal(1); | ||
getStub.args[0][0].should.equal(`/accounts/${accountId}/decisions`); | ||
getStub.args[0][1].should.deepEqual(params); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |