Created
July 10, 2017 09:53
-
-
Save 80xer/3f15fdface0ce96deebbd613b4e0fc5f to your computer and use it in GitHub Desktop.
request test
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
'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