git ssb

0+

Piet / ssb-loomio



Tree: 6360e70f9c420261c04295d55bd6181e31a333fb

Files: 6360e70f9c420261c04295d55bd6181e31a333fb / test / position / async / buildChooseOne.test.js

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

Built with git-ssb-web