@opentripplanner/core-utils 14.2.4 → 14.3.1
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/esm/__tests__/__mocks__/three-transfer-itinerary.json +2195 -0
- package/esm/itinerary.js +20 -25
- package/esm/itinerary.js.map +1 -1
- package/esm/otpSchema.json +17765 -14884
- package/esm/planQuery.graphql +1 -3
- package/esm/query-gen.js +1 -1
- package/esm/query-gen.js.map +1 -1
- package/esm/three-transfer-itinerary.json +2195 -0
- package/lib/__tests__/__mocks__/three-transfer-itinerary.json +2195 -0
- package/lib/index.js +13 -42
- package/lib/index.js.map +1 -1
- package/lib/itinerary.d.ts.map +1 -1
- package/lib/itinerary.js +75 -134
- package/lib/itinerary.js.map +1 -1
- package/lib/map.js +11 -25
- package/lib/map.js.map +1 -1
- package/lib/otpSchema.json +17765 -14884
- package/lib/planQuery.graphql +1 -3
- package/lib/query-gen.js +12 -21
- package/lib/query-gen.js.map +1 -1
- package/lib/route.d.ts.map +1 -1
- package/lib/route.js +26 -44
- package/lib/route.js.map +1 -1
- package/lib/storage.js +4 -11
- package/lib/storage.js.map +1 -1
- package/lib/suspense.d.ts.map +1 -1
- package/lib/suspense.js +3 -28
- package/lib/suspense.js.map +1 -1
- package/lib/time.d.ts.map +1 -1
- package/lib/time.js +20 -33
- package/lib/time.js.map +1 -1
- package/lib/ui.js +2 -7
- package/lib/ui.js.map +1 -1
- package/package.json +2 -2
- package/src/__snapshots__/core-utils.story.tsx.snap +1 -1
- package/src/__tests__/__mocks__/three-transfer-itinerary.json +2195 -0
- package/src/__tests__/itinerary.ts +9 -0
- package/src/itinerary.ts +21 -21
- package/src/otpSchema.json +17765 -14884
- package/src/planQuery.graphql +1 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -18,6 +18,7 @@ import bikeRentalItinerary from "./__mocks__/bike-rental-itinerary.json";
|
|
|
18
18
|
import tncItinerary from "./__mocks__/tnc-itinerary.json";
|
|
19
19
|
import fareProductItinerary from "./__mocks__/fare-products-itinerary.json";
|
|
20
20
|
import complexItinerary from "./__mocks__/complex-fares.json";
|
|
21
|
+
import tripleItinerary from "./__mocks__/three-transfer-itinerary.json";
|
|
21
22
|
import flexItinerary from "../../../itinerary-body/src/__mocks__/itineraries/flex-itinerary.json";
|
|
22
23
|
import faresv2Itinerary from "../../../itinerary-body/src/__mocks__/itineraries/fares-v2-fare-components.json";
|
|
23
24
|
|
|
@@ -267,6 +268,14 @@ describe("util > itinerary", () => {
|
|
|
267
268
|
const result = getItineraryCost(complexItinerary.legs, "0", "ADULT");
|
|
268
269
|
expect(result.amount).toEqual(3.0);
|
|
269
270
|
});
|
|
271
|
+
it("should calculate the total cost of an itinerary with three different fares v2 transfers with different rider categories", () => {
|
|
272
|
+
const result = getItineraryCost(
|
|
273
|
+
tripleItinerary.legs,
|
|
274
|
+
["0", "0"],
|
|
275
|
+
["ADULT", null]
|
|
276
|
+
);
|
|
277
|
+
expect(result.amount).toEqual(11.55);
|
|
278
|
+
});
|
|
270
279
|
it("should calculate the individual leg cost of a fares v2 legs", () => {
|
|
271
280
|
const firstLegResult = getLegCost(faresv2Itinerary.legs[1], "3", "ADULT");
|
|
272
281
|
expect(firstLegResult.price?.amount).toEqual(2);
|
package/src/itinerary.ts
CHANGED
|
@@ -735,31 +735,31 @@ export function getItineraryCost(
|
|
|
735
735
|
return total;
|
|
736
736
|
}
|
|
737
737
|
|
|
738
|
-
const
|
|
738
|
+
const legCosts = legs
|
|
739
739
|
// Only legs with fares (no walking legs)
|
|
740
740
|
.filter(leg => leg.fareProducts?.length > 0)
|
|
741
741
|
// Get the leg cost object of each leg
|
|
742
|
-
.
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
//
|
|
748
|
-
|
|
749
|
-
|
|
742
|
+
.reduce<{ seenIds: string[]; legCosts: AppliedFareProduct[] }>(
|
|
743
|
+
(acc, leg) => {
|
|
744
|
+
// getLegCost handles filtering out duplicate use IDs
|
|
745
|
+
// One fare product can be used on multiple legs,
|
|
746
|
+
// and we don't want to count it more than once.
|
|
747
|
+
// Use an object keyed by productUseId to deduplicate, then extract prices
|
|
748
|
+
const { appliedFareProduct, productUseId } = getLegCost(
|
|
749
|
+
leg,
|
|
750
|
+
mediumId,
|
|
751
|
+
riderCategoryId,
|
|
752
|
+
acc.seenIds
|
|
753
|
+
);
|
|
754
|
+
if (!appliedFareProduct) return acc;
|
|
755
|
+
return {
|
|
756
|
+
legCosts: [...acc.legCosts, appliedFareProduct],
|
|
757
|
+
seenIds: [...acc.seenIds, productUseId]
|
|
758
|
+
};
|
|
759
|
+
},
|
|
760
|
+
{ seenIds: [], legCosts: [] }
|
|
750
761
|
)
|
|
751
|
-
.
|
|
752
|
-
// Filter out duplicate use IDs
|
|
753
|
-
// One fare product can be used on multiple legs,
|
|
754
|
-
// and we don't want to count it more than once.
|
|
755
|
-
// Use an object keyed by productUseId to deduplicate, then extract prices
|
|
756
|
-
.reduce<{ [productUseId: string]: Money }>((acc, cur) => {
|
|
757
|
-
if (cur.productUseId && acc[cur.productUseId] === undefined) {
|
|
758
|
-
acc[cur.productUseId] = cur.appliedFareProduct?.legPrice;
|
|
759
|
-
}
|
|
760
|
-
return acc;
|
|
761
|
-
}, {});
|
|
762
|
-
const legCosts = Object.values(legCostsObj);
|
|
762
|
+
.legCosts.map(lc => lc.legPrice);
|
|
763
763
|
|
|
764
764
|
if (legCosts.length === 0) return undefined;
|
|
765
765
|
// Calculate the total
|