ensl_gathers/spec/gatherer.js
2015-10-03 18:17:31 +01:00

88 lines
No EOL
2.6 KiB
JavaScript

"use strict";
var helper = require("./helpers/index.js");
var User = helper.User;
var Gather = helper.Gather;
var Gatherer = helper.Gatherer;
var assert = require("chai").assert;
describe("Gather Model:", function () {
var user, gatherer;
beforeEach(function () {
user = helper.createUser();
gatherer = new Gatherer(user);
});
describe("#voteRegather", function () {
it ("marks gatherer as voting for regather", function () {
assert.isFalse(gatherer.regatherVote);
gatherer.voteRegather();
assert.isTrue(gatherer.regatherVote);
});
it ("assigns vote for regather", function () {
gatherer.voteRegather(true);
assert.isTrue(gatherer.regatherVote);
gatherer.voteRegather(false);
assert.isFalse(gatherer.regatherVote);
});
});
describe("#voteForMap", function () {
it ("assigns vote for map id", function () {
assert.equal(gatherer.mapVote.length, 0);
gatherer.voteForMap(1);
assert.isTrue(gatherer.mapVote.some(voteId => voteId === 1));
});
it ("only assigns vote once", function () {
gatherer.voteForMap(1);
gatherer.voteForMap(1);
assert.equal(gatherer.mapVote.length, 1);
});
it ("allows a maximum of 2 votes", function () {
gatherer.voteForMap(1);
gatherer.voteForMap(2);
gatherer.voteForMap(3);
assert.equal(gatherer.mapVote.length, 2);
});
it ("removes oldest vote if maximum vote exceeded", function () {
gatherer.voteForMap(1);
gatherer.voteForMap(2);
gatherer.voteForMap(3);
assert.isFalse(gatherer.mapVote.some(voteId => voteId === 1));
assert.isTrue(gatherer.mapVote.some(voteId => voteId === 2));
assert.isTrue(gatherer.mapVote.some(voteId => voteId === 3));
});
});
describe("#voteForServer", function () {
it ("assigns vote for server id", function () {
assert.equal(gatherer.serverVote.length, 0);
gatherer.voteForServer(1);
assert.isTrue(gatherer.serverVote.some(voteId => voteId === 1));
});
it ("only assigns vote once", function () {
gatherer.voteForServer(1);
gatherer.voteForServer(1);
assert.equal(gatherer.serverVote.length, 1);
});
it ("allows a maximum of 2 votes", function () {
gatherer.voteForServer(1);
gatherer.voteForServer(2);
gatherer.voteForServer(3);
assert.equal(gatherer.serverVote.length, 2);
});
it ("removes oldest vote if maximum vote exceeded", function () {
gatherer.voteForServer(1);
gatherer.voteForServer(2);
gatherer.voteForServer(3);
assert.isFalse(gatherer.serverVote.some(voteId => voteId === 1));
assert.isTrue(gatherer.serverVote.some(voteId => voteId === 2));
assert.isTrue(gatherer.serverVote.some(voteId => voteId === 3));
});
});
describe("#voteForLeader", function () {
});
});