Commit d6df270592b877a672af61b40638876aeba4c5a4
Get one test passing.
Piet Geursen committed on 4/11/2018, 2:46:14 AMParent: 9e5a426e0a4859825b9743e57b563a7845310484
Files changed
package-lock.json | changed |
results/sync/buildResults.js | changed |
test/results/sync/buildResults.test.js | changed |
package-lock.json | ||
---|---|---|
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.js | ||
---|---|---|
@@ -33,12 +33,10 @@ | ||
33 | 33 | } |
34 | 34 | }) |
35 | 35 | |
36 | 36 | return positions.reduce(function (acc, position) { |
37 | - console.log(position) | |
38 | 37 | const { author } = position.value |
39 | 38 | const { choice } = getContent(position).details |
40 | - console.log(author, choice) | |
41 | 39 | |
42 | 40 | if (isInvalidChoice({position, poll})) { |
43 | 41 | acc.errors.push(PositionChoiceError({position})) |
44 | 42 | return acc |
test/results/sync/buildResults.test.js | ||
---|---|---|
@@ -1,9 +1,13 @@ | ||
1 | 1 | const test = require('tape') |
2 | 2 | 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) | |
4 | 7 | const ChooseOnePoll = require('../../../poll/sync/buildChooseOne') |
5 | 8 | const chooseOneResults = require('../../../results/sync/buildResults') |
9 | +const PublishChooseOnePoll = require('../../../poll/async/publishChooseOne')(server) | |
6 | 10 | const {isPosition, isPoll} = require('ssb-poll-schema') |
7 | 11 | const {ERROR_POSITION_CHOICE, ERROR_POSITION_LATE} = require('../../../types') |
8 | 12 | |
9 | 13 | const pietId = '@Mq8D3YC6VdErKQzV3oi2oK5hHSoIwR0hUQr4M46wr/0=.ed25519' |
@@ -17,69 +21,69 @@ | ||
17 | 21 | |
18 | 22 | const now = new Date().toISOString() |
19 | 23 | |
20 | 24 | 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 | |
29 | 28 | } |
30 | 29 | |
31 | 30 | 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) | |
40 | 33 | |
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 | + } | |
49 | 65 | } |
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 | + } | |
67 | 69 | |
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() | |
74 | 83 | }) |
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 | + }) | |
82 | 86 | }) |
83 | 87 | |
84 | 88 | test('ChooseOneResults - a position stated for an invalid choice index is not counted', function (t) { |
85 | 89 | const positions = [ |
Built with git-ssb-web