git ssb

0+

Piet / ssb-loomio



Commit 2098413236ee6f4dd584c5a606b2036f11f2b177

Pass tests for postions made after closing at time.

Piet Geursen committed on 3/6/2018, 2:06:34 AM
Parent: baa693cac72b7ff23948b6de1b175ef386d99cb2

Files changed

position/sync/chooseOneResults.jschanged
test/position/sync/chooseOneResults.test.jschanged
position/sync/chooseOneResults.jsView
@@ -5,9 +5,9 @@
55 module.exports = function ({positions, poll}) { //postions must be of the correct type ie checked by the caller.
66 return positions.reduce(function (results, position) {
77 var { choice } = Position(position).positionDetails
88
9- if (choice >= poll.pollDetails.choices.length) {
9+ if (choice >= poll.pollDetails.choices.length || position.value.timestamp > poll.closesAt) {
1010 results.errors.invalidPositions.push(position)
1111 return results
1212 }
1313
test/position/sync/chooseOneResults.test.jsView
@@ -12,12 +12,14 @@
1212 const sallyId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/5=.ed25519'
1313
1414 const poll = '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256'
1515
16+const now = Number(new Date())
17+
1618 const validPoll = ChooseOnePoll({
1719 choices: [1, 2, 'three'],
1820 title: 'how many food',
19- closesAt: Date.now()
21+ closesAt: now
2022 })
2123
2224 test('ChooseOneResults - ChooseOneResults', function (t) {
2325 const positions = [
@@ -56,8 +58,33 @@
5658 t.deepEqual(actual.errors.invalidPositions[0], positions[0], 'invalid vote is on error object')
5759 t.end()
5860 })
5961
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+ ]
6166
67+ const actual = chooseOneResults({positions, poll: validPoll})
68+ t.true(actual[0], 'valid vote is counted')
6269 t.end()
6370 })
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+})

Built with git-ssb-web