Skip to content

Commit

Permalink
Added DHID and DLID
Browse files Browse the repository at this point in the history
  • Loading branch information
justusjonas74 committed Nov 21, 2023
1 parent 23301c0 commit 3759b48
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/dvbjs/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export interface IStop extends ILocation {
platform?: IPlatform;
arrival: Date;
departure: Date;
dhid: string;
}

export interface IStopLocation extends ILocation {
Expand All @@ -114,6 +115,7 @@ export interface INode {
line: string;
direction: string;
diva?: IDiva;
dlid?: string;
duration: number;
path: coord[];
}
Expand Down
2 changes: 2 additions & 0 deletions packages/dvbjs/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ export function parsePoiID(id: string): { id: string; type: POI_TYPE } {
function extractStop(stop: any): IStop {
return {
id: stop.DataId,
dhid: stop.DhId,
name: stop.Name.trim(),
city: stop.Place,
type: stop.Type,
Expand Down Expand Up @@ -461,6 +462,7 @@ function extractNode(node: any, mapData: any): INode {
line: node.Mot.Name ? node.Mot.Name : "",
direction: node.Mot.Direction ? node.Mot.Direction.trim() : "",
diva: parseDiva(node.Mot.Diva),
dlid: node.Mot.DlId,
duration: node.Duration || 1,
path: convertCoordinates(mapData[node.MapDataIndex]),
};
Expand Down
32 changes: 31 additions & 1 deletion packages/dvbjs/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint @typescript-eslint/no-non-null-assertion: 0 */

import axios from "axios";
import chai, { assert } from "chai";
import chai, { assert, expect } from "chai";
import chaiAsPromised from "chai-as-promised";
import * as dvb from "../src/index";
import { IRoute, IStop } from "../src/index";
Expand Down Expand Up @@ -113,7 +113,37 @@ describe("dvb.route", () => {
assert.notEqual(0, durationSum);
});
});

it("all stops should have all prperties", ()=>{
const stops = data.trips.flatMap((trip)=>{
return trip.nodes.flatMap((node) => {
return node.stops
})
})
stops.forEach(stop => {
assert.property(stop,'id')
assert.property(stop,'dhid')
assert.property(stop,'name')
assert.property(stop,'city')
assert.property(stop,'type')
assert.property(stop,'platform')
assert.property(stop,'coords')
assert.property(stop,'arrival')
assert.property(stop,'departure')
expect(stop.dhid).not.to.be.empty
})
})

it("all nodes except footpaths should have prperty 'dlid' ", ()=>{
const nodes = data.trips.flatMap((trip)=>{
return trip.nodes
}).filter(node => node.mode && node.mode.name !== 'Footpath')
nodes.forEach(node=>{
expect(node.dlid).to.exist.and.to.be.an('string')
})
})
});

describe('dvb.route "33000742 (Helmholtzstraße) --> via: 33000016 (Bahnhof Neustadt) --> 33000037 (Postplatz Dresden)"', () => {
let data: dvb.IRoute;

Expand Down

0 comments on commit 3759b48

Please sign in to comment.