test/position/sync/chooseOneResults.test.jsView |
---|
12 | 12 | const sallyId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/5=.ed25519' |
13 | 13 | |
14 | 14 | const poll = '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256' |
15 | 15 | |
| 16 | +const now = Number(new Date()) |
| 17 | + |
16 | 18 | const validPoll = ChooseOnePoll({ |
17 | 19 | choices: [1, 2, 'three'], |
18 | 20 | title: 'how many food', |
19 | | - closesAt: Date.now() |
| 21 | + closesAt: now |
20 | 22 | }) |
21 | 23 | |
22 | 24 | test('ChooseOneResults - ChooseOneResults', function (t) { |
23 | 25 | const positions = [ |
56 | 58 | t.deepEqual(actual.errors.invalidPositions[0], positions[0], 'invalid vote is on error object') |
57 | 59 | t.end() |
58 | 60 | }) |
59 | 61 | |
60 | | -test.skip('ChooseOneResults - A position stated after the closing time of the poll is not counted', function(t) { |
| 62 | +test('ChooseOneResults - A position stated before the closing time of the poll is counted', function(t) { |
| 63 | + const positions = [ |
| 64 | + { value: { content: Position(ChooseOne({choice: 0, poll})), author: pietId, timestamp: now - 1} } |
| 65 | + ] |
61 | 66 | |
| 67 | + const actual = chooseOneResults({positions, poll: validPoll}) |
| 68 | + t.true(actual[0], 'valid vote is counted') |
62 | 69 | t.end() |
63 | 70 | }) |
| 71 | + |
| 72 | +test('ChooseOneResults - A position stated after the closing time of the poll is not counted', function(t) { |
| 73 | + const positions = [ |
| 74 | + { value: { content: Position(ChooseOne({choice: 0, poll})), author: pietId, timestamp: now + 1} } |
| 75 | + ] |
| 76 | + |
| 77 | + const actual = chooseOneResults({positions, poll: validPoll}) |
| 78 | + t.false(actual[0], 'invalid vote is not counted') |
| 79 | + t.end() |
| 80 | +}) |
| 81 | + |
| 82 | +test('ChooseOneResults - A position stated after the closing time of the poll is included in the error object', function(t) { |
| 83 | + const positions = [ |
| 84 | + { value: { content: Position(ChooseOne({choice: 0, poll})), author: pietId, timestamp: now + 1} } |
| 85 | + ] |
| 86 | + |
| 87 | + const actual = chooseOneResults({positions, poll: validPoll}) |
| 88 | + t.deepEqual(actual.errors.invalidPositions[0], positions[0], 'invalid vote is on error object') |
| 89 | + t.end() |
| 90 | +}) |