From 00eb69050f83c0ac3dde6a3bc228a0a918067945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Dahlgren?= Date: Sat, 14 Feb 2015 19:42:18 +0100 Subject: [PATCH] Tests --- app.js | 1 + lib/mods.js | 17 ++++++++--------- package.json | 7 ++++++- test/lib/mods.js | 22 ++++++++++++++++++++++ test/lib/server.js | 12 ++++++++++++ 5 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 test/lib/mods.js create mode 100644 test/lib/server.js diff --git a/app.js b/app.js index 5ae33c0..32b9eeb 100644 --- a/app.js +++ b/app.js @@ -18,6 +18,7 @@ app.use(express.static(__dirname + '/public')); var manager = new Manager(config); manager.load(); var mods = new Mods(config); +mods.updateMods(); var serversRoutes = require('./routes/servers')(manager, mods); var modsRoutes = require('./routes/mods')(mods); diff --git a/lib/mods.js b/lib/mods.js index ffabb30..32bf5b8 100644 --- a/lib/mods.js +++ b/lib/mods.js @@ -13,7 +13,13 @@ var Mods = function (config) { this.mods = []; var self = this; - this.updateMods(); +}; + +Mods.removeDuplicates = function (mods) { + return mods.reduce(function(a,b){ + if (a.indexOf(b) < 0 ) a.push(b); + return a; + },[]); }; Mods.prototype = new events.EventEmitter(); @@ -66,18 +72,11 @@ Mods.prototype.isPlayWithSixMod = function (modPath, cb) { }); }; -Mods.prototype.removeDuplicates = function (mods) { - return mods.reduce(function(a,b){ - if (a.indexOf(b) < 0 ) a.push(b); - return a; - },[]); -}; - Mods.prototype.resolveMods = function (modsToResolve, cb) { var self = this; playwithsix.resolveDependencies(modsToResolve, {lite: this.liteMods}, function (err, mods) { if (!err && mods) { - cb(null, self.removeDuplicates(modsToResolve.concat(mods))); + cb(null, Mods.removeDuplicates(modsToResolve.concat(mods))); } else { cb(err); } diff --git a/package.json b/package.json index 07396ae..182450a 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "version": "0.0.1", "private": true, "scripts": { - "start": "node app.js" + "start": "node app.js", + "test": "node node_modules/mocha/bin/mocha --recursive" }, "dependencies": { "arma-server": "git+https://github.com/Dahlgren/node-arma-server.git", @@ -18,5 +19,9 @@ "socket.io": "^1.0.4", "userhome": "^1.0.0", "when": "~3.1.0" + }, + "devDependencies": { + "mocha": "~2.1.0", + "should": "~5.0.0" } } diff --git a/test/lib/mods.js b/test/lib/mods.js new file mode 100644 index 0000000..0e77818 --- /dev/null +++ b/test/lib/mods.js @@ -0,0 +1,22 @@ +var should = require('should'); + +var Mods = require('../../lib/mods.js'); + +describe('Mods', function() { + describe('removeDuplicates()', function() { + it('should remove duplicate mods', function() { + Mods.removeDuplicates(['mod1', 'mod1']).should.eql(['mod1']); + }); + }); + + describe('search()', function() { + it('should find mods', function(done) { + var mods = new Mods(); + mods.search('', function (err, mods) { + should(err).be.null; + mods.should.not.be.empty; + done(); + }); + }); + }); +}); diff --git a/test/lib/server.js b/test/lib/server.js new file mode 100644 index 0000000..e30aacd --- /dev/null +++ b/test/lib/server.js @@ -0,0 +1,12 @@ +var should = require('should'); + +var Server = require('../../lib/server.js'); + +describe('Server', function() { + describe('toJSON()', function() { + it('should include title', function() { + var server = new Server(null, null, {title: 'test'}); + server.toJSON().should.have.property('title', 'test'); + }); + }); +});