2019-09-03 15:35:12 +02:00
|
|
|
'use strict'
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
const tap = require('tap')
|
2019-09-03 15:35:12 +02:00
|
|
|
const parse = require('../../parse/hint')
|
|
|
|
|
2019-10-20 00:19:11 +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
|
2019-10-20 00:19:11 +02:00
|
|
|
t.equal(parse(ctx, {...input, type: 'X'}), null)
|
2019-09-03 15:35:12 +02:00
|
|
|
|
|
|
|
t.end()
|
|
|
|
})
|