Files: 5a278075ec43325cf000c2fcb66c71b38a75df86 / test / errors / sync / index.test.js
2226 bytesRaw
1 | const test = require('tape') |
2 | const pull = require('pull-stream') |
3 | const pullAsync = require('pull-async') |
4 | |
5 | const isPositionChoiceError = require('../../../errors/sync/isPositionChoiceError') |
6 | const isPositionLateError = require('../../../errors/sync/isPositionLateError') |
7 | const isPositionTypeError = require('../../../errors/sync/isPositionTypeError') |
8 | |
9 | const PositionTypeError = require('../../../errors/sync/positionTypeError') |
10 | const PositionLateError = require('../../../errors/sync/positionLateError') |
11 | const PositionChoiceError = require('../../../errors/sync/positionChoiceError') |
12 | |
13 | const ChooseOne = require('../../../position/async/chooseOne')() |
14 | |
15 | test('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 | |
35 | test('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 | |
54 | test('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