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