git ssb

0+

Piet / ssb-loomio



Tree: 870e2cb73a3e01c6b5810eaa4f9e264b5b974d03

Files: 870e2cb73a3e01c6b5810eaa4f9e264b5b974d03 / test / position / sync / chooseOneResults.test.js

2644 bytesRaw
1const test = require('tape')
2const ChooseOne = require('../../../position/sync/chooseOne')
3const ChooseOnePoll = require('../../../poll/sync/chooseOne')
4const Position = require('../../../position/sync/position')
5const chooseOneResults = require('../../../position/sync/chooseOneResults')
6
7const pietId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/0=.ed25519'
8const mixId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/1=.ed25519'
9const mikeyId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/2=.ed25519'
10const timmyId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/3=.ed25519'
11const tommyId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/4=.ed25519'
12const sallyId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/5=.ed25519'
13
14const poll = '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256'
15
16const validPoll = ChooseOnePoll({
17 choices: [1, 2, 'three'],
18 title: 'how many food',
19 closesAt: Date.now()
20})
21
22test('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
39test('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
50test('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
60test.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