git ssb

0+

Piet / ssb-loomio



Commit 9792bede1cbfa9f873cc29f78a3b82929b371767

Woops, pretty big bug with these tests fixed.

Piet Geursen committed on 5/14/2018, 10:24:36 PM
Parent: 1502f0ba17e8680d8ec32ad7bf6195d105d75f6a

Files changed

test/results/sync/buildResults.test.jschanged
test/results/sync/buildResults.test.jsView
@@ -4,9 +4,9 @@
44 const server = Server()
55 const ChooseOne = require('../../../position/async/buildChooseOne')(server)
66 const chooseOneResults = require('../../../results/sync/buildResults')
77 const PublishChooseOnePoll = require('../../../poll/async/publishChooseOne')(server)
8-const {ERROR_POSITION_CHOICE, ERROR_POSITION_LATE} = require('../../../types')
8+const {ERROR_POSITION_CHOICE, ERROR_POSITION_LATE, ERROR_POSITION_TYPE} = require('../../../types')
99
1010 const pietId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/0=.ed25519'
1111 const mixId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/1=.ed25519'
1212 const mikeyId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/2=.ed25519'
@@ -72,9 +72,10 @@
7272 fullPosition.value.content = position
7373 cb(err, fullPosition)
7474 })
7575 }),
76- pull.collect(postions => {
76+ pull.collect((err, positions) => {
77+ t.error(err)
7778 const actual = chooseOneResults({positions, poll})
7879 t.deepEqual(actual, expected, 'results are correct')
7980 t.end()
8081 })
@@ -99,17 +100,74 @@
99100 fullPosition.value.content = position
100101 cb(err, fullPosition)
101102 })
102103 }),
103- pull.collect(postions => {
104+ pull.collect((err, positions) => {
105+ t.error(err)
104106 const actual = chooseOneResults({positions, poll})
105107 t.false(actual.results[3], 'invalid vote is not counted')
106108 t.end()
107109 })
108110 )
109111 })
110112 })
111113
114+test('ChooseOneResults - a position of the wrong type is not counted', function (t) {
115+ PublishChooseOnePoll(validPoll, function (err, poll) {
116+ t.error(err)
117+ const positions = [
118+ { value: { content: {choice: 2, poll}, author: pietId }, key: '%dfkjdf' }
119+ ]
120+
121+ pull(
122+ pull.values(positions),
123+ pull.asyncMap((fullPosition, cb) => {
124+ var positionAndPoll = Object.assign({}, fullPosition.value.content, { poll })
125+ ChooseOne(positionAndPoll, (err, position) => {
126+ t.error(err)
127+ fullPosition.value.content = position
128+ cb(err, fullPosition)
129+ })
130+ }),
131+ pull.collect((err, positions) => {
132+ t.error(err)
133+ positions[0].value.content.details.type = 'INVALID'
134+ const actual = chooseOneResults({positions, poll})
135+ t.false(actual.results[3], 'invalid vote is not counted')
136+ t.end()
137+ })
138+ )
139+ })
140+})
141+
142+test('ChooseOneResults - a position stated for an invalid positionType is included in the errors object', function (t) {
143+ PublishChooseOnePoll(validPoll, function (err, poll) {
144+ t.error(err)
145+ const positions = [
146+ { value: { content: {choice: 2, poll}, author: pietId }, key: '%fdfslkjdf' }
147+ ]
148+
149+ pull(
150+ pull.values(positions),
151+ pull.asyncMap((fullPosition, cb) => {
152+ var positionAndPoll = Object.assign({}, fullPosition.value.content, { poll })
153+ ChooseOne(positionAndPoll, (err, position) => {
154+ t.error(err)
155+ fullPosition.value.content = position
156+ cb(err, fullPosition)
157+ })
158+ }),
159+ pull.collect((err, positions) => {
160+ t.error(err)
161+ positions[0].value.content.details.type = 'INVALID'
162+ const actual = chooseOneResults({positions, poll})
163+ t.deepEqual(actual.errors[0].type, ERROR_POSITION_TYPE, 'invalid vote is on error object')
164+ t.end()
165+ })
166+ )
167+ })
168+})
169+
112170 test('ChooseOneResults - a position stated for an invalid choice index is included in the errors object', function (t) {
113171 PublishChooseOnePoll(validPoll, function (err, poll) {
114172 t.error(err)
115173 const positions = [
@@ -126,9 +184,10 @@
126184 fullPosition.value.content = position
127185 cb(err, fullPosition)
128186 })
129187 }),
130- pull.collect(postions => {
188+ pull.collect((err, positions) => {
189+ t.error(err)
131190 const actual = chooseOneResults({positions, poll})
132191 t.deepEqual(actual.errors[0].type, ERROR_POSITION_CHOICE, 'invalid vote is on error object')
133192 t.end()
134193 })
@@ -151,9 +210,10 @@
151210 fullPosition.value.content = position
152211 cb(err, fullPosition)
153212 })
154213 }),
155- pull.collect(postions => {
214+ pull.collect((err, positions) => {
215+ t.error(err)
156216 const actual = chooseOneResults({positions, poll})
157217 t.ok(actual.results[0].voters[pietId], 'valid vote is counted')
158218 t.end()
159219 })
@@ -176,9 +236,10 @@
176236 fullPosition.value.content = position
177237 cb(err, fullPosition)
178238 })
179239 }),
180- pull.collect(postions => {
240+ pull.collect((err, positions) => {
241+ t.error(err)
181242 const actual = chooseOneResults({positions, poll})
182243 t.deepEqual(actual.results[0].voters, {}, 'invalid vote is not counted')
183244 t.end()
184245 })
@@ -201,9 +262,10 @@
201262 fullPosition.value.content = position
202263 cb(err, fullPosition)
203264 })
204265 }),
205- pull.collect(postions => {
266+ pull.collect((err, positions) => {
267+ t.error(err)
206268 const actual = chooseOneResults({positions, poll})
207269 t.deepEqual(actual.errors[0].type, ERROR_POSITION_LATE, 'invalid vote is on error object')
208270 t.end()
209271 })
@@ -227,9 +289,10 @@
227289 fullPosition.value.content = position
228290 cb(err, fullPosition)
229291 })
230292 }),
231- pull.collect(postions => {
293+ pull.collect((err, positions) => {
294+ t.error(err)
232295 const actual = chooseOneResults({positions, poll})
233296 t.false(actual.results[2].voters[pietId], 'old vote is deleted')
234297 t.true(actual.results[0].voters[pietId], 'new vote is counted')
235298 t.end()

Built with git-ssb-web