burnchart/test/request.coffee

114 lines
3.3 KiB
CoffeeScript
Raw Normal View History

2013-10-05 11:45:07 +00:00
#!/usr/bin/env coffee
proxy = do require('proxyquire').noCallThru
assert = require 'assert'
path = require 'path'
2013-12-31 17:13:13 +00:00
_ = require 'lodash'
2013-10-05 11:45:07 +00:00
class Superagent
2014-01-01 13:30:32 +00:00
# How soon do we call back?
timeout: 1
# Save the uri.
2013-12-31 17:13:13 +00:00
get: (uri) ->
@params = { uri }
@
2014-01-01 13:30:32 +00:00
# Save the key-value pair.
2013-12-31 17:13:13 +00:00
set: (key, value) ->
@params[key] = value
@
2014-01-01 13:30:32 +00:00
# Call back with the response.
end: (cb) ->
setTimeout =>
cb null, @response
, @timeout
2013-10-05 11:45:07 +00:00
request = proxy path.resolve(__dirname, '../src/modules/request.coffee'),
2013-11-05 12:44:15 +00:00
'./require':
'_': require 'lodash'
'superagent': sa = new Superagent()
'd3': null
'async': null
'marked': null
2013-10-05 11:45:07 +00:00
module.exports =
'request - all milestones (ok)': (done) ->
sa.response =
'statusType': 2
'error': no
'body': [ null ]
2013-12-31 17:13:13 +00:00
request.all_milestones {}, (err, data) ->
2013-10-05 11:45:07 +00:00
assert.ifError err
2013-12-31 17:13:13 +00:00
assert.deepEqual sa.params,
'uri': 'undefined://undefined/repos/undefined/milestones?state=open&sort=due_date&direction=asc'
'Content-Type': 'application/json',
'Accept': 'application/vnd.github.v3'
assert.deepEqual data, [ null ]
2013-10-05 11:45:07 +00:00
do done
2013-12-31 17:13:13 +00:00
'request - one milestone (ok)': (done) ->
sa.response =
'statusType': 2
'error': no
'body': [ null ]
request.one_milestone {}, 1, (err, data) ->
assert.ifError err
assert.deepEqual sa.params,
'uri': 'undefined://undefined/repos/undefined/milestones/1?state=open&sort=due_date&direction=asc'
'Content-Type': 'application/json',
'Accept': 'application/vnd.github.v3'
assert.deepEqual data, [ null ]
do done
2013-10-05 11:45:07 +00:00
'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'
2013-12-31 17:13:13 +00:00
do done
'request - all issues (ok)': (done) ->
sa.response =
'statusType': 2
'error': no
'body': [ null ]
request.all_issues {}, {}, (err, data) ->
assert.ifError err
assert.deepEqual sa.params,
'uri': 'undefined://undefined/repos/undefined/issues?per_page=100'
'Content-Type': 'application/json',
'Accept': 'application/vnd.github.v3'
assert.deepEqual data, [ null ]
2014-01-01 13:30:32 +00:00
do done
'request - timeout': (done) ->
sa.timeout = 10001
sa.response =
'statusType': 2
'error': no
'body': [ null ]
request.all_issues {}, {}, (err) ->
assert.equal err, 'Request has timed out'
2013-10-05 11:45:07 +00:00
do done