2014-10-27 03:10:41 +00:00
|
|
|
proxy = do require('proxyquire').noCallThru
|
|
|
|
assert = require 'assert'
|
|
|
|
path = require 'path'
|
2014-10-29 04:30:42 +00:00
|
|
|
require 'blanket'
|
2014-10-27 03:10:41 +00:00
|
|
|
|
|
|
|
class Sa
|
|
|
|
|
|
|
|
# How soon do we call back?
|
|
|
|
timeout: 1
|
|
|
|
|
|
|
|
# Save the uri.
|
|
|
|
get: (uri) ->
|
|
|
|
@params = { uri }
|
|
|
|
@
|
|
|
|
|
|
|
|
# Save the key-value pair.
|
|
|
|
set: (key, value) ->
|
|
|
|
@params[key] = value
|
|
|
|
@
|
|
|
|
|
|
|
|
# Call back with the response.
|
|
|
|
end: (cb) ->
|
|
|
|
setTimeout =>
|
|
|
|
cb null, @response
|
|
|
|
, @timeout
|
|
|
|
|
2014-10-29 02:12:02 +00:00
|
|
|
superagent = new Sa()
|
|
|
|
|
|
|
|
# Proxy the superagent lib.
|
2014-10-27 03:10:41 +00:00
|
|
|
request = proxy path.resolve(__dirname, '../src/modules/github/request.coffee'),
|
2014-10-29 02:12:02 +00:00
|
|
|
'superagent': superagent
|
|
|
|
|
|
|
|
# User is ready, make the requests.
|
|
|
|
user = require '../src/models/user.coffee'
|
|
|
|
user.set 'ready', yes
|
2014-10-27 03:10:41 +00:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
'request - all milestones (ok)': (done) ->
|
2014-10-29 02:12:02 +00:00
|
|
|
superagent.response =
|
2014-10-27 03:10:41 +00:00
|
|
|
'statusType': 2
|
|
|
|
'error': no
|
|
|
|
'body': [ null ]
|
|
|
|
|
2014-10-29 02:12:02 +00:00
|
|
|
owner = 'radekstepan'
|
|
|
|
name = 'burnchart'
|
|
|
|
|
|
|
|
request.allMilestones { owner, name }, (err, data) ->
|
2014-10-27 03:10:41 +00:00
|
|
|
assert.ifError err
|
2014-10-29 02:12:02 +00:00
|
|
|
assert.deepEqual superagent.params,
|
|
|
|
'uri': 'https://api.github.com/repos/radekstepan/burnchart/milestones?state=open&sort=due_date&direction=asc'
|
2014-10-27 03:10:41 +00:00
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Accept': 'application/vnd.github.v3'
|
|
|
|
assert.deepEqual data, [ null ]
|
|
|
|
do done
|
|
|
|
|
|
|
|
'request - one milestone (ok)': (done) ->
|
2014-10-29 02:12:02 +00:00
|
|
|
superagent.response =
|
2014-10-27 03:10:41 +00:00
|
|
|
'statusType': 2
|
|
|
|
'error': no
|
|
|
|
'body': [ null ]
|
|
|
|
|
2014-10-29 02:12:02 +00:00
|
|
|
owner = 'radekstepan'
|
|
|
|
name = 'burnchart'
|
|
|
|
milestone = 1
|
|
|
|
|
|
|
|
request.oneMilestone { owner, name, milestone }, (err, data) ->
|
2014-10-27 03:10:41 +00:00
|
|
|
assert.ifError err
|
2014-10-29 02:12:02 +00:00
|
|
|
assert.deepEqual superagent.params,
|
|
|
|
'uri': 'https://api.github.com/repos/radekstepan/burnchart/milestones/1?state=open&sort=due_date&direction=asc'
|
2014-10-27 03:10:41 +00:00
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Accept': 'application/vnd.github.v3'
|
|
|
|
assert.deepEqual data, [ null ]
|
|
|
|
do done
|
|
|
|
|
|
|
|
'request - one milestone (404)': (done) ->
|
2014-10-29 02:12:02 +00:00
|
|
|
superagent.response =
|
2014-10-27 03:10:41 +00:00
|
|
|
'statusType': 4
|
|
|
|
'error': Error "cannot GET undefined (404)"
|
|
|
|
'body':
|
|
|
|
'documentation_url': "http://developer.github.com/v3"
|
|
|
|
'message': "Not Found"
|
2014-10-29 02:12:02 +00:00
|
|
|
|
|
|
|
owner = 'radekstepan'
|
|
|
|
name = 'burnchart'
|
|
|
|
milestone = 0
|
2014-10-27 03:10:41 +00:00
|
|
|
|
2014-10-29 02:12:02 +00:00
|
|
|
request.oneMilestone { owner, name, milestone }, (err) ->
|
2014-10-27 03:10:41 +00:00
|
|
|
assert.equal err, 'Not Found'
|
|
|
|
do done
|
|
|
|
|
|
|
|
'request - one milestone (500)': (done) ->
|
2014-10-29 02:12:02 +00:00
|
|
|
superagent.response =
|
2014-10-27 03:10:41 +00:00
|
|
|
'statusType': 5
|
|
|
|
'error': Error "Error"
|
|
|
|
'body': null
|
2014-10-29 02:12:02 +00:00
|
|
|
|
|
|
|
owner = 'radekstepan'
|
|
|
|
name = 'burnchart'
|
|
|
|
milestone = 0
|
2014-10-27 03:10:41 +00:00
|
|
|
|
2014-10-29 02:12:02 +00:00
|
|
|
request.oneMilestone { owner, name, milestone }, (err) ->
|
2014-10-27 03:10:41 +00:00
|
|
|
assert.equal err, 'Error'
|
|
|
|
do done
|
|
|
|
|
|
|
|
'request - all issues (ok)': (done) ->
|
2014-10-29 02:12:02 +00:00
|
|
|
superagent.response =
|
2014-10-27 03:10:41 +00:00
|
|
|
'statusType': 2
|
|
|
|
'error': no
|
|
|
|
'body': [ null ]
|
2014-10-29 02:12:02 +00:00
|
|
|
|
|
|
|
owner = 'radekstepan'
|
|
|
|
name = 'burnchart'
|
|
|
|
milestone = 0
|
2014-10-27 03:10:41 +00:00
|
|
|
|
2014-10-29 02:12:02 +00:00
|
|
|
request.allIssues { owner, name, milestone }, {}, (err, data) ->
|
2014-10-27 03:10:41 +00:00
|
|
|
assert.ifError err
|
2014-10-29 02:12:02 +00:00
|
|
|
assert.deepEqual superagent.params,
|
|
|
|
'uri': 'https://api.github.com/repos/radekstepan/burnchart/issues?milestone=0&per_page=100'
|
2014-10-27 03:10:41 +00:00
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Accept': 'application/vnd.github.v3'
|
|
|
|
assert.deepEqual data, [ null ]
|
|
|
|
do done
|
|
|
|
|
|
|
|
'request - timeout': (done) ->
|
2014-10-29 02:12:02 +00:00
|
|
|
superagent.timeout = 5001
|
|
|
|
superagent.response =
|
2014-10-27 03:10:41 +00:00
|
|
|
'statusType': 2
|
|
|
|
'error': no
|
|
|
|
'body': [ null ]
|
2014-10-29 02:12:02 +00:00
|
|
|
|
|
|
|
owner = 'radekstepan'
|
|
|
|
name = 'burnchart'
|
|
|
|
milestone = 0
|
2014-10-27 03:10:41 +00:00
|
|
|
|
2014-10-29 02:12:02 +00:00
|
|
|
request.allIssues { owner, name, milestone }, {}, (err) ->
|
2014-10-27 03:10:41 +00:00
|
|
|
assert.equal err, 'Request has timed out'
|
|
|
|
do done
|