This commit is contained in:
Björn Dahlgren 2015-02-14 19:42:18 +01:00 committed by Björn Dahlgren
parent f46e6acd13
commit 00eb69050f
5 changed files with 49 additions and 10 deletions

1
app.js
View File

@ -18,6 +18,7 @@ app.use(express.static(__dirname + '/public'));
var manager = new Manager(config); var manager = new Manager(config);
manager.load(); manager.load();
var mods = new Mods(config); var mods = new Mods(config);
mods.updateMods();
var serversRoutes = require('./routes/servers')(manager, mods); var serversRoutes = require('./routes/servers')(manager, mods);
var modsRoutes = require('./routes/mods')(mods); var modsRoutes = require('./routes/mods')(mods);

View File

@ -13,7 +13,13 @@ var Mods = function (config) {
this.mods = []; this.mods = [];
var self = this; 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(); 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) { Mods.prototype.resolveMods = function (modsToResolve, cb) {
var self = this; var self = this;
playwithsix.resolveDependencies(modsToResolve, {lite: this.liteMods}, function (err, mods) { playwithsix.resolveDependencies(modsToResolve, {lite: this.liteMods}, function (err, mods) {
if (!err && mods) { if (!err && mods) {
cb(null, self.removeDuplicates(modsToResolve.concat(mods))); cb(null, Mods.removeDuplicates(modsToResolve.concat(mods)));
} else { } else {
cb(err); cb(err);
} }

View File

@ -4,7 +4,8 @@
"version": "0.0.1", "version": "0.0.1",
"private": true, "private": true,
"scripts": { "scripts": {
"start": "node app.js" "start": "node app.js",
"test": "node node_modules/mocha/bin/mocha --recursive"
}, },
"dependencies": { "dependencies": {
"arma-server": "git+https://github.com/Dahlgren/node-arma-server.git", "arma-server": "git+https://github.com/Dahlgren/node-arma-server.git",
@ -18,5 +19,9 @@
"socket.io": "^1.0.4", "socket.io": "^1.0.4",
"userhome": "^1.0.0", "userhome": "^1.0.0",
"when": "~3.1.0" "when": "~3.1.0"
},
"devDependencies": {
"mocha": "~2.1.0",
"should": "~5.0.0"
} }
} }

22
test/lib/mods.js Normal file
View File

@ -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();
});
});
});
});

12
test/lib/server.js Normal file
View File

@ -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');
});
});
});