db-vendo-client/test/parse/line.js

64 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2022-05-07 16:17:37 +02:00
import tap from 'tap'
import omit from 'lodash/omit.js'
import {parseLine as parse} from '../../parse/line.js'
2019-09-03 15:35:12 +02:00
const profile = {
products: [
{id: 'train', bitmasks: [1]},
{id: 'ferry', bitmasks: [2]},
{id: 'bus', bitmasks: [4, 8]}
]
}
const ctx = {
data: {},
opt: {},
profile
}
2019-09-03 15:35:12 +02:00
2021-05-20 16:42:43 +01:00
tap.test('parses lines correctly', (t) => {
2019-09-03 15:35:12 +02:00
const input = {
line: 'foo line',
prodCtx: {
lineId: 'Foo ',
num: 123,
// HAFAS endpoints commonly have these padded admin codes.
admin: 'foo---',
2019-09-03 15:35:12 +02:00
}
}
const expected = {
type: 'line',
id: 'foo',
fahrtNr: 123,
name: 'foo line',
public: true,
adminCode: 'foo---',
2019-09-03 15:35:12 +02:00
}
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, input), expected)
2019-09-03 15:35:12 +02:00
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
2019-09-03 15:35:12 +02:00
...input, line: null, addName: input.line
}), expected)
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
2019-09-03 15:35:12 +02:00
...input, line: null, name: input.line
}), expected)
// no prodCtx.lineId
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
2019-09-03 15:35:12 +02:00
...input, prodCtx: {...input.prodCtx, lineId: null}
}), {
...expected, id: 'foo-line'
})
// no prodCtx
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
2019-09-03 15:35:12 +02:00
...input, prodCtx: undefined
}), {
...omit(expected, [
'adminCode',
]),
id: 'foo-line',
fahrtNr: null,
2019-09-03 15:35:12 +02:00
})
t.end()
})