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

119 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

import tap from 'tap';
import {parseWarning as parse} from '../../parse/warning.js';
import merge from 'lodash/merge.js';
2019-09-03 15:35:12 +02:00
const profile = {
parseProductsBitmask: (_, bitmask) => [bitmask],
parseDateTime: (_, date, time) => date + ':' + time,
};
const ctx = {
data: {},
opt: {},
profile,
};
2019-09-03 15:35:12 +02:00
2021-05-20 16:42:43 +01:00
tap.test('parses warnings correctly', (t) => {
2019-09-03 15:35:12 +02:00
const input = {
hid: 'some warning ID', // todo: null
head: 'some<br>summary', // todo: null
text: 'some long<br>text<br><br />body', // todo: null
icon: {type: 'HimWarn'}, // todo: null
prio: 123,
cat: 1,
};
2019-09-03 15:35:12 +02:00
const expected = {
id: 'some warning ID',
type: 'status',
summary: 'some\nsummary',
text: 'some long\ntext\n\nbody',
icon: {type: 'HimWarn'},
priority: 123,
category: 1,
};
2019-09-03 15:35:12 +02:00
t.same(parse(ctx, input), expected);
2019-09-03 15:35:12 +02:00
// without basic fields
t.same(parse(ctx, {...input, hid: null}), {...expected, id: null});
t.same(parse(ctx, {...input, head: null}), {...expected, summary: null});
t.same(parse(ctx, {...input, text: null}), {...expected, text: null});
t.same(parse(ctx, {...input, cat: null}), {...expected, category: null});
2019-09-03 15:35:12 +02:00
// without icon
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {...input, icon: null}), {
...expected, type: 'warning', icon: null,
});
2019-09-03 15:35:12 +02:00
// with products
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {...input, prod: 123}), {
...expected, products: [123],
});
2019-09-03 15:35:12 +02:00
// validFrom, validUntil, modified
2021-05-20 16:42:43 +01:00
t.same(parse(ctx, {
2019-09-03 15:35:12 +02:00
...input,
sDate: '20190101', sTime: '094020',
eDate: '20190101', eTime: '114020',
lModDate: '20190101', lModTime: '084020',
}), {
...expected,
validFrom: '20190101:094020',
validUntil: '20190101:114020',
modified: '20190101:084020',
});
2019-09-03 15:35:12 +02:00
// events
const ctxWithHimMsgEventL = {
...ctx,
res: {
common: {
himMsgEventL: [{
fDate: '20211111', fTime: '123456',
tDate: '20211221', tTime: '012345',
}],
},
},
};
const inputWithEventRefL = {
...input,
eventRefL: [0],
};
const expectedWithEvents = {
...expected,
events: [{
fromLocation: null,
toLocation: null,
start: '20211111:123456',
end: '20211221:012345',
sections: [],
}],
};
t.same(parse(
ctxWithHimMsgEventL,
inputWithEventRefL,
), expectedWithEvents);
// without res.common.himMsgEventL[].{f,t}Time
t.same(parse(
merge(ctxWithHimMsgEventL, {
res: {
common: {
himMsgEventL: [{
fTime: null,
tTime: null,
}],
},
},
}),
inputWithEventRefL,
), merge(expectedWithEvents, {
events: [{
start: '20211111:000000',
end: '20211221:000000',
}],
}));
// todo: .edges
t.end();
});