burnchart/test/milestones.coffee

188 lines
5.9 KiB
CoffeeScript
Raw Normal View History

#!/usr/bin/env coffee
2013-09-29 20:43:20 +00:00
proxy = do require('proxyquire').noCallThru
assert = require 'assert'
path = require 'path'
req = {}
2013-08-15 17:12:12 +00:00
milestones = proxy path.resolve(__dirname, '../src/modules/milestones.coffee'),
'./request': req
2013-11-05 12:44:15 +00:00
'./require':
'_': require 'lodash'
'superagent': null
'd3': null
'async': null
'marked': require 'marked'
2013-09-29 20:43:20 +00:00
module.exports =
'milestones - get current from 1': (done) ->
2013-08-13 12:05:21 +00:00
req.all_milestones = (opts, cb) ->
cb null, [
{
'number': 1
'created_at': '2013-01-01T00:00:00Z'
'due_on': '2013-02-01T00:00:00Z'
}
]
2013-10-05 11:45:07 +00:00
milestones {}, (err, warn, milestone) ->
assert.ifError err
assert.equal milestone.number, 1
2013-09-29 20:43:20 +00:00
do done
2013-08-12 18:43:58 +00:00
'milestones - get current from 1 when milestone has no due date': (done) ->
req.all_milestones = (opts, cb) ->
cb null, [
{
'number': 1
'created_at': '2013-01-01T00:00:00Z'
'due_on': null
}
]
2013-10-05 11:45:07 +00:00
milestones {}, (err, warn, milestone) ->
assert.ifError err
assert.equal milestone.number, 1
do done
2013-08-15 19:30:06 +00:00
# We always take from head because of request params.
2013-09-29 20:43:20 +00:00
'milestones - 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-10-05 11:45:07 +00:00
milestones {}, (err, warn, milestone) ->
2013-08-12 18:43:58 +00:00
assert.ifError err
assert.equal milestone.number, 2
2013-09-29 20:43:20 +00:00
do done
2013-08-12 18:43:58 +00:00
'milestones - get current from > 1 when there are milestones without due date': (done) ->
req.all_milestones = (opts, cb) ->
cb null, [
{
'number': 2
'created_at': '2013-01-01T00:00:00Z'
'due_on': null
}
{
'number': 1
'created_at': '2013-01-01T00:00:00Z'
'due_on': '2013-02-01T00:00:00Z'
}
{
'number': 3
'created_at': '2013-01-01T00:00:00Z'
'due_on': '2013-02-15T00:00:00Z'
}
]
2013-10-05 11:45:07 +00:00
milestones {}, (err, warn, milestone) ->
assert.ifError err
assert.equal milestone.number, 1
do done
2013-09-29 20:43:20 +00:00
'milestones - 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-10-05 11:45:07 +00:00
milestones { 'path': 'some/repo' }, (err, warn, milestone) ->
2013-08-12 19:09:43 +00:00
assert.ifError err
2013-10-04 17:47:46 +00:00
assert.equal warn, 'No open milestones for repo some/repo'
2013-09-29 20:43:20 +00:00
do done
2013-08-12 18:43:58 +00:00
2013-09-29 20:43:20 +00:00
'milestones - get current when not found': (done) ->
2013-08-13 12:05:21 +00:00
req.all_milestones = (opts, cb) ->
2013-10-05 11:45:07 +00:00
cb 'Not Found'
2013-08-12 18:43:58 +00:00
2013-10-05 11:45:07 +00:00
milestones {}, (err, warn, milestone) ->
2013-08-12 18:43:58 +00:00
assert.equal err, 'Not Found'
2013-09-29 20:43:20 +00:00
do done
2013-08-12 19:09:43 +00:00
2013-09-29 20:43:20 +00:00
'milestones - 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, [
{
2013-10-04 17:47:46 +00:00
'title': 'No issues'
2013-08-12 19:09:43 +00:00
'number': 1
'created_at': '2013-01-01T00:00:00Z'
'due_on': '2013-02-01T00:00:00Z',
'open_issues': 0,
'closed_issues': 0
}
]
2013-10-05 11:45:07 +00:00
milestones {}, (err, warn, milestone) ->
2013-08-12 19:09:43 +00:00
assert.ifError err
2013-10-05 11:45:07 +00:00
assert.equal warn, 'No issues for milestone `No issues`'
do done
'milestones - get one': (done) ->
m =
'number': 1
'created_at': '2013-01-01T00:00:00Z'
'due_on': '2013-02-01T00:00:00Z'
req.one_milestone = (opts, number, cb) ->
cb null, m
milestones { 'milestone': 1 }, (err, warn, milestone) ->
assert.ifError err
assert.equal warn, null
assert.deepEqual milestone, m
do done
'milestones - get one (404)': (done) ->
req.one_milestone = (opts, number, cb) ->
cb 'Not Found'
milestones { 'milestone': 9 }, (err, warn, milestone) ->
assert.equal err, 'Not Found'
do done
'milestones - get one when no issues': (done) ->
req.one_milestone = (opts, number, cb) ->
cb null, {
'title': 'No issues'
'number': 1
'created_at': '2013-01-01T00:00:00Z'
'due_on': '2013-02-01T00:00:00Z',
'open_issues': 0,
'closed_issues': 0
}
milestones { 'milestone': 9 }, (err, warn, milestone) ->
assert.ifError err
assert.equal warn, 'No issues for milestone `No issues`'
2013-10-04 22:42:54 +00:00
do done
'milestones - has description': (done) ->
req.all_milestones = (opts, cb) ->
cb null, [
{
'number': 1
'created_at': '2013-01-01T00:00:00Z'
'due_on': '2013-02-01T00:00:00Z'
'description': 'A description of this <strong>milestone</strong> goes *here*'
}
]
2013-10-05 11:45:07 +00:00
milestones {}, (err, warn, milestone) ->
2013-10-04 22:42:54 +00:00
assert.ifError err
assert.equal milestone.description, 'A description of this <strong>milestone</strong> goes <em>here</em>'
2013-09-29 20:43:20 +00:00
do done