mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
parseWarning: handle missing common.himMsgEventL[].{f,t}Time 🐛✅
This commit is contained in:
parent
bb70081ceb
commit
b1c2eb9b93
2 changed files with 57 additions and 3 deletions
|
@ -18,13 +18,15 @@ const parseMsgEdge = (ctx) => (e) => {
|
||||||
res.toLocation = Array.isArray(e.toLocations) && e.toLocations[0] || e.toLocation || null
|
res.toLocation = Array.isArray(e.toLocations) && e.toLocations[0] || e.toLocation || null
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fallbackTime = '000000' // midnight
|
||||||
const parseMsgEvent = (ctx) => (e) => {
|
const parseMsgEvent = (ctx) => (e) => {
|
||||||
const {profile} = ctx // todo: test that covers this
|
const {profile} = ctx // todo: test that covers this
|
||||||
return {
|
return {
|
||||||
fromLocation: Array.isArray(e.fromLocations) && e.fromLocations[0] || e.fromLocation || null,
|
fromLocation: Array.isArray(e.fromLocations) && e.fromLocations[0] || e.fromLocation || null,
|
||||||
toLocation: Array.isArray(e.toLocations) && e.toLocations[0] || e.toLocation || null,
|
toLocation: Array.isArray(e.toLocations) && e.toLocations[0] || e.toLocation || null,
|
||||||
start: profile.parseDateTime(ctx, e.fDate, e.fTime, null),
|
start: profile.parseDateTime(ctx, e.fDate, e.fTime || fallbackTime, null),
|
||||||
end: profile.parseDateTime(ctx, e.tDate, e.tTime, null),
|
end: profile.parseDateTime(ctx, e.tDate, e.tTime || fallbackTime, null),
|
||||||
sections: e.sectionNums || [] // todo: parse
|
sections: e.sectionNums || [] // todo: parse
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
const tap = require('tap')
|
const tap = require('tap')
|
||||||
const parse = require('../../parse/warning')
|
const parse = require('../../parse/warning')
|
||||||
|
const merge = require('lodash/merge')
|
||||||
|
|
||||||
const profile = {
|
const profile = {
|
||||||
parseProductsBitmask: (_, bitmask) => [bitmask],
|
parseProductsBitmask: (_, bitmask) => [bitmask],
|
||||||
|
@ -63,6 +64,57 @@ tap.test('parses warnings correctly', (t) => {
|
||||||
modified: '20190101:084020'
|
modified: '20190101:084020'
|
||||||
})
|
})
|
||||||
|
|
||||||
// todo: .edges, .events
|
// 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()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue