Files: 6360e70f9c420261c04295d55bd6181e31a333fb / test / errors / sync / index.test.js
2843 bytesRaw
1 | const test = require('tape') |
2 | const pull = require('pull-stream') |
3 | const pullAsync = require('pull-async') |
4 | const Server = require('../../../lib/testServer') |
5 | |
6 | const isPositionChoiceError = require('../../../errors/sync/isPositionChoiceError') |
7 | const isPositionLateError = require('../../../errors/sync/isPositionLateError') |
8 | const isPositionTypeError = require('../../../errors/sync/isPositionTypeError') |
9 | |
10 | const PositionTypeError = require('../../../errors/sync/positionTypeError') |
11 | const PositionLateError = require('../../../errors/sync/positionLateError') |
12 | const PositionChoiceError = require('../../../errors/sync/positionChoiceError') |
13 | |
14 | const pollOpts = { |
15 | title: 'want to join my coop?', |
16 | choices: [ |
17 | 'yeah', |
18 | 'nah' |
19 | ], |
20 | closesAt: new Date().toISOString() |
21 | } |
22 | |
23 | test('positionTypeError', function (t) { |
24 | var server = Server() |
25 | const scuttlePoll = require('../../../index')(server) |
26 | pull( |
27 | pullAsync(cb => scuttlePoll.poll.async.publishChooseOne(pollOpts, cb)), |
28 | pull.asyncMap((poll, cb) => { |
29 | scuttlePoll.position.async.publishChooseOne({ |
30 | poll, |
31 | choice: 0 |
32 | }, cb) |
33 | }), |
34 | pull.drain(validPosition => { |
35 | var invalidError = PositionTypeError({}) |
36 | t.false(isPositionTypeError(invalidError), 'catches invalid error') |
37 | |
38 | var validError = PositionTypeError({position: validPosition}) |
39 | t.true(isPositionTypeError(validError), 'validates valid error') |
40 | server.close() |
41 | t.end() |
42 | }) |
43 | ) |
44 | }) |
45 | |
46 | test('positionLateError', function (t) { |
47 | var server = Server() |
48 | const scuttlePoll = require('../../../index')(server) |
49 | pull( |
50 | pullAsync(cb => scuttlePoll.poll.async.publishChooseOne(pollOpts, cb)), |
51 | pull.asyncMap((poll, cb) => { |
52 | scuttlePoll.position.async.publishChooseOne({ |
53 | poll, |
54 | choice: 0 |
55 | }, cb) |
56 | }), |
57 | pull.drain(validPosition => { |
58 | var invalidError = PositionLateError({}) |
59 | t.false(isPositionTypeError(invalidError), 'catches invalid error') |
60 | |
61 | var validError = PositionLateError({position: validPosition}) |
62 | t.true(isPositionLateError(validError), 'validates valid error') |
63 | server.close() |
64 | t.end() |
65 | }) |
66 | ) |
67 | }) |
68 | |
69 | test('positionChoiceError', function (t) { |
70 | var server = Server() |
71 | const scuttlePoll = require('../../../index')(server) |
72 | pull( |
73 | pullAsync(cb => scuttlePoll.poll.async.publishChooseOne(pollOpts, cb)), |
74 | pull.asyncMap((poll, cb) => { |
75 | scuttlePoll.position.async.publishChooseOne({ |
76 | poll, |
77 | choice: 0 |
78 | }, cb) |
79 | }), |
80 | pull.drain(validPosition => { |
81 | var invalidError = PositionChoiceError({}) |
82 | t.false(isPositionChoiceError(invalidError), 'catches invalid error') |
83 | |
84 | var validError = PositionChoiceError({position: validPosition}) |
85 | t.true(isPositionChoiceError(validError), 'validates valid error') |
86 | server.close() |
87 | t.end() |
88 | }) |
89 | ) |
90 | }) |
91 |
Built with git-ssb-web