ensl_gathers/spec/gatherer.js

88 lines
2.7 KiB
JavaScript
Raw Permalink Normal View History

2015-10-03 16:40:11 +00:00
"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);
});
});
2015-12-25 07:50:27 +00:00
describe("#toggleMapVote", function () {
it ("assigns vote for map id", function () {
assert.equal(gatherer.mapVote.length, 0);
2015-12-25 07:50:27 +00:00
gatherer.toggleMapVote(1);
assert.isTrue(gatherer.mapVote.some(voteId => voteId === 1));
});
2015-12-25 07:50:27 +00:00
it ("removes map vote if toggled twice", function () {
gatherer.toggleMapVote(1);
gatherer.toggleMapVote(1);
assert.equal(gatherer.mapVote.length, 0);
});
it ("allows a maximum of 2 votes", function () {
2015-12-25 07:50:27 +00:00
gatherer.toggleMapVote(1);
gatherer.toggleMapVote(2);
gatherer.toggleMapVote(3);
assert.equal(gatherer.mapVote.length, 2);
});
it ("removes oldest vote if maximum vote exceeded", function () {
2015-12-25 07:50:27 +00:00
gatherer.toggleMapVote(1);
gatherer.toggleMapVote(2);
gatherer.toggleMapVote(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));
});
});
2015-10-03 16:40:11 +00:00
describe("#toggleServerVote", function () {
it ("assigns vote for server id", function () {
assert.equal(gatherer.serverVote.length, 0);
gatherer.toggleServerVote(1);
assert.isTrue(gatherer.serverVote.some(voteId => voteId === 1));
});
it ("removes server vote if toggled twice", function () {
gatherer.toggleServerVote(1);
gatherer.toggleServerVote(1);
assert.equal(gatherer.serverVote.length, 0);
});
it ("allows a maximum of 2 votes", function () {
gatherer.toggleServerVote(1);
gatherer.toggleServerVote(2);
gatherer.toggleServerVote(3);
assert.equal(gatherer.serverVote.length, 2);
});
it ("removes oldest vote if maximum vote exceeded", function () {
gatherer.toggleServerVote(1);
gatherer.toggleServerVote(2);
gatherer.toggleServerVote(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));
});
2015-10-03 16:40:11 +00:00
});
describe("#voteForLeader", function () {
});
});