diff --git a/package.json b/package.json index 8beaa4d..9d94084 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "dependencies": { "coffee-script": "~1.6.3", "async": "~0.2.9", - "proxyquire": "~0.4.1", + "proxyquire": "~0.5.1", "lodash": "~1.3.1", "connect": "~2.8.5", "request": "~2.27.0" diff --git a/test/graph.coffee b/test/graph.coffee deleted file mode 100644 index 8f3cc2a..0000000 --- a/test/graph.coffee +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env coffee -assert = require 'assert' -path = require 'path' - -graph = require path.resolve __dirname, '../src/modules/graph.coffee' - -module.exports = - 'chartize closed issues': (done) -> - a = { number: 2, closed_at: '2013-05-09T09:04:53Z', size: 6 } - b = { number: 1, closed_at: '2013-05-09T10:04:53Z', size: 4 } - c = { number: 3, closed_at: '2013-05-12T09:04:53Z', size: 2 } - - graph.actual [ a, b, c ], '2013-05-08T09:04:53Z', 20, (err, data) -> - assert.ifError err - assert.deepEqual data, [ - { x: 1368003893, y: 20 } - { x: 1368090293, y: 14 } - { x: 1368093893, y: 10 } - { x: 1368349493, y: 8 } - ] - done.call null \ No newline at end of file diff --git a/test/issues.coffee b/test/issues.coffee index a1ec35c..29b940d 100644 --- a/test/issues.coffee +++ b/test/issues.coffee @@ -1,100 +1,105 @@ #!/usr/bin/env coffee +proxy = do require('proxyquire').noCallThru assert = require 'assert' path = require 'path' -proxy = require 'proxyquire' req = {} +regex = require path.resolve(__dirname, '../src/modules/regex.coffee') + issues = proxy path.resolve(__dirname, '../src/modules/issues.coffee'), './request': req +repo = { 'milestone': { 'number': no } } + module.exports = - 'all empty': (done) -> + + 'issues - all empty': (done) -> called = 0 - req.all_issues = (opts, cb) -> + req.all_issues = (repo, opts, cb) -> called += 1 cb null, [] - issues.get_all {}, (err, [ open, closed ]) -> + issues.get_all repo, (err, [ open, closed ]) -> assert.ifError err assert.equal called, 2 assert.equal open.length, 0 assert.equal closed.length, 0 - done.call null + do done - 'open empty': (done) -> + 'issues - open empty': (done) -> called = 0 - req.all_issues = (opts, cb) -> + req.all_issues = (repo, opts, cb) -> called += 1 cb null, if called is 1 then [] else [ { number: 1 } ] - issues.get_all {}, (err, [ open, closed ]) -> + issues.get_all repo, (err, [ open, closed ]) -> assert.ifError err assert.equal called, 2 assert.equal open.length, 0 assert.equal closed.length, 1 - done.call null + do done - 'closed empty': (done) -> + 'issues - closed empty': (done) -> called = 0 - req.all_issues = (opts, cb) -> + req.all_issues = (repo, opts, cb) -> called += 1 cb null, if called is 2 then [] else [ { number: 1 } ] - issues.get_all {}, (err, [ open, closed ]) -> + issues.get_all repo, (err, [ open, closed ]) -> assert.ifError err assert.equal called, 2 assert.equal open.length, 1 assert.equal closed.length, 0 - done.call null + do done - 'both not empty': (done) -> + 'issues - both not empty': (done) -> called = 0 - req.all_issues = (opts, cb) -> + req.all_issues = (repo, opts, cb) -> called += 1 cb null, [ { number: 1 } ] - issues.get_all {}, (err, [ open, closed ]) -> + issues.get_all repo, (err, [ open, closed ]) -> assert.ifError err assert.equal called, 2 assert.equal open.length, 1 assert.equal closed.length, 1 - done.call null + do done - '99 results on a page': (done) -> + 'issues - 99 results on a page': (done) -> called = 0 - req.all_issues = (opts, cb) -> + req.all_issues = (repo, opts, cb) -> called += 1 cb null, ( { number: i } for i in [ 0...99 ] ) - issues.get_all {}, (err, [ open, closed ]) -> + issues.get_all repo, (err, [ open, closed ]) -> assert.ifError err assert.equal called, 2 assert.equal open.length, 99 assert.equal closed.length, 99 - done.call null + do done - '100 results on a page': (done) -> + 'issues - 100 results on a page': (done) -> called = 0 - req.all_issues = (opts, cb) -> + req.all_issues = (repo, opts, cb) -> called += 1 assert opts.page in [ 1, 2 ] cb null, if opts.page is 1 then ( { number: i } for i in [ 0...100 ] ) else [] - issues.get_all {}, (err, [ open, closed ]) -> + issues.get_all repo, (err, [ open, closed ]) -> assert.ifError err assert.equal called, 4 assert.equal open.length, 100 assert.equal closed.length, 100 - done.call null + do done - '101 total results': (done) -> + 'issues - 101 total results': (done) -> called = 0 - req.all_issues = (opts, cb) -> + req.all_issues = (repo, opts, cb) -> called += 1 assert opts.page in [ 1, 2 ] cb null, if opts.page is 1 @@ -102,18 +107,18 @@ module.exports = else [ { number: 100 } ] - issues.get_all {}, (err, [ open, closed ]) -> + issues.get_all repo, (err, [ open, closed ]) -> 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 } - done.call null + do done - '201 total results': (done) -> + 'issues - 201 total results': (done) -> called = 0 - req.all_issues = (opts, cb) -> + req.all_issues = (repo, opts, cb) -> called += 1 assert opts.page in [ 1, 2, 3 ] cb null, if opts.page in [ 1, 2 ] @@ -121,7 +126,7 @@ module.exports = else [ { number: 200 } ] - issues.get_all {}, (err, [ open, closed ]) -> + issues.get_all repo, (err, [ open, closed ]) -> assert.ifError err assert.equal called, 6 assert.equal open.length, 201 @@ -129,68 +134,56 @@ module.exports = for i in [ open, closed ] for j in [ 100, 200 ] assert.deepEqual i[j], { number: j } - done.call null + do done - 'get all when not found': (done) -> + 'issues - get all when not found': (done) -> called = 0 - req.all_issues = (opts, cb) -> + req.all_issues = (repo, opts, cb) -> called += 1 cb null, { 'message': 'Not Found' } - issues.get_all {}, (err, [ open, closed ]) -> + issues.get_all repo, (err, [ open, closed ]) -> assert.equal err, 'Not Found' assert.equal called, 1 - done.call null + do done - 'filter on existing label regex': (done) -> + 'issues - filter on existing label regex': (done) -> issues.filter [ { labels: [ { name: 'size 15' } ] } ] - , /size (\d+)$/, (err, warn, data) -> + , regex.size_label, (err, warn, data) -> assert.ifError err assert.ifError warn assert.equal data.length, 1 assert.equal data[0].size, 15 - done.call null + do done - 'filter when no labels': (done) -> + 'issues - filter when no labels': (done) -> issues.filter [ { } ] - , /size (\d+)$/, (err, warn, data) -> + , regex.size_label, (err, warn, data) -> assert.ifError err assert.ifError warn assert.equal data.length, 0 - done.call null + do done - 'filter when empty labels': (done) -> + 'issues - filter when empty labels': (done) -> issues.filter [ { labels: [] } ] - , /size (\d+)$/, (err, warn, data) -> + , regex.size_label, (err, warn, data) -> assert.ifError err assert.ifError warn assert.equal data.length, 0 - done.call null + do done - 'filter when not matching regex': (done) -> + 'issues - filter when not matching regex': (done) -> issues.filter [ { labels: [ { name: 'size 1A' } ] } ] - , /size (\d+)$/, (err, warn, data) -> + , regex.size_label, (err, warn, data) -> assert.ifError err assert.ifError warn assert.equal data.length, 0 - done.call null + do done - 'filter when multiple match the regex': (done) -> + 'issues - filter when multiple match the regex': (done) -> issues.filter [ { labels: [ { name: 'size 1' }, { name: 'size 6' } ] } ] - , /size (\d+)$/, (err, warn, data) -> + , regex.size_label, (err, warn, data) -> assert.ifError err assert.equal warn.length, 1 assert.equal data.length, 1 - done.call null - - 'organize issues into days': (done) -> - a = { number: 2, closed_at: '2013-05-09T09:04:53Z', size: 6 } - b = { number: 1, closed_at: '2013-05-09T10:04:53Z', size: 4 } - c = { number: 3, closed_at: '2013-05-10T09:04:53Z', size: 2 } - - issues.into_days [ a, b, c ], /size (\d+)$/, (err, data) -> - assert.ifError err - assert.deepEqual data, - '2013-05-09': [ a, b ] - '2013-05-10': [ c ] - done.call null \ No newline at end of file + do done \ No newline at end of file diff --git a/test/milestones.coffee b/test/milestones.coffee index a403272..eb4f17b 100644 --- a/test/milestones.coffee +++ b/test/milestones.coffee @@ -1,15 +1,16 @@ #!/usr/bin/env coffee +proxy = do require('proxyquire').noCallThru assert = require 'assert' path = require 'path' -proxy = require 'proxyquire' req = {} milestones = proxy path.resolve(__dirname, '../src/modules/milestones.coffee'), './request': req -module.exports = - 'get current from 1': (done) -> +module.exports = + + 'milestones - get current from 1': (done) -> req.all_milestones = (opts, cb) -> cb null, [ { @@ -22,10 +23,10 @@ module.exports = milestones.get_current {}, (err, warn, milestone) -> assert.ifError err assert.equal milestone.number, 1 - done.call null + do done # We always take from head because of request params. - 'get current from > 1': (done) -> + 'milestones - get current from > 1': (done) -> req.all_milestones = (opts, cb) -> cb null, [ { @@ -48,26 +49,26 @@ module.exports = milestones.get_current {}, (err, warn, milestone) -> assert.ifError err assert.equal milestone.number, 2 - done.call null + do done - 'get current when empty': (done) -> + 'milestones - get current when empty': (done) -> req.all_milestones = (opts, cb) -> cb null, [] milestones.get_current {}, (err, warn, milestone) -> assert.ifError err assert.equal warn, 'No open milestones for repo' - done.call null + do done - 'get current when not found': (done) -> + 'milestones - get current when not found': (done) -> req.all_milestones = (opts, cb) -> cb null, { 'message': 'Not Found' } milestones.get_current {}, (err, warn, milestone) -> assert.equal err, 'Not Found' - done.call null + do done - 'get current when no issues': (done) -> + 'milestones - get current when no issues': (done) -> req.all_milestones = (opts, cb) -> cb null, [ { @@ -82,4 +83,4 @@ module.exports = milestones.get_current {}, (err, warn, milestone) -> assert.ifError err assert.equal warn, 'No issues for milestone' - done.call null \ No newline at end of file + do done \ No newline at end of file