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

59 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2022-05-07 16:17:37 +02:00
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'
}
const expected = {
type: 'hint',
code: 'bf',
text: 'some text'
}
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, input), expected)
t.same(parse(ctx, {
2019-09-03 15:35:12 +02:00
...input, type: 'I'
}), expected)
// alternative trip
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
2019-09-03 15:35:12 +02:00
...input, type: 'L', jid: 'trip id'
}), {
...expected, type: 'status', code: 'alternative-trip', tripId: 'trip id'
})
// type: M
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
2019-09-03 15:35:12 +02:00
...input, type: 'M', txtS: 'some summary'
}), {
...expected, type: 'status', summary: 'some summary'
})
// 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}), {
2019-09-03 15:35:12 +02:00
...expected, type: 'status'
})
}
// .code via .icon
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
2019-09-03 15:35:12 +02:00
...input, code: null, icon: {type: 'cancel'}
}), {...expected, code: 'cancelled'})
// invalid
t.equal(parse(ctx, {...input, type: 'X'}), null)
2019-09-03 15:35:12 +02:00
t.end()
})