Skip to content

Commit

Permalink
update(tests/decision): add more tests for better coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vanatd committed Mar 30, 2020
1 parent d8a3040 commit d79a387
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/lib/client/decision/applyByAccountIdAndOrderId-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,29 @@ describe('lib', () => {
});
});
});

describe('when call return an error', () => {
const accountId = '123';
const userId = '123';
const orderId = '123';
const error = new Error('Some error');


before('stub v3HttpClient.post()', () => {
sandbox.stub(v3HttpClient, 'post')
.returns(Promise.reject(error));
});

it('should also throw error if v3HttpClient.post() throw it', () => {
return siftScienceClient.decisions.applyByAccountIdAndOrderId(accountId, userId, orderId)
.then(should.not.exist)
.catch((err) => {
should.exist(err);
err.should.be.instanceOf(Error);
err.message.should.equal(error.message);
});
});
});
});
});
});
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/client/decision/applyByAccountIdAndSessionId-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,29 @@ describe('lib', () => {
});
});
});

describe('when call return an error', () => {
const accountId = '123';
const userId = '123';
const sessionId = '123';
const error = new Error('Some error');


before('stub v3HttpClient.post()', () => {
sandbox.stub(v3HttpClient, 'post')
.returns(Promise.reject(error));
});

it('should also throw error if v3HttpClient.post() throw it', () => {
return siftScienceClient.decisions.applyByAccountIdAndSessionId(accountId, userId, sessionId)
.then(should.not.exist)
.catch((err) => {
should.exist(err);
err.should.be.instanceOf(Error);
err.message.should.equal(error.message);
});
});
});
});
});
});
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/client/decision/applyByAccountIdAndUserId-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,28 @@ describe('lib', () => {
});
});
});

describe('when call return an error', () => {
const accountId = '123';
const userId = '123';
const error = new Error('Some error');


before('stub v3HttpClient.post()', () => {
sandbox.stub(v3HttpClient, 'post')
.returns(Promise.reject(error));
});

it('should also throw error if v3HttpClient.post() throw it', () => {
return siftScienceClient.decisions.applyByAccountIdAndUserId(accountId, userId)
.then(should.not.exist)
.catch((err) => {
should.exist(err);
err.should.be.instanceOf(Error);
err.message.should.equal(error.message);
});
});
});
});
});
});
Expand Down
32 changes: 32 additions & 0 deletions tests/lib/client/decision/getByAccountIdAndOrderId-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,38 @@ describe('lib', () => {
});
});
});

describe('when call return an error', () => {
const accountId = '123';
const orderId = '123';
const error = new Error('Some error');

const key = '123';
let siftScienceClient;

before('create siftScienceClient', () => {
siftScienceClient = new SiftScienceClient(key);
});

before('stub v3HttpClient.get()', () => {
sandbox.stub(v3HttpClient, 'get')
.returns(Promise.reject(error));
});

afterEach(() => {
sandbox.restore();
});

it('should also throw error if v3HttpClient.get() throw it', () => {
return siftScienceClient.decisions.getByAccountIdAndOrderId(accountId, orderId)
.then(should.not.exist)
.catch((err) => {
should.exist(err);
err.should.be.instanceOf(Error);
err.message.should.equal(error.message);
});
});
});
});
});
});
32 changes: 32 additions & 0 deletions tests/lib/client/decision/getByAccountIdAndUserId-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,38 @@ describe('lib', () => {
});
});
});

describe('when call return an error', () => {
const accountId = '123';
const userId = '123';
const error = new Error('Some error');

const key = '123';
let siftScienceClient;

before('create siftScienceClient', () => {
siftScienceClient = new SiftScienceClient(key);
});

before('stub v3HttpClient.get()', () => {
sandbox.stub(v3HttpClient, 'get')
.returns(Promise.reject(error));
});

afterEach(() => {
sandbox.restore();
});

it('should also throw error if v3HttpClient.get() throw it', () => {
return siftScienceClient.decisions.getByAccountIdAndUserId(accountId, userId)
.then(should.not.exist)
.catch((err) => {
should.exist(err);
err.should.be.instanceOf(Error);
err.message.should.equal(error.message);
});
});
});
});
});
});
31 changes: 31 additions & 0 deletions tests/lib/client/decision/listByAccountId-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,37 @@ describe('lib', () => {
});
});
});

describe('when call return an error', () => {
const accountId = '123';
const error = new Error('Some error');

const key = '123';
let siftScienceClient;

before('create siftScienceClient', () => {
siftScienceClient = new SiftScienceClient(key);
});

before('stub v3HttpClient.get()', () => {
sandbox.stub(v3HttpClient, 'get')
.returns(Promise.reject(error));
});

afterEach(() => {
sandbox.restore();
});

it('should also throw error if v3HttpClient.get() throw it', () => {
return siftScienceClient.decisions.listByAccountId(accountId)
.then(should.not.exist)
.catch((err) => {
should.exist(err);
err.should.be.instanceOf(Error);
err.message.should.equal(error.message);
});
});
});
});
});
});
Expand Down

0 comments on commit d79a387

Please sign in to comment.