From c54089958069159633e665749c3bc6782f3949cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 25 Jan 2016 10:47:21 +0100 Subject: [PATCH] Implemented unit test for user indexer in batch service --- test/unit/batch/user_indexer.js | 80 +++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 test/unit/batch/user_indexer.js diff --git a/test/unit/batch/user_indexer.js b/test/unit/batch/user_indexer.js new file mode 100644 index 00000000..38185d37 --- /dev/null +++ b/test/unit/batch/user_indexer.js @@ -0,0 +1,80 @@ +var UserIndexer = require('../../../batch/user_indexer'); +var assert = require('assert'); + +describe('batch API user indexer', function () { + describe('backend works well', function () { + beforeEach(function () { + this.metadataBackend = { + redisCmd: function () { + var callback = arguments[arguments.length -1]; + process.nextTick(function () { + callback(null, 'irrelevantJob'); + }); + } + }; + this.userIndexer = new UserIndexer(this.metadataBackend); + }); + + it('.add() should save the given job into the given username list', function (done) { + this.userIndexer.add('irrelevantUsername', 'irrelevantJobId', function (err) { + assert.ok(!err); + done(); + }); + }); + + it('.list() should list jobs of the given username', function (done) { + this.userIndexer.list('irrelevantUsername', function (err) { + assert.ok(!err); + done(); + }); + }); + + it('.remove() should remove the job id from the given username list', function (done) { + this.userIndexer.remove('irrelevantUsername', 'irrelevantJobId', function (err) { + assert.ok(!err); + done(); + }); + }); + }); + + + describe('backend fails', function () { + beforeEach(function () { + this.metadataBackend = { + redisCmd: function () { + var callback = arguments[arguments.length -1]; + process.nextTick(function () { + callback(new Error('Something went wrong')); + }); + } + }; + this.userIndexer = new UserIndexer(this.metadataBackend); + }); + + it('.add() should save the given job into the given username list', function (done) { + this.userIndexer.add('irrelevantUsername', 'irrelevantJobId', function (err) { + assert.ok(err); + assert.ok(err.message, 'Something went wrong'); + done(); + }); + }); + + it('.list() should list jobs of the given username', function (done) { + this.userIndexer.list('irrelevantUsername', function (err) { + assert.ok(err); + assert.ok(err.message, 'Something went wrong'); + done(); + }); + }); + + it('.remove() should remove the job id from the given username list', function (done) { + this.userIndexer.remove('irrelevantUsername', 'irrelevantJobId', function (err) { + assert.ok(err); + assert.ok(err.message, 'Something went wrong'); + done(); + }); + }); + + }); + +});