burnchart/test/request.coffee

52 lines
1.3 KiB
CoffeeScript

#!/usr/bin/env coffee
proxy = do require('proxyquire').noCallThru
assert = require 'assert'
path = require 'path'
class Superagent
get: -> @
set: -> @
end: (cb) -> cb @response
request = proxy path.resolve(__dirname, '../src/modules/request.coffee'),
'./require':
'_': require 'lodash'
'superagent': sa = new Superagent()
'd3': null
'async': null
'marked': null
module.exports =
'request - all milestones (ok)': (done) ->
sa.response =
'statusType': 2
'error': no
'body': [ null ]
request.all_milestones {}, (err) ->
assert.ifError err
do done
'request - one milestone (404)': (done) ->
sa.response =
'statusType': 4
'error': Error "cannot GET undefined (404)"
'body':
'documentation_url': "http://developer.github.com/v3"
'message': "Not Found"
request.one_milestone {}, 9, (err) ->
assert.equal err, 'Not Found'
do done
'request - one milestone (500)': (done) ->
sa.response =
'statusType': 5
'error': Error "Error"
'body': null
request.one_milestone {}, 9, (err) ->
assert.equal err, 'Error'
do done