Files: 870e2cb73a3e01c6b5810eaa4f9e264b5b974d03 / test / position / sync / chooseOneResults.test.js
2644 bytesRaw
1 | const test = require('tape') |
2 | const ChooseOne = require('../../../position/sync/chooseOne') |
3 | const ChooseOnePoll = require('../../../poll/sync/chooseOne') |
4 | const Position = require('../../../position/sync/position') |
5 | const chooseOneResults = require('../../../position/sync/chooseOneResults') |
6 | |
7 | const pietId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/0=.ed25519' |
8 | const mixId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/1=.ed25519' |
9 | const mikeyId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/2=.ed25519' |
10 | const timmyId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/3=.ed25519' |
11 | const tommyId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/4=.ed25519' |
12 | const sallyId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/5=.ed25519' |
13 | |
14 | const poll = '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256' |
15 | |
16 | const validPoll = ChooseOnePoll({ |
17 | choices: [1, 2, 'three'], |
18 | title: 'how many food', |
19 | closesAt: Date.now() |
20 | }) |
21 | |
22 | test('Position - ChooseOneResults', function (t) { |
23 | const positions = [ |
24 | { value: { content: Position(ChooseOne({choice: 0, poll})), author: pietId } }, |
25 | { value: { content: Position(ChooseOne({choice: 0, poll})), author: mixId } }, |
26 | { value: { content: Position(ChooseOne({choice: 0, poll})), author: mikeyId } }, |
27 | { value: { content: Position(ChooseOne({choice: 1, poll})), author: timmyId } }, |
28 | { value: { content: Position(ChooseOne({choice: 1, poll})), author: tommyId } }, |
29 | { value: { content: Position(ChooseOne({choice: 2, poll})), author: sallyId } } |
30 | ] |
31 | |
32 | const actual = chooseOneResults({positions, poll: validPoll}) |
33 | t.deepEqual(actual[0], [pietId, mixId, mikeyId], 'correct voters for choice 0') |
34 | t.deepEqual(actual[1], [timmyId, tommyId], 'correct voters for choice 1') |
35 | t.deepEqual(actual[2], [sallyId], 'correct voters for choice 2') |
36 | t.end() |
37 | }) |
38 | |
39 | test('Position - a position stated for an invalid choice index is not counted', function(t) { |
40 | |
41 | const positions = [ |
42 | { value: { content: Position(ChooseOne({choice: 3, poll})), author: pietId } } |
43 | ] |
44 | |
45 | const actual = chooseOneResults({positions, poll: validPoll}) |
46 | t.false(actual[3], 'invalid vote is not counted') |
47 | t.end() |
48 | }) |
49 | |
50 | test('Position - a position stated for an invalid choice index is included in the errors object', function(t) { |
51 | const positions = [ |
52 | { value: { content: Position(ChooseOne({choice: 3, poll})), author: pietId } } |
53 | ] |
54 | |
55 | const actual = chooseOneResults({positions, poll: validPoll}) |
56 | t.deepEqual(actual.errors.invalidPositions[0], positions[0], 'invalid vote is on error object') |
57 | t.end() |
58 | }) |
59 | |
60 | test.skip('Position - A position stated after the closing time of the poll is not counted', function(t) { |
61 | |
62 | t.end() |
63 | }) |
64 |
Built with git-ssb-web