2024-12-07 16:16:31 +00:00
import tap from 'tap' ;
import { parseRemarks as parse } from '../../parse/remarks.js' ;
2024-12-08 21:42:57 +00:00
import { parseDateTime } from '../../parse/date-time.js' ;
2024-12-07 16:16:31 +00:00
const ctx = {
data : { } ,
opt : { } ,
profile : {
parseHintByCode : _ => null ,
parseDateTime ,
timezone : 'Europe/Berlin' ,
locale : 'de-DE' ,
} ,
} ;
tap . test ( 'parses meldungenAsObject correctly' , ( t ) => {
const input = { meldungenAsObject : [ {
2024-12-08 21:42:57 +00:00
code : 'MDA-AK-MSG-1000' ,
nachrichtKurz : 'Connection is in the past.' ,
nachrichtLang : 'Selected connection is in the past.' ,
fahrtRichtungKennzeichen : 'HINFAHRT' ,
} ] } ;
2024-12-07 16:16:31 +00:00
const expected = [ {
2024-12-08 21:42:57 +00:00
code : 'MDA-AK-MSG-1000' ,
summary : 'Connection is in the past.' ,
text : 'Selected connection is in the past.' ,
type : 'hint' ,
} ] ;
2024-12-07 16:16:31 +00:00
t . same ( parse ( ctx , input ) , expected ) ;
t . end ( ) ;
} ) ;
tap . test ( 'parses risNotizen correctly' , ( t ) => {
2024-12-08 21:42:57 +00:00
const input = { risNotizen : [ { key : 'FT' , value : 'Staff delayed due to earlier journey' , routeIdxFrom : 0 , routeIdxTo : 12 } ] } ;
2024-12-07 16:16:31 +00:00
const expected = [ {
2024-12-08 21:42:57 +00:00
code : 'FT' ,
summary : 'Staff delayed due to earlier journey' ,
text : 'Staff delayed due to earlier journey' ,
type : 'warning' ,
} ] ;
2024-12-07 16:16:31 +00:00
t . same ( parse ( ctx , input ) , expected ) ;
t . end ( ) ;
} ) ;
tap . test ( 'parses low Prio him himMeldungen correctly' , ( t ) => {
const input = { himMeldungen : [ {
2024-12-08 21:42:57 +00:00
ueberschrift : 'Construction work.' ,
text : 'Advance notice! In the period from 15.12.24 to 17.01.25, construction work will take place' ,
prioritaet : 'NIEDRIG' ,
modDateTime : '2024-12-03T12:52:29' ,
} ] } ;
2024-12-07 16:16:31 +00:00
const expected = [ {
2024-12-08 21:42:57 +00:00
code : undefined ,
summary : 'Construction work.' ,
text : 'Advance notice! In the period from 15.12.24 to 17.01.25, construction work will take place' ,
type : 'status' ,
modified : '2024-12-03T12:52:29+01:00' ,
} ] ;
2024-12-07 16:16:31 +00:00
t . same ( parse ( ctx , input ) , expected ) ;
t . end ( ) ;
} ) ;
tap . test ( 'parses high Prio him himMeldungen correctly' , ( t ) => {
const input = { himMeldungen : [ {
2024-12-08 21:42:57 +00:00
ueberschrift : 'Disruption.' ,
text : 'Switch repairs between Frankfurt(Main)Hbf and Mannheim Hbf delays rail transport.' ,
prioritaet : 'HOCH' ,
modDateTime : '2024-12-05T19:01:48' ,
} ] } ;
2024-12-07 16:16:31 +00:00
const expected = [ {
2024-12-08 21:42:57 +00:00
code : undefined ,
summary : 'Disruption.' ,
text : 'Switch repairs between Frankfurt(Main)Hbf and Mannheim Hbf delays rail transport.' ,
type : 'warning' ,
modified : '2024-12-05T19:01:48+01:00' ,
} ] ;
2024-12-07 16:16:31 +00:00
t . same ( parse ( ctx , input ) , expected ) ;
t . end ( ) ;
} ) ;
tap . test ( 'parses zugattribute correctly' , ( t ) => {
const input = { verkehrsmittel : { zugattribute : [ {
2024-12-08 21:42:57 +00:00
kategorie : 'BEFÖRDERER' ,
key : 'BEF' ,
value : 'DB Fernverkehr AG' ,
} , {
kategorie : 'FAHRRADMITNAHME' ,
key : 'FR' ,
value : 'Bicycles conveyed - subject to reservation' ,
teilstreckenHinweis : '(Mainz Hbf - Mannheim Hbf)' ,
} , {
kategorie : 'INFORMATION' ,
key : 'CK' ,
value : 'Komfort Check-in possible (visit bahn.de/kci for more information)' ,
teilstreckenHinweis : '(Mainz Hbf - Mannheim Hbf)' ,
} ] } } ;
2024-12-07 16:16:31 +00:00
const expected = [ {
2024-12-08 21:42:57 +00:00
// "code": "bicycle-conveyance-reservation",
code : 'FR' ,
// "summary": "bicycles conveyed, subject to reservation",
summary : 'Bicycles conveyed - subject to reservation' ,
text : 'Bicycles conveyed - subject to reservation' ,
type : 'hint' ,
} , {
// "code": "komfort-checkin",
code : 'CK' ,
// "summary": "Komfort-Checkin available",
summary : 'Komfort Check-in possible (visit bahn.de/kci for more information)' ,
text : 'Komfort Check-in possible (visit bahn.de/kci for more information)' ,
type : 'hint' ,
} ] ;
2024-12-07 16:16:31 +00:00
t . same ( parse ( ctx , input ) , expected ) ;
t . end ( ) ;
} ) ;
2024-12-07 22:46:04 +00:00
tap . test ( 'parses board disruptions correctly' , ( t ) => {
2024-12-08 21:42:57 +00:00
const input = { disruptions : [
{
disruptionID : '9aee61d6-700e-3c19-aaa0-019f5612df4c' ,
disruptionCommunicationID : null ,
displayPriority : 25 ,
descriptions : {
DE : {
text : 'Eine Reparatur an einem Signal verzögert den Zugverkehr' ,
textShort : 'Verzögerungen durch Reparatur an einem Signal' ,
} ,
} ,
} ,
] } ;
2024-12-07 22:46:04 +00:00
const expected = [ {
2024-12-08 21:42:57 +00:00
code : undefined ,
summary : 'Verzögerungen durch Reparatur an einem Signal' ,
text : 'Eine Reparatur an einem Signal verzögert den Zugverkehr' ,
type : 'warning' ,
} ] ;
2024-12-07 22:46:04 +00:00
t . same ( parse ( ctx , input ) , expected ) ;
t . end ( ) ;
} ) ;
tap . test ( 'parses board messages correctly' , ( t ) => {
2024-12-08 21:42:57 +00:00
const input = { messages : [
{
code : '80' ,
type : 'QUALITY_VARIATION' ,
displayPriority : null ,
category : null ,
text : 'Andere Reihenfolge der Wagen' ,
textShort : null ,
} ,
] } ;
2024-12-07 22:46:04 +00:00
const expected = [ {
2024-12-08 21:42:57 +00:00
code : 80 ,
summary : 'Andere Reihenfolge der Wagen' ,
text : 'Andere Reihenfolge der Wagen' ,
type : 'status' ,
} ] ;
2024-12-07 22:46:04 +00:00
t . same ( parse ( ctx , input ) , expected ) ;
t . end ( ) ;
} ) ;
tap . test ( 'parses ris attributes correctly' , ( t ) => {
2024-12-08 21:42:57 +00:00
const input = { attributes : [
{
displayPriority : null ,
displayPriorityDetail : null ,
code : 'CK' ,
text : 'Komfort Check-in verfügbar - wenn möglich bitte einchecken' ,
textShort : null ,
} ,
] } ;
2024-12-07 22:46:04 +00:00
const expected = [ {
2024-12-08 21:42:57 +00:00
// "code": "komfort-checkin",
code : 'CK' ,
// "summary": "Komfort-Checkin available",
summary : 'Komfort Check-in verfügbar - wenn möglich bitte einchecken' ,
text : 'Komfort Check-in verfügbar - wenn möglich bitte einchecken' ,
type : 'hint' ,
} ] ;
2024-12-07 22:46:04 +00:00
t . same ( parse ( ctx , input ) , expected ) ;
t . end ( ) ;
2024-12-08 21:42:57 +00:00
} ) ;
2025-01-02 14:00:45 +00:00
tap . test ( 'parses dbnav attributes correctly' , ( t ) => {
const input = {
echtzeitNotizen : [ { text : 'Halt entfällt' } ] ,
himNotizen : [ { text : 'Coach 27 is closed to passengers today.' , prio : 'NORMAL' , ueberschrift : 'Information.' , letzteAktualisierung : '2024-12-16T08:35:53+00:00' } ] ,
attributNotizen : [ { text : 'Komfort Check-in possible (visit bahn.de/kci for more information)' , key : 'CK' , priority : 200 } , { text : 'DB Fernverkehr AG' , key : 'OP' } ] ,
} ;
const expected = [
{
code : undefined ,
summary : 'Halt entfällt' ,
text : 'Halt entfällt' ,
type : 'warning' ,
} ,
{
code : undefined ,
summary : 'Information.' ,
text : 'Coach 27 is closed to passengers today.' ,
modified : '2024-12-16T09:35:53+01:00' ,
type : 'status' ,
} ,
{
code : 'CK' ,
summary : 'Komfort Check-in possible (visit bahn.de/kci for more information)' ,
text : 'Komfort Check-in possible (visit bahn.de/kci for more information)' ,
type : 'hint' ,
} ,
] ;
t . same ( parse ( ctx , input ) , expected ) ;
t . end ( ) ;
} ) ;