test/errors/sync/index.test.jsView |
---|
| 1 | +const test = require('tape') |
| 2 | + |
| 3 | +const isError = require('../../../errors/sync/isError') |
| 4 | +const isPositionChoiceError = require('../../../errors/sync/isPositionChoiceError')() |
| 5 | +const isPositionLateError = require('../../../errors/sync/isPositionLateError')() |
| 6 | +const isPositionTypeError = require('../../../errors/sync/isPositionTypeError')() |
| 7 | + |
| 8 | +const positionTypeError = require('../../../errors/sync/positionTypeError') |
| 9 | +const positionLateError = require('../../../errors/sync/positionLateError') |
| 10 | +const positionChoiceError = require('../../../errors/sync/positionChoiceError') |
| 11 | + |
| 12 | +const ChooseOne = require('../../../position/sync/chooseOne') |
| 13 | + |
| 14 | +test('positionTypeError', function (t) { |
| 15 | + var validPosition = ChooseOne({ |
| 16 | + poll: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256', |
| 17 | + choice: 0 |
| 18 | + }) |
| 19 | + var invalidError = positionTypeError({}) |
| 20 | + t.false(isPositionTypeError(invalidError), 'catches invalid error') |
| 21 | + |
| 22 | + var validError = positionTypeError({position: validPosition}) |
| 23 | + t.true(isPositionTypeError(validError), 'validates valid error') |
| 24 | + t.end() |
| 25 | +}) |
| 26 | + |
| 27 | +test('positionLateError', function (t) { |
| 28 | + var validPosition = ChooseOne({ |
| 29 | + poll: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256', |
| 30 | + choice: 0 |
| 31 | + }) |
| 32 | + var invalidError = positionLateError({}) |
| 33 | + t.false(isPositionTypeError(invalidError), 'catches invalid error') |
| 34 | + |
| 35 | + var validError = positionLateError({position: validPosition}) |
| 36 | + t.true(isPositionLateError(validError), 'validates valid error') |
| 37 | + t.end() |
| 38 | +}) |
| 39 | + |
| 40 | +test('positionChoiceError', function (t) { |
| 41 | + var validPosition = ChooseOne({ |
| 42 | + poll: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256', |
| 43 | + choice: 0 |
| 44 | + }) |
| 45 | + var invalidError = positionChoiceError({}) |
| 46 | + t.false(isPositionChoiceError(invalidError), 'catches invalid error') |
| 47 | + |
| 48 | + var validError = positionChoiceError({position: validPosition}) |
| 49 | + t.true(isPositionChoiceError(validError), 'validates valid error') |
| 50 | + t.end() |
| 51 | +}) |