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

59 lines
1.1 KiB
JavaScript
Raw Normal View History

import tap from 'tap';
import {parseHint as parse} from '../../parse/hint.js';
2019-09-03 15:35:12 +02:00
const ctx = {
data: {},
opt: {},
profile: {},
};
2019-09-03 15:35:12 +02:00
2021-05-20 16:42:43 +01:00
tap.test('parses hints correctly', (t) => {
2019-09-03 15:35:12 +02:00
const input = {
type: 'A',
code: 'bf',
prio: 123,
txtN: 'some text',
};
2019-09-03 15:35:12 +02:00
const expected = {
type: 'hint',
code: 'bf',
text: 'some text',
};
2019-09-03 15:35:12 +02:00
t.same(parse(ctx, input), expected);
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
...input, type: 'I',
}), expected);
2019-09-03 15:35:12 +02:00
// alternative trip
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
...input, type: 'L', jid: 'trip id',
2019-09-03 15:35:12 +02:00
}), {
...expected, type: 'status', code: 'alternative-trip', tripId: 'trip id',
});
2019-09-03 15:35:12 +02:00
// type: M
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
...input, type: 'M', txtS: 'some summary',
2019-09-03 15:35:12 +02:00
}), {
...expected, type: 'status', summary: 'some summary',
});
2019-09-03 15:35:12 +02:00
// type: D
for (const type of ['D', 'U', 'R', 'N', 'Y']) {
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {...input, type}), {
...expected, type: 'status',
});
2019-09-03 15:35:12 +02:00
}
// .code via .icon
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
...input, code: null, icon: {type: 'cancel'},
}), {...expected, code: 'cancelled'});
2019-09-03 15:35:12 +02:00
// invalid
t.equal(parse(ctx, {...input, type: 'X'}), null);
2019-09-03 15:35:12 +02:00
t.end();
});