@wemap/routers 11.8.4 → 11.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/routers"
13
13
  },
14
14
  "name": "@wemap/routers",
15
- "version": "11.8.4",
15
+ "version": "11.8.6",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -52,5 +52,5 @@
52
52
  },
53
53
  "./helpers/*": "./helpers/*"
54
54
  },
55
- "gitHead": "07f877af0625c2fe518bb6af00cb5a404beea908"
55
+ "gitHead": "85ecb346b13f810d6ab917c2be5c890991281f59"
56
56
  }
@@ -12,7 +12,7 @@ import { StepsGenerationRules } from './generateSteps.js';
12
12
  import { getDurationFromLength } from '../Utils.js';
13
13
 
14
14
 
15
- export type ItineraryMode = 'PT' | 'CAR' | 'BIKE' | 'WALK';
15
+ export type ItineraryMode = 'MULTI' | 'CAR' | 'BIKE' | 'WALK';
16
16
 
17
17
  export type ItineraryCommon = {
18
18
  startTime?: number,
@@ -111,7 +111,7 @@ export default class Itinerary {
111
111
  });
112
112
 
113
113
  if (isPublicTransport) {
114
- this._mode = 'PT';
114
+ this._mode = 'MULTI';
115
115
  } else if (isDriving) {
116
116
  this._mode = 'CAR';
117
117
  } else if (isBicycle) {
@@ -36,7 +36,7 @@ describe('CitywayRemoteRouter - createRouterResponseFromJson', () => {
36
36
  const itinerary1 = routerResponse.itineraries[0];
37
37
  expect(itinerary1.distance).to.be.closeTo(6887, 1);
38
38
  expect(itinerary1.duration).equal(2379);
39
- expect(itinerary1.mode).equal('PT');
39
+ expect(itinerary1.mode).equal('MULTI');
40
40
  // Do not work because of the input time format
41
41
  expect(itinerary1.startTime).equal(1620659156000);
42
42
  expect(itinerary1.endTime).equal(1620661535000);
@@ -85,7 +85,7 @@ describe('CitywayRemoteRouter - createRouterResponseFromJson', () => {
85
85
  const routerResponse = CitywayRemoteRouter.createRouterResponseFromJson(json, fakeCoords, fakeCoords);
86
86
  routerResponse.itineraries.forEach(verifyStepsCoherence);
87
87
 
88
- expect(routerResponse.itineraries[0].mode).equal('PT');
88
+ expect(routerResponse.itineraries[0].mode).equal('MULTI');
89
89
  expect(routerResponse.itineraries[0].legs[1].mode).equal('FUNICULAR');
90
90
  });
91
91
 
@@ -109,7 +109,7 @@ describe('CitywayRemoteRouter - createRouterResponseFromJson', () => {
109
109
  const routerResponse = CitywayRemoteRouter.createRouterResponseFromJson(json, fakeCoords, fakeCoords);
110
110
  routerResponse.itineraries.forEach(verifyStepsCoherence);
111
111
 
112
- expect(routerResponse.itineraries[1].mode).equal('PT');
112
+ expect(routerResponse.itineraries[1].mode).equal('MULTI');
113
113
  expect(routerResponse.itineraries[1].legs[1].mode).equal('TRAM');
114
114
  expect(routerResponse.itineraries[1].legs[1].transportInfo?.name).equal('B');
115
115
  });
@@ -35,7 +35,7 @@ describe('IdfmRouter - createRouterResponseFromJson', () => {
35
35
  expect(itinerary1.to.equals(new Coordinates(48.877877, 2.351929))).true;
36
36
  expect(itinerary1.distance).to.be.closeTo(5264, 1);
37
37
  expect(itinerary1.duration).equal(1842);
38
- expect(itinerary1.mode).equal('PT');
38
+ expect(itinerary1.mode).equal('MULTI');
39
39
  // Do not work because of the input time format
40
40
  expect(itinerary1.startTime).equal(1637596640000);
41
41
  expect(itinerary1.endTime).equal(1637598482000);
@@ -54,6 +54,9 @@ type IdfmJson = {
54
54
  }[],
55
55
  context: {
56
56
  timezone: string
57
+ };
58
+ error: {
59
+ message?: string;
57
60
  }
58
61
  };
59
62
 
@@ -172,7 +175,7 @@ class IdfmRemoteRouter extends RemoteRouter {
172
175
  }));
173
176
 
174
177
 
175
- const jsonResponse = await res.json().catch(() => {
178
+ const jsonResponse: IdfmJson = await res.json().catch(() => {
176
179
  throw new RemoteRouterServerUnreachable(this.rname, url);
177
180
  });
178
181
 
@@ -188,7 +191,20 @@ class IdfmRemoteRouter extends RemoteRouter {
188
191
  });
189
192
  }
190
193
 
191
- return this.createRouterResponseFromJson(jsonResponse, waypoints[0], waypoints[1]);
194
+ const routerResponse = this.createRouterResponseFromJson(jsonResponse, waypoints[0], waypoints[1]);
195
+
196
+ const sameModeFound = routerResponse.itineraries.some((itinerary) => itinerary.mode === mode);
197
+
198
+ if (!sameModeFound) {
199
+ return new RouterResponse({
200
+ routerName: this.rname,
201
+ from: waypoints[0],
202
+ to: waypoints[1],
203
+ error: 'Selected mode of transport was not found for this itinerary.'
204
+ });
205
+ }
206
+
207
+ return routerResponse;
192
208
  }
193
209
 
194
210
  getURL(endpointUrl: string, mode: RoutingMode, waypoints: Coordinates[], options: RemoteRouterOptions) {
@@ -41,7 +41,7 @@ describe('OtpRouter - createRouterResponseFromJson', () => {
41
41
  expect(itinerary1.startTime).equal(1614607210000);
42
42
  expect(itinerary1.endTime).equal(1614608416000);
43
43
  expect(itinerary1.legs.length).equal(3);
44
- expect(itinerary1.mode).equal('PT');
44
+ expect(itinerary1.mode).equal('MULTI');
45
45
 
46
46
  const itinerary1leg1 = itinerary1.legs[0];
47
47
  expect(itinerary1leg1.startTime).equal(1614607210000);
@@ -83,7 +83,7 @@ describe('OtpRouter - createRouterResponseFromJson', () => {
83
83
  expect(itinerary1.to.equals(new Coordinates(45.18544, 5.73123))).true;
84
84
  expect(itinerary1.legs.length).equal(5);
85
85
 
86
- expect(itinerary1.mode).equal('PT');
86
+ expect(itinerary1.mode).equal('MULTI');
87
87
 
88
88
  expect(itinerary1.legs[0].mode).equal('WALK');
89
89