@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.
Files changed (41) hide show
  1. package/esm/__tests__/__mocks__/three-transfer-itinerary.json +2195 -0
  2. package/esm/itinerary.js +20 -25
  3. package/esm/itinerary.js.map +1 -1
  4. package/esm/otpSchema.json +17765 -14884
  5. package/esm/planQuery.graphql +1 -3
  6. package/esm/query-gen.js +1 -1
  7. package/esm/query-gen.js.map +1 -1
  8. package/esm/three-transfer-itinerary.json +2195 -0
  9. package/lib/__tests__/__mocks__/three-transfer-itinerary.json +2195 -0
  10. package/lib/index.js +13 -42
  11. package/lib/index.js.map +1 -1
  12. package/lib/itinerary.d.ts.map +1 -1
  13. package/lib/itinerary.js +75 -134
  14. package/lib/itinerary.js.map +1 -1
  15. package/lib/map.js +11 -25
  16. package/lib/map.js.map +1 -1
  17. package/lib/otpSchema.json +17765 -14884
  18. package/lib/planQuery.graphql +1 -3
  19. package/lib/query-gen.js +12 -21
  20. package/lib/query-gen.js.map +1 -1
  21. package/lib/route.d.ts.map +1 -1
  22. package/lib/route.js +26 -44
  23. package/lib/route.js.map +1 -1
  24. package/lib/storage.js +4 -11
  25. package/lib/storage.js.map +1 -1
  26. package/lib/suspense.d.ts.map +1 -1
  27. package/lib/suspense.js +3 -28
  28. package/lib/suspense.js.map +1 -1
  29. package/lib/time.d.ts.map +1 -1
  30. package/lib/time.js +20 -33
  31. package/lib/time.js.map +1 -1
  32. package/lib/ui.js +2 -7
  33. package/lib/ui.js.map +1 -1
  34. package/package.json +2 -2
  35. package/src/__snapshots__/core-utils.story.tsx.snap +1 -1
  36. package/src/__tests__/__mocks__/three-transfer-itinerary.json +2195 -0
  37. package/src/__tests__/itinerary.ts +9 -0
  38. package/src/itinerary.ts +21 -21
  39. package/src/otpSchema.json +17765 -14884
  40. package/src/planQuery.graphql +1 -3
  41. 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 legCostsObj = legs
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
- .map((leg, index, arr) =>
743
- getLegCost(
744
- leg,
745
- mediumId,
746
- riderCategoryId,
747
- // We need to include the seen fare ids by gathering all previous leg fare product ids
748
- arr.splice(0, index).flatMap(l => l?.fareProducts.map(fp => fp?.id))
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
- .filter(cost => cost.appliedFareProduct?.legPrice !== undefined)
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