git ssb

0+

Piet / ssb-loomio



Tree: 15faa252573d24fb834a5b13c7db4411cf2edb21

Files: 15faa252573d24fb834a5b13c7db4411cf2edb21 / test / poll / async / buildUpatedClosingTime.test.js

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

Built with git-ssb-web