2013-08-12 18:23:30 +00:00
|
|
|
#!/usr/bin/env coffee
|
|
|
|
assert = require 'assert'
|
|
|
|
path = require 'path'
|
|
|
|
proxy = require 'proxyquire'
|
|
|
|
|
|
|
|
req = {}
|
|
|
|
|
2013-08-15 17:12:12 +00:00
|
|
|
milestones = proxy path.resolve(__dirname, '../src/modules/milestones.coffee'),
|
2013-08-12 18:23:30 +00:00
|
|
|
'./request': req
|
|
|
|
|
|
|
|
module.exports =
|
2013-08-12 18:43:58 +00:00
|
|
|
'get current from 1': (done) ->
|
2013-08-13 12:05:21 +00:00
|
|
|
req.all_milestones = (opts, cb) ->
|
2013-08-12 18:23:30 +00:00
|
|
|
cb null, [
|
|
|
|
{
|
|
|
|
'number': 1
|
|
|
|
'created_at': '2013-01-01T00:00:00Z'
|
|
|
|
'due_on': '2013-02-01T00:00:00Z'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2013-08-13 12:05:21 +00:00
|
|
|
milestones.get_current {}, (err, warn, milestone) ->
|
2013-08-12 18:23:30 +00:00
|
|
|
assert.ifError err
|
|
|
|
assert.equal milestone.number, 1
|
2013-08-12 18:43:58 +00:00
|
|
|
done.call null
|
|
|
|
|
2013-08-15 19:30:06 +00:00
|
|
|
# We always take from head because of request params.
|
2013-08-12 18:43:58 +00:00
|
|
|
'get current from > 1': (done) ->
|
2013-08-13 12:05:21 +00:00
|
|
|
req.all_milestones = (opts, cb) ->
|
2013-08-12 18:43:58 +00:00
|
|
|
cb null, [
|
|
|
|
{
|
2013-08-15 19:30:06 +00:00
|
|
|
'number': 2
|
2013-08-12 18:43:58 +00:00
|
|
|
'created_at': '2013-01-01T00:00:00Z'
|
2013-08-15 19:30:06 +00:00
|
|
|
'due_on': '2013-01-15T00:00:00Z'
|
2013-08-12 18:43:58 +00:00
|
|
|
}
|
|
|
|
{
|
2013-08-15 19:30:06 +00:00
|
|
|
'number': 1
|
2013-08-12 18:43:58 +00:00
|
|
|
'created_at': '2013-01-01T00:00:00Z'
|
2013-08-15 19:30:06 +00:00
|
|
|
'due_on': '2013-02-01T00:00:00Z'
|
2013-08-12 18:43:58 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
'number': 3
|
|
|
|
'created_at': '2013-01-01T00:00:00Z'
|
|
|
|
'due_on': '2013-02-15T00:00:00Z'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2013-08-13 12:05:21 +00:00
|
|
|
milestones.get_current {}, (err, warn, milestone) ->
|
2013-08-12 18:43:58 +00:00
|
|
|
assert.ifError err
|
|
|
|
assert.equal milestone.number, 2
|
|
|
|
done.call null
|
|
|
|
|
|
|
|
'get current when empty': (done) ->
|
2013-08-13 12:05:21 +00:00
|
|
|
req.all_milestones = (opts, cb) ->
|
2013-08-12 18:43:58 +00:00
|
|
|
cb null, []
|
|
|
|
|
2013-08-13 12:05:21 +00:00
|
|
|
milestones.get_current {}, (err, warn, milestone) ->
|
2013-08-12 19:09:43 +00:00
|
|
|
assert.ifError err
|
|
|
|
assert.equal warn, 'No open milestones for repo'
|
2013-08-12 18:43:58 +00:00
|
|
|
done.call null
|
|
|
|
|
|
|
|
'get current when not found': (done) ->
|
2013-08-13 12:05:21 +00:00
|
|
|
req.all_milestones = (opts, cb) ->
|
2013-08-12 18:43:58 +00:00
|
|
|
cb null, { 'message': 'Not Found' }
|
|
|
|
|
2013-08-13 12:05:21 +00:00
|
|
|
milestones.get_current {}, (err, warn, milestone) ->
|
2013-08-12 18:43:58 +00:00
|
|
|
assert.equal err, 'Not Found'
|
2013-08-12 19:09:43 +00:00
|
|
|
done.call null
|
|
|
|
|
|
|
|
'get current when no issues': (done) ->
|
2013-08-13 12:05:21 +00:00
|
|
|
req.all_milestones = (opts, cb) ->
|
2013-08-12 19:09:43 +00:00
|
|
|
cb null, [
|
|
|
|
{
|
|
|
|
'number': 1
|
|
|
|
'created_at': '2013-01-01T00:00:00Z'
|
|
|
|
'due_on': '2013-02-01T00:00:00Z',
|
|
|
|
'open_issues': 0,
|
|
|
|
'closed_issues': 0
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2013-08-13 12:05:21 +00:00
|
|
|
milestones.get_current {}, (err, warn, milestone) ->
|
2013-08-12 19:09:43 +00:00
|
|
|
assert.ifError err
|
|
|
|
assert.equal warn, 'No issues for milestone'
|
2013-08-12 18:23:30 +00:00
|
|
|
done.call null
|