burnchart/test/issues.coffee

196 lines
6.1 KiB
CoffeeScript
Raw Normal View History

2013-08-13 12:58:21 +00:00
#!/usr/bin/env coffee
2013-09-29 20:43:20 +00:00
proxy = do require('proxyquire').noCallThru
2013-08-13 12:58:21 +00:00
assert = require 'assert'
path = require 'path'
req = {}
2013-09-29 20:43:20 +00:00
regex = require path.resolve(__dirname, '../src/modules/regex.coffee')
2013-08-15 17:12:12 +00:00
issues = proxy path.resolve(__dirname, '../src/modules/issues.coffee'),
2013-08-13 12:58:21 +00:00
'./request': req
2013-11-05 12:44:15 +00:00
'./require':
'_': require 'lodash'
'superagent': null
'd3': null
'async': require 'async'
'marked': null
2013-08-13 12:58:21 +00:00
2013-09-29 20:43:20 +00:00
repo = { 'milestone': { 'number': no } }
module.exports =
2013-09-29 20:43:20 +00:00
'issues - all empty': (done) ->
2013-08-13 12:58:21 +00:00
called = 0
2013-09-29 20:43:20 +00:00
req.all_issues = (repo, opts, cb) ->
2013-08-13 12:58:21 +00:00
called += 1
cb null, []
2013-09-29 20:43:20 +00:00
issues.get_all repo, (err, [ open, closed ]) ->
2013-08-13 12:58:21 +00:00
assert.ifError err
assert.equal called, 2
assert.equal open.length, 0
assert.equal closed.length, 0
2013-09-29 20:43:20 +00:00
do done
2013-08-13 13:02:00 +00:00
2013-09-29 20:43:20 +00:00
'issues - open empty': (done) ->
2013-08-13 13:02:00 +00:00
called = 0
2013-09-29 20:43:20 +00:00
req.all_issues = (repo, opts, cb) ->
2013-08-13 13:02:00 +00:00
called += 1
cb null, if called is 1 then [] else [
{ number: 1 }
]
2013-09-29 20:43:20 +00:00
issues.get_all repo, (err, [ open, closed ]) ->
2013-08-13 13:02:00 +00:00
assert.ifError err
assert.equal called, 2
assert.equal open.length, 0
assert.equal closed.length, 1
2013-09-29 20:43:20 +00:00
do done
2013-08-13 13:02:00 +00:00
2013-09-29 20:43:20 +00:00
'issues - closed empty': (done) ->
2013-08-13 13:02:00 +00:00
called = 0
2013-09-29 20:43:20 +00:00
req.all_issues = (repo, opts, cb) ->
2013-08-13 13:02:00 +00:00
called += 1
cb null, if called is 2 then [] else [
{ number: 1 }
]
2013-09-29 20:43:20 +00:00
issues.get_all repo, (err, [ open, closed ]) ->
2013-08-13 13:02:00 +00:00
assert.ifError err
assert.equal called, 2
assert.equal open.length, 1
assert.equal closed.length, 0
2013-09-29 20:43:20 +00:00
do done
2013-08-13 13:22:41 +00:00
2013-09-29 20:43:20 +00:00
'issues - both not empty': (done) ->
2013-08-13 13:22:41 +00:00
called = 0
2013-09-29 20:43:20 +00:00
req.all_issues = (repo, opts, cb) ->
2013-08-13 13:22:41 +00:00
called += 1
cb null, [ { number: 1 } ]
2013-09-29 20:43:20 +00:00
issues.get_all repo, (err, [ open, closed ]) ->
2013-08-13 13:22:41 +00:00
assert.ifError err
assert.equal called, 2
assert.equal open.length, 1
assert.equal closed.length, 1
2013-09-29 20:43:20 +00:00
do done
2013-08-13 13:22:41 +00:00
2013-09-29 20:43:20 +00:00
'issues - 99 results on a page': (done) ->
2013-08-13 13:22:41 +00:00
called = 0
2013-09-29 20:43:20 +00:00
req.all_issues = (repo, opts, cb) ->
2013-08-13 13:22:41 +00:00
called += 1
cb null, ( { number: i } for i in [ 0...99 ] )
2013-09-29 20:43:20 +00:00
issues.get_all repo, (err, [ open, closed ]) ->
2013-08-13 13:22:41 +00:00
assert.ifError err
assert.equal called, 2
assert.equal open.length, 99
assert.equal closed.length, 99
2013-09-29 20:43:20 +00:00
do done
2013-08-13 13:22:41 +00:00
2013-09-29 20:43:20 +00:00
'issues - 100 results on a page': (done) ->
2013-08-13 13:22:41 +00:00
called = 0
2013-09-29 20:43:20 +00:00
req.all_issues = (repo, opts, cb) ->
2013-08-13 13:22:41 +00:00
called += 1
assert opts.page in [ 1, 2 ]
cb null, if opts.page is 1 then ( { number: i } for i in [ 0...100 ] ) else []
2013-09-29 20:43:20 +00:00
issues.get_all repo, (err, [ open, closed ]) ->
2013-08-13 13:22:41 +00:00
assert.ifError err
assert.equal called, 4
assert.equal open.length, 100
assert.equal closed.length, 100
2013-09-29 20:43:20 +00:00
do done
2013-08-13 13:22:41 +00:00
2013-09-29 20:43:20 +00:00
'issues - 101 total results': (done) ->
2013-08-13 13:22:41 +00:00
called = 0
2013-09-29 20:43:20 +00:00
req.all_issues = (repo, opts, cb) ->
2013-08-13 13:22:41 +00:00
called += 1
assert opts.page in [ 1, 2 ]
cb null, if opts.page is 1
( { number: i } for i in [ 0...100 ] )
else
[ { number: 100 } ]
2013-09-29 20:43:20 +00:00
issues.get_all repo, (err, [ open, closed ]) ->
2013-08-13 13:22:41 +00:00
assert.ifError err
assert.equal called, 4
assert.equal open.length, 101
assert.equal closed.length, 101
assert.deepEqual open[100], { number: 100 }
assert.deepEqual closed[100], { number: 100 }
2013-09-29 20:43:20 +00:00
do done
2013-08-13 13:22:41 +00:00
2013-09-29 20:43:20 +00:00
'issues - 201 total results': (done) ->
2013-08-13 13:22:41 +00:00
called = 0
2013-09-29 20:43:20 +00:00
req.all_issues = (repo, opts, cb) ->
2013-08-13 13:22:41 +00:00
called += 1
assert opts.page in [ 1, 2, 3 ]
cb null, if opts.page in [ 1, 2 ]
( { number: i } for i in [ (h = 100 * (opts.page - 1))...h + 100 ] )
else
[ { number: 200 } ]
2013-09-29 20:43:20 +00:00
issues.get_all repo, (err, [ open, closed ]) ->
2013-08-13 13:22:41 +00:00
assert.ifError err
assert.equal called, 6
assert.equal open.length, 201
assert.equal closed.length, 201
for i in [ open, closed ]
for j in [ 100, 200 ]
assert.deepEqual i[j], { number: j }
2013-09-29 20:43:20 +00:00
do done
2013-08-13 13:22:41 +00:00
2013-09-29 20:43:20 +00:00
'issues - get all when not found': (done) ->
2013-08-13 13:22:41 +00:00
called = 0
2013-09-29 20:43:20 +00:00
req.all_issues = (repo, opts, cb) ->
2013-08-13 13:22:41 +00:00
called += 1
2013-10-05 11:45:07 +00:00
cb 'Not Found'
2013-08-13 13:22:41 +00:00
2013-09-29 20:43:20 +00:00
issues.get_all repo, (err, [ open, closed ]) ->
2013-08-13 13:22:41 +00:00
assert.equal err, 'Not Found'
assert.equal called, 1
2013-09-29 20:43:20 +00:00
do done
2013-08-13 14:47:52 +00:00
2013-09-29 20:43:20 +00:00
'issues - filter on existing label regex': (done) ->
2013-08-13 16:20:08 +00:00
issues.filter [ { labels: [ { name: 'size 15' } ] } ]
, regex.size_label, (err, data) ->
2013-08-13 14:47:52 +00:00
assert.ifError err
assert.equal data.length, 1
2013-08-13 16:20:08 +00:00
assert.equal data[0].size, 15
2013-09-29 20:43:20 +00:00
do done
2013-08-13 14:47:52 +00:00
2013-09-29 20:43:20 +00:00
'issues - filter when no labels': (done) ->
2013-08-13 14:47:52 +00:00
issues.filter [ { } ]
, regex.size_label, (err, data) ->
2013-08-13 14:47:52 +00:00
assert.ifError err
assert.equal data.length, 0
2013-09-29 20:43:20 +00:00
do done
2013-08-13 14:47:52 +00:00
2013-09-29 20:43:20 +00:00
'issues - filter when empty labels': (done) ->
2013-08-13 14:47:52 +00:00
issues.filter [ { labels: [] } ]
, regex.size_label, (err, data) ->
2013-08-13 14:47:52 +00:00
assert.ifError err
assert.equal data.length, 0
2013-09-29 20:43:20 +00:00
do done
2013-08-13 14:47:52 +00:00
2013-09-29 20:43:20 +00:00
'issues - filter when not matching regex': (done) ->
2013-08-13 14:47:52 +00:00
issues.filter [ { labels: [ { name: 'size 1A' } ] } ]
, regex.size_label, (err, data) ->
2013-08-13 14:47:52 +00:00
assert.ifError err
assert.equal data.length, 0
2013-09-29 20:43:20 +00:00
do done
2013-08-13 14:47:52 +00:00
2013-09-29 20:43:20 +00:00
'issues - filter when multiple match the regex': (done) ->
issues.filter [
{ labels: [ { name: 'size 1' }, { name: 'size 6' } ] }
{ labels: [ { name: 'size really big' }, { name: 'size 4' } ] }
]
, regex.size_label, (err, data) ->
2013-08-13 14:47:52 +00:00
assert.ifError err
assert.equal data.length, 2
[ a, b ] = data
assert.equal a.size, 7
assert.equal b.size, 4
2013-09-29 20:43:20 +00:00
do done