UNPKG

werewolf-core

Version:

Are you a WEREWOLF?

202 lines (201 loc) 5.71 kB
"use strict"; var votebox_1 = require('../../../core/lib/votebox'); describe('votebox', function () { var box; beforeEach(function () { box = votebox_1.initVoteBox(); }); it('Empty votebox is an empty object', function () { expect(box).toEqual({}); }); describe('voting', function () { it('Adding a vote to the box', function () { var v = { from: 'foo', to: 'bar', num: 1, priority: 0, }; votebox_1.addVote(box, v); expect(box).toEqual({ foo: { from: 'foo', to: 'bar', num: 1, priority: 0, }, }); var v2 = { from: 'bar', to: 'baz', num: 2, priority: 0, }; votebox_1.addVote(box, v2); expect(box).toEqual({ foo: { from: 'foo', to: 'bar', num: 1, priority: 0, }, bar: { from: 'bar', to: 'baz', num: 2, priority: 0, }, }); }); it('Replacing a vote', function () { votebox_1.addVote(box, { from: 'foo', to: 'bar', num: 1, priority: 0, }); votebox_1.addVote(box, { from: 'foo', to: 'baz', num: 1, priority: 0, }); expect(box).toEqual({ foo: { from: 'foo', to: 'baz', num: 1, priority: 0, }, }); }); }); describe('counting', function () { it('none for empty box', function () { expect(votebox_1.countVotes(box)).toEqual({ result: votebox_1.VOTERESULT_NONE, ids: [], }); }); it('chosen for non-tie box (sum of num)', function () { votebox_1.addVote(box, { from: 'id1', to: 'baz', num: 1, priority: 0, }); votebox_1.addVote(box, { from: 'id2', to: 'baz', num: 1, priority: 0, }); votebox_1.addVote(box, { from: 'id3', to: 'bar', num: 1, priority: 0, }); votebox_1.addVote(box, { from: 'id4', to: 'bar', num: 2, priority: 0, }); expect(votebox_1.countVotes(box)).toEqual({ result: votebox_1.VOTERESULT_CHOSEN, ids: ['bar'], }); }); it('chosen for non-tie box (priority)', function () { votebox_1.addVote(box, { from: 'id1', to: 'baz', num: 1, priority: 1, }); votebox_1.addVote(box, { from: 'id2', to: 'baz', num: 2, priority: 0, }); votebox_1.addVote(box, { from: 'id3', to: 'bar', num: 1, priority: 0, }); votebox_1.addVote(box, { from: 'id4', to: 'bar', num: 2, priority: 0, }); expect(votebox_1.countVotes(box)).toEqual({ result: votebox_1.VOTERESULT_CHOSEN, ids: ['baz'], }); }); it('multi', function () { votebox_1.addVote(box, { from: 'id1', to: 'baz', num: 1, priority: 0, }); votebox_1.addVote(box, { from: 'id2', to: 'baz', num: 2, priority: 0, }); votebox_1.addVote(box, { from: 'id3', to: 'bar', num: 1, priority: 0, }); votebox_1.addVote(box, { from: 'id4', to: 'bar', num: 2, priority: 0, }); expect(votebox_1.countVotes(box)).toEqual({ result: votebox_1.VOTERESULT_MULTI, ids: ['baz', 'bar'], }); }); it('multi (with priority)', function () { votebox_1.addVote(box, { from: 'id1', to: 'baz', num: 1, priority: 2, }); votebox_1.addVote(box, { from: 'id2', to: 'baz', num: 2, priority: 1, }); votebox_1.addVote(box, { from: 'id3', to: 'bar', num: 1, priority: 0, }); votebox_1.addVote(box, { from: 'id4', to: 'bar', num: 2, priority: 2, }); expect(votebox_1.countVotes(box)).toEqual({ result: votebox_1.VOTERESULT_MULTI, ids: ['baz', 'bar'], }); }); }); });