git ssb

0+

Piet / ssb-loomio



Commit d6df270592b877a672af61b40638876aeba4c5a4

Get one test passing.

Piet Geursen committed on 4/11/2018, 2:46:14 AM
Parent: 9e5a426e0a4859825b9743e57b563a7845310484

Files changed

package-lock.jsonchanged
results/sync/buildResults.jschanged
test/results/sync/buildResults.test.jschanged
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 193428 bytes
New file size: 193428 bytes
results/sync/buildResults.jsView
@@ -33,12 +33,10 @@
3333 }
3434 })
3535
3636 return positions.reduce(function (acc, position) {
37- console.log(position)
3837 const { author } = position.value
3938 const { choice } = getContent(position).details
40- console.log(author, choice)
4139
4240 if (isInvalidChoice({position, poll})) {
4341 acc.errors.push(PositionChoiceError({position}))
4442 return acc
test/results/sync/buildResults.test.jsView
@@ -1,9 +1,13 @@
11 const test = require('tape')
22 const pull = require('pull-stream')
3-const ChooseOne = require('../../../position/async/buildChooseOne')()
3+const pullAsync = require('pull-async')
4+const Server = require('../../../lib/testServer')
5+const server = Server()
6+const ChooseOne = require('../../../position/async/buildChooseOne')(server)
47 const ChooseOnePoll = require('../../../poll/sync/buildChooseOne')
58 const chooseOneResults = require('../../../results/sync/buildResults')
9+const PublishChooseOnePoll = require('../../../poll/async/publishChooseOne')(server)
610 const {isPosition, isPoll} = require('ssb-poll-schema')
711 const {ERROR_POSITION_CHOICE, ERROR_POSITION_LATE} = require('../../../types')
812
913 const pietId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/0=.ed25519'
@@ -17,69 +21,69 @@
1721
1822 const now = new Date().toISOString()
1923
2024 const validPoll = {
21- key: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256',
22- value: {
23- content: ChooseOnePoll({
24- choices: [1, 2, 'three'],
25- title: 'how many food',
26- closesAt: now
27- })
28- }
25+ choices: [1, 2, 'three'],
26+ title: 'how many food',
27+ closesAt: now
2928 }
3029
3130 test('ChooseOneResults - ChooseOneResults', function (t) {
32- const positions = [
33- { value: { content: {choice: 0, poll}, author: pietId } },
34- { value: { content: {choice: 0, poll}, author: mixId } },
35- { value: { content: {choice: 0, poll}, author: mikeyId } },
36- { value: { content: {choice: 1, poll}, author: timmyId } },
37- { value: { content: {choice: 1, poll}, author: tommyId } },
38- { value: { content: {choice: 2, poll}, author: sallyId } }
39- ]
31+ PublishChooseOnePoll(validPoll, function (err, poll) {
32+ t.error(err)
4033
41- const expected = {
42- results: [
43- {
44- choice: 1,
45- voters: {
46- [pietId]: positions[0],
47- [mixId]: positions[1],
48- [mikeyId]: positions[2]
34+ const positions = [
35+ { value: { content: {choice: 0, poll}, author: pietId }, key: '%dfkjd0' },
36+ { value: { content: {choice: 0, poll}, author: mixId }, key: '%dfkjd1' },
37+ { value: { content: {choice: 0, poll}, author: mikeyId }, key: '%dfkjd2' },
38+ { value: { content: {choice: 1, poll}, author: timmyId }, key: '%dfkjd3' },
39+ { value: { content: {choice: 1, poll}, author: tommyId }, key: '%dfkjd4' },
40+ { value: { content: {choice: 2, poll}, author: sallyId }, key: '%dfkjd5' }
41+ ]
42+
43+ const expected = {
44+ results: [
45+ {
46+ choice: 1,
47+ voters: {
48+ [pietId]: positions[0],
49+ [mixId]: positions[1],
50+ [mikeyId]: positions[2]
51+ }
52+ },
53+ {
54+ choice: 2,
55+ voters: {
56+ [timmyId]: positions[3],
57+ [tommyId]: positions[4]
58+ }
59+ },
60+ {
61+ choice: 'three',
62+ voters: {
63+ [sallyId]: positions[5]
64+ }
4965 }
50- },
51- {
52- choice: 2,
53- voters: {
54- [timmyId]: positions[3],
55- [tommyId]: positions[4]
56- }
57- },
58- {
59- choice: 'three',
60- voters: {
61- [sallyId]: positions[5]
62- }
63- }
64- ],
65- errors: {}
66- }
66+ ],
67+ errors: {}
68+ }
6769
68- pull(
69- pull.values(positions),
70- pull.asyncMap((fullPosition, cb) => {
71- ChooseOne(fullPosition.value.content, (err, position) => {
72- fullPosition.value.content = position
73- cb(err, fullPosition)
70+ pull(
71+ pull.values(positions),
72+ pull.asyncMap((fullPosition, cb) => {
73+ var positionAndPoll = Object.assign({}, fullPosition.value.content, { poll })
74+ ChooseOne(positionAndPoll, (err, position) => {
75+ fullPosition.value.content = position
76+ cb(err, fullPosition)
77+ })
78+ }),
79+ pull.collect(postions => {
80+ const actual = chooseOneResults({positions, poll})
81+ t.deepEqual(actual, expected, 'results are correct')
82+ t.end()
7483 })
75- }),
76- pull.collect(postions => {
77- const actual = chooseOneResults({positions, poll: validPoll})
78- t.deepEqual(actual, expected, 'results are correct')
79- t.end()
80- })
81- )
84+ )
85+ })
8286 })
8387
8488 test('ChooseOneResults - a position stated for an invalid choice index is not counted', function (t) {
8589 const positions = [

Built with git-ssb-web