-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
53 lines (40 loc) · 1.48 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict'
const test = require('tape')
const validJourney = require('friendly-public-transport-format/examples/valid-journey.json')
const validSimpleJourney = require('friendly-public-transport-format/examples/valid-simple-journey.json')
const invalidJourney = require('friendly-public-transport-format/examples/invalid-journey.json')
const createValidate = require('.')
const validate = createValidate()
test('passes with valid-journey.json from FPTF', (t) => {
t.doesNotThrow(() => validate(validJourney))
t.end()
})
test('passes with valid-simple-journey.json from FPTF', (t) => {
t.doesNotThrow(() => validate(validSimpleJourney))
t.end()
})
test('fails with invalid-journey.json from FPTF', (t) => {
t.throws(() => validate(invalidJourney))
t.end()
})
test('against FPTF/valid-journey.json: passes with `journey` type', (t) => {
t.doesNotThrow(() => validate(validJourney, 'journey'))
t.doesNotThrow(() => validate(validJourney, ['journey']))
t.doesNotThrow(() => validate(validJourney, ['journey', 'schedule']))
t.end()
})
test('against FPTF/valid-journey.json: fails with non-`journey` type', (t) => {
t.throws(() => validate(validJourney, 'schedule'))
t.throws(() => validate(validJourney, ['schedule']))
t.throws(() => validate(validJourney, ['stop', 'station']))
t.end()
})
test('lets you override the validators', (t) => {
const validate = createValidate({
journey: () => {}
})
t.doesNotThrow(() => {
validate(invalidJourney)
})
t.end()
})