git ssb

0+

Piet / ssb-loomio



Tree: b792992e79b3b28771b347e53432ec76daa47ee5

Files: b792992e79b3b28771b347e53432ec76daa47ee5 / test / position / async / buildChooseOne.test.js

2014 bytesRaw
1const test = require('tape')
2const pull = require('pull-stream')
3const pullAsync = require('pull-async')
4const {isPosition} = require('ssb-poll-schema')
5const Server = require('../../../lib/testServer')
6
7var server = Server()
8
9const publishChooseOne = require('../../../poll/async/publishChooseOne')(server)
10const ChooseOne = require('../../../position/async/buildChooseOne')(server)
11
12test('position.async.buildChooseOne', function (t) {
13 t.plan(5)
14
15 const pollOpts = {title: 'are you reading this', choices: ['yes', 'no'], closesAt: new Date().toISOString()}
16 publishChooseOne(pollOpts, (err, poll) => {
17 if (err) throw err
18
19 pull(
20 pullAsync(cb => {
21 ChooseOne({
22 poll
23 }, cb)
24 }),
25 pull.drain((missingChoice) => {
26 t.false(isPosition(missingChoice), 'missing a choice')
27 })
28 )
29
30 t.throws(() => {
31 pull(
32 pullAsync(cb => {
33 ChooseOne({
34 choice: 0
35 }, cb)
36 }),
37 pull.drain((missingPoll) => {})
38 )
39 }, 'missing a poll')
40
41 t.throws(() => {
42 pull(
43 pullAsync(cb => {
44 ChooseOne({
45 poll: 'dog?',
46 choice: 0
47 }, cb)
48 }),
49 pull.drain((missingPoll) => { })
50 )
51 }, 'does not reference a poll')
52
53 pull(
54 pullAsync(cb => {
55 ChooseOne({
56 poll,
57 choice: 0
58 }, cb)
59 }),
60 pull.drain((poll) => {
61 t.true(isPosition(poll), 'simple')
62 })
63 )
64
65 pull(
66 pullAsync(cb => {
67 ChooseOne({
68 poll,
69 choice: 0
70 }, cb)
71 }),
72 pull.map((validPosition) => {
73 return {
74 key: '%somekey',
75 value: {
76 content: validPosition
77 }
78 }
79 }),
80 pull.drain((poll) => {
81 t.true(isPosition(poll), 'simple (full msg)')
82 })
83 )
84
85 // NOTE - we might want an isChooseOnePosition in future
86 // t.true(isChooseOnePosition(fullPositionMsg), 'simple (full msg)')
87 })
88})
89

Built with git-ssb-web