git ssb

0+

Piet / ssb-loomio



Tree: 1bab8bfe2ee8bd0453f1951d21f80ee743113c4e

Files: 1bab8bfe2ee8bd0453f1951d21f80ee743113c4e / test / errors / sync / index.test.js

2230 bytesRaw
1const test = require('tape')
2const pull = require('pull-stream')
3const pullAsync = require('pull-async')
4
5const isPositionChoiceError = require('../../../errors/sync/isPositionChoiceError')()
6const isPositionLateError = require('../../../errors/sync/isPositionLateError')()
7const isPositionTypeError = require('../../../errors/sync/isPositionTypeError')()
8
9const PositionTypeError = require('../../../errors/sync/positionTypeError')
10const PositionLateError = require('../../../errors/sync/positionLateError')
11const PositionChoiceError = require('../../../errors/sync/positionChoiceError')
12
13const ChooseOne = require('../../../position/async/chooseOne')
14
15test('positionTypeError', function (t) {
16 pull(
17 pullAsync(cb => {
18 ChooseOne({
19 poll: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256',
20 choice: 0
21 }, cb)
22 }),
23 pull.drain(validPosition => {
24 var invalidError = PositionTypeError({})
25 t.false(isPositionTypeError(invalidError), 'catches invalid error')
26
27 var validError = PositionTypeError({position: validPosition})
28 t.true(isPositionTypeError(validError), 'validates valid error')
29 t.end()
30 })
31
32 )
33})
34
35test('positionLateError', function (t) {
36 pull(
37 pullAsync(cb => {
38 ChooseOne({
39 poll: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256',
40 choice: 0
41 }, cb)
42 }),
43 pull.drain(validPosition => {
44 var invalidError = PositionLateError({})
45 t.false(isPositionTypeError(invalidError), 'catches invalid error')
46
47 var validError = PositionLateError({position: validPosition})
48 t.true(isPositionLateError(validError), 'validates valid error')
49 t.end()
50 })
51 )
52})
53
54test('positionChoiceError', function (t) {
55 pull(
56 pullAsync(cb => {
57 ChooseOne({
58 poll: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256',
59 choice: 0
60 }, cb)
61 }),
62 pull.drain(validPosition => {
63 var invalidError = PositionChoiceError({})
64 t.false(isPositionChoiceError(invalidError), 'catches invalid error')
65
66 var validError = PositionChoiceError({position: validPosition})
67 t.true(isPositionChoiceError(validError), 'validates valid error')
68 t.end()
69 })
70 )
71})
72

Built with git-ssb-web