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

64 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

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
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, {
...input, line: null, addName: input.line,
}), expected);
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
...input, line: null, name: input.line,
}), expected);
2019-09-03 15:35:12 +02:00
// no prodCtx.lineId
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
...input, prodCtx: {...input.prodCtx, lineId: null},
2019-09-03 15:35:12 +02:00
}), {
...expected, id: 'foo-line',
});
2019-09-03 15:35:12 +02:00
// no prodCtx
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
...input, prodCtx: undefined,
2019-09-03 15:35:12 +02:00
}), {
...omit(expected, [
'adminCode',
]),
id: 'foo-line',
fahrtNr: null,
});
t.end();
});