not found and empty milestones cases
This commit is contained in:
parent
3abc97e45e
commit
c107a15abb
|
@ -5,7 +5,10 @@ module.exports =
|
||||||
'get_current': (user, repo, cb) ->
|
'get_current': (user, repo, cb) ->
|
||||||
req.milestones user, repo, (err, data) ->
|
req.milestones user, repo, (err, data) ->
|
||||||
return cb err if err
|
return cb err if err
|
||||||
|
return cb data.message if data.message
|
||||||
|
return cb 'No open milestones for a repo' unless data.length
|
||||||
# Go through the milestones looking for one that ends/ended soonest.
|
# Go through the milestones looking for one that ends/ended soonest.
|
||||||
max = [ null, +Infinity ]
|
max = [ null, 'A' ]
|
||||||
( max = [ parseInt(i), int ] if (int = +new Date due_on) < max[1] for i, { due_on } of data )
|
for i, { due_on } of data when due_on < max[1]
|
||||||
|
max = [ parseInt(i), due_on ]
|
||||||
cb null, data[max[0]]
|
cb null, data[max[0]]
|
|
@ -10,7 +10,7 @@ milestones = proxy path.resolve(__dirname, '../src/milestones.coffee'),
|
||||||
'./request': req
|
'./request': req
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
'get current': (done) ->
|
'get current from 1': (done) ->
|
||||||
req.milestones = (user, repo, cb) ->
|
req.milestones = (user, repo, cb) ->
|
||||||
cb null, [
|
cb null, [
|
||||||
{
|
{
|
||||||
|
@ -23,4 +23,45 @@ module.exports =
|
||||||
milestones.get_current null, null, (err, milestone) ->
|
milestones.get_current null, null, (err, milestone) ->
|
||||||
assert.ifError err
|
assert.ifError err
|
||||||
assert.equal milestone.number, 1
|
assert.equal milestone.number, 1
|
||||||
|
done.call null
|
||||||
|
|
||||||
|
'get current from > 1': (done) ->
|
||||||
|
req.milestones = (user, repo, cb) ->
|
||||||
|
cb null, [
|
||||||
|
{
|
||||||
|
'number': 1
|
||||||
|
'created_at': '2013-01-01T00:00:00Z'
|
||||||
|
'due_on': '2013-02-01T00:00:00Z'
|
||||||
|
}
|
||||||
|
{
|
||||||
|
'number': 2
|
||||||
|
'created_at': '2013-01-01T00:00:00Z'
|
||||||
|
'due_on': '2013-01-15T00:00:00Z'
|
||||||
|
}
|
||||||
|
{
|
||||||
|
'number': 3
|
||||||
|
'created_at': '2013-01-01T00:00:00Z'
|
||||||
|
'due_on': '2013-02-15T00:00:00Z'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
milestones.get_current null, null, (err, milestone) ->
|
||||||
|
assert.ifError err
|
||||||
|
assert.equal milestone.number, 2
|
||||||
|
done.call null
|
||||||
|
|
||||||
|
'get current when empty': (done) ->
|
||||||
|
req.milestones = (user, repo, cb) ->
|
||||||
|
cb null, []
|
||||||
|
|
||||||
|
milestones.get_current null, null, (err, milestone) ->
|
||||||
|
assert.equal err, 'No open milestones for a repo'
|
||||||
|
done.call null
|
||||||
|
|
||||||
|
'get current when not found': (done) ->
|
||||||
|
req.milestones = (user, repo, cb) ->
|
||||||
|
cb null, { 'message': 'Not Found' }
|
||||||
|
|
||||||
|
milestones.get_current null, null, (err, milestone) ->
|
||||||
|
assert.equal err, 'Not Found'
|
||||||
done.call null
|
done.call null
|
Loading…
Reference in New Issue