Commit 9792bede1cbfa9f873cc29f78a3b82929b371767
Woops, pretty big bug with these tests fixed.
Piet Geursen committed on 5/14/2018, 10:24:36 PMParent: 1502f0ba17e8680d8ec32ad7bf6195d105d75f6a
Files changed
test/results/sync/buildResults.test.js | changed |
test/results/sync/buildResults.test.js | ||
---|---|---|
@@ -4,9 +4,9 @@ | ||
4 | 4 | const server = Server() |
5 | 5 | const ChooseOne = require('../../../position/async/buildChooseOne')(server) |
6 | 6 | const chooseOneResults = require('../../../results/sync/buildResults') |
7 | 7 | 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') | |
9 | 9 | |
10 | 10 | const pietId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/0=.ed25519' |
11 | 11 | const mixId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/1=.ed25519' |
12 | 12 | const mikeyId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/2=.ed25519' |
@@ -72,9 +72,10 @@ | ||
72 | 72 | fullPosition.value.content = position |
73 | 73 | cb(err, fullPosition) |
74 | 74 | }) |
75 | 75 | }), |
76 | - pull.collect(postions => { | |
76 | + pull.collect((err, positions) => { | |
77 | + t.error(err) | |
77 | 78 | const actual = chooseOneResults({positions, poll}) |
78 | 79 | t.deepEqual(actual, expected, 'results are correct') |
79 | 80 | t.end() |
80 | 81 | }) |
@@ -99,17 +100,74 @@ | ||
99 | 100 | fullPosition.value.content = position |
100 | 101 | cb(err, fullPosition) |
101 | 102 | }) |
102 | 103 | }), |
103 | - pull.collect(postions => { | |
104 | + pull.collect((err, positions) => { | |
105 | + t.error(err) | |
104 | 106 | const actual = chooseOneResults({positions, poll}) |
105 | 107 | t.false(actual.results[3], 'invalid vote is not counted') |
106 | 108 | t.end() |
107 | 109 | }) |
108 | 110 | ) |
109 | 111 | }) |
110 | 112 | }) |
111 | 113 | |
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 | + | |
112 | 170 | test('ChooseOneResults - a position stated for an invalid choice index is included in the errors object', function (t) { |
113 | 171 | PublishChooseOnePoll(validPoll, function (err, poll) { |
114 | 172 | t.error(err) |
115 | 173 | const positions = [ |
@@ -126,9 +184,10 @@ | ||
126 | 184 | fullPosition.value.content = position |
127 | 185 | cb(err, fullPosition) |
128 | 186 | }) |
129 | 187 | }), |
130 | - pull.collect(postions => { | |
188 | + pull.collect((err, positions) => { | |
189 | + t.error(err) | |
131 | 190 | const actual = chooseOneResults({positions, poll}) |
132 | 191 | t.deepEqual(actual.errors[0].type, ERROR_POSITION_CHOICE, 'invalid vote is on error object') |
133 | 192 | t.end() |
134 | 193 | }) |
@@ -151,9 +210,10 @@ | ||
151 | 210 | fullPosition.value.content = position |
152 | 211 | cb(err, fullPosition) |
153 | 212 | }) |
154 | 213 | }), |
155 | - pull.collect(postions => { | |
214 | + pull.collect((err, positions) => { | |
215 | + t.error(err) | |
156 | 216 | const actual = chooseOneResults({positions, poll}) |
157 | 217 | t.ok(actual.results[0].voters[pietId], 'valid vote is counted') |
158 | 218 | t.end() |
159 | 219 | }) |
@@ -176,9 +236,10 @@ | ||
176 | 236 | fullPosition.value.content = position |
177 | 237 | cb(err, fullPosition) |
178 | 238 | }) |
179 | 239 | }), |
180 | - pull.collect(postions => { | |
240 | + pull.collect((err, positions) => { | |
241 | + t.error(err) | |
181 | 242 | const actual = chooseOneResults({positions, poll}) |
182 | 243 | t.deepEqual(actual.results[0].voters, {}, 'invalid vote is not counted') |
183 | 244 | t.end() |
184 | 245 | }) |
@@ -201,9 +262,10 @@ | ||
201 | 262 | fullPosition.value.content = position |
202 | 263 | cb(err, fullPosition) |
203 | 264 | }) |
204 | 265 | }), |
205 | - pull.collect(postions => { | |
266 | + pull.collect((err, positions) => { | |
267 | + t.error(err) | |
206 | 268 | const actual = chooseOneResults({positions, poll}) |
207 | 269 | t.deepEqual(actual.errors[0].type, ERROR_POSITION_LATE, 'invalid vote is on error object') |
208 | 270 | t.end() |
209 | 271 | }) |
@@ -227,9 +289,10 @@ | ||
227 | 289 | fullPosition.value.content = position |
228 | 290 | cb(err, fullPosition) |
229 | 291 | }) |
230 | 292 | }), |
231 | - pull.collect(postions => { | |
293 | + pull.collect((err, positions) => { | |
294 | + t.error(err) | |
232 | 295 | const actual = chooseOneResults({positions, poll}) |
233 | 296 | t.false(actual.results[2].voters[pietId], 'old vote is deleted') |
234 | 297 | t.true(actual.results[0].voters[pietId], 'new vote is counted') |
235 | 298 | t.end() |
Built with git-ssb-web