Skip to content

Instantly share code, notes, and snippets.

@80xer
Created July 10, 2017 09:53
Show Gist options
  • Save 80xer/3f15fdface0ce96deebbd613b4e0fc5f to your computer and use it in GitHub Desktop.
Save 80xer/3f15fdface0ce96deebbd613b4e0fc5f to your computer and use it in GitHub Desktop.
request test
'use strict';
import nock from 'nock';
import chai from 'chai';
import request from 'request'
const expect = chai.expect;
const tax = {
calculate: (subtotal, state, done) => {
if (state !== 'CA') {
return done({ amount: 0 });
}
request.post(
{
url: 'https://some-tax-service.com/request',
method: 'POST',
json: {
subtotal: subtotal,
},
},
(error, response, body) => {
done(body);
}
);
},
};
describe('tax', () => {
it('calculate() should send the subtotal in the request', done => {
nock('https://some-tax-service.com')
.post('/request')
.reply(200, (uri, requestBody) => {
return {
amount: requestBody.subtotal * 0.1,
};
});
tax.calculate(100, 'CA', taxDetails => {
expect(taxDetails).to.eql({ amount: 10 });
done();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment