git ssb

0+

Piet / ssb-loomio



Commit 6730668ae7223a39f319ed33a69019c0ef1d8c38

Passes test

Piet Geursen committed on 3/9/2018, 4:20:29 AM
Parent: 5caf2c17fe0bf657ce2cbd15e624b51c8176b2e4

Files changed

position/sync/chooseOneResults.jschanged
test/position/sync/chooseOneResults.test.jschanged
position/sync/chooseOneResults.jsView
@@ -38,14 +38,25 @@
3838 acc.errors.push(PositionLateError({position}))
3939 return acc
4040 }
4141
42 + deleteExistingVotesByAuthor({results: acc.results, author})
4243 acc.results[choice].voters[author] = position
4344
4445 return acc
4546 }, {errors: [], results})
4647 }
4748
49 +// !!! assumes these are already sorted by time.
50 +// modifies results passed in
51 +function deleteExistingVotesByAuthor ({author, results}) {
52 + results.forEach(result => {
53 + if (result.voters[author]) {
54 + delete result.voters[author]
55 + }
56 + })
57 +}
58 +
4859 function isInvalidChoice ({position, poll}) {
4960 const { choice } = position.value.content.details
5061 return choice >= poll.value.content.details.choices.length
5162 }
test/position/sync/chooseOneResults.test.jsView
@@ -116,4 +116,16 @@
116116 const actual = chooseOneResults({positions, poll: validPoll})
117117 t.deepEqual(actual.errors[0].type, ERROR_POSITION_LATE, 'invalid vote is on error object')
118118 t.end()
119119 })
120 +
121 +test('ChooseOneResults - ChooseOneResults only counts latest vote by an author', function (t) {
122 + const positions = [
123 + { value: { content: ChooseOne({choice: 2, poll}), author: pietId } },
124 + { value: { content: ChooseOne({choice: 0, poll}), author: pietId } }
125 + ]
126 +
127 + const actual = chooseOneResults({positions, poll: validPoll})
128 + t.false(actual.results[2].voters[pietId], 'old vote is deleted')
129 + t.true(actual.results[0].voters[pietId], 'new vote is counted')
130 + t.end()
131 +})

Built with git-ssb-web