spur-common
Version:
Common node library that is implemented through the use of spur-ioc and bluebird promises.
56 lines (42 loc) • 1.29 kB
text/coffeescript
nock = require "nock"
describe "HTTPLogging", ->
beforeEach ->
injector().inject (, , , , )=>
.mockDuration(33)
.setGlobalPlugins([])
.useRecorder()
nock.disableNetConnect()
afterEach ->
nock.cleanAll()
it "should exist", ->
expect().to.exist
it "http success", (done)->
nock("http://someurl")
.get("/")
.reply(200, {
message:"response"
})
.get("http://someurl")
.promise().then (res)=>
expect(.recorded.info).to.deep.equal [
[ 'HTTPService attempting: GET http://someurl' ],
[ 'HTTPService success: GET http://someurl, timing:33ms, status:200' ]
]
done()
it "http error",(done)->
nock("http://someurl")
.get("/")
.reply(400, {
message:"response"
})
.get("http://someurl")
.promise().catch (e)=>
expect(.recorded).to.deep.equal {
info: [ [ 'HTTPService attempting: GET http://someurl' ] ],
error:
[ [ 'HTTPService error: GET http://someurl, timing:33ms, status:400',
'Validation Error' ] ]
}
done()