Skip to content

Commit

Permalink
Merge branch 'master' into otp2-fare-products-table
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-heppner-ibigroup committed Jul 3, 2023
2 parents d5f1340 + 423dbd6 commit 118d5fe
Show file tree
Hide file tree
Showing 38 changed files with 10,272 additions and 20,662 deletions.
24,884 changes: 8,915 additions & 15,969 deletions __snapshots__/storybook.test.ts.snap

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/core-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/core-utils",
"version": "8.2.4",
"version": "8.3.2",
"description": "Core functionality that is shared among numerous UI components",
"engines": {
"node": ">=13"
Expand Down
52 changes: 34 additions & 18 deletions packages/core-utils/src/__tests__/__mocks__/tnc-itinerary.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,23 @@
"rentedCar": false,
"rentedVehicle": false,
"hailedCar": true,
"tncData": {
"company": "UBER",
"currency": "USD",
"travelDuration": 300,
"maxCost": 10,
"minCost": 9,
"productId": "a6eef2e1-c99a-436f-bde9-fefb9181c0b0",
"displayName": "UberX",
"estimatedArrival": 240
"rideHailingEstimate": {
"provider": {
"id": "uber"
},
"arrival": "PT4M",
"minPrice": {
"currency": {
"code": "USD"
},
"amount": 17
},
"maxPrice": {
"currency": {
"code": "USD"
},
"amount": 19
}
},
"duration": 180,
"transitLeg": false,
Expand Down Expand Up @@ -1045,15 +1053,23 @@
"rentedCar": false,
"rentedVehicle": false,
"hailedCar": true,
"tncData": {
"company": "UBER",
"currency": "USD",
"travelDuration": 300,
"maxCost": 9,
"minCost": 8,
"productId": "a6eef2e1-c99a-436f-bde9-fefb9181c0b0",
"displayName": "UberX",
"estimatedArrival": 240
"rideHailingEstimate": {
"provider": {
"id": "uber"
},
"arrival": "PT4M",
"minPrice": {
"currency": {
"code": "USD"
},
"amount": 17
},
"maxPrice": {
"currency": {
"code": "USD"
},
"amount": 19
}
},
"duration": 341,
"transitLeg": false,
Expand Down
6 changes: 3 additions & 3 deletions packages/core-utils/src/__tests__/itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ describe("util > itinerary", () => {

it("should return company for TNC leg", () => {
const company = getCompanyFromLeg(tncItinerary.legs[0]);
expect(company).toEqual("UBER");
expect(company).toEqual("uber");
});
});

describe("calculateTncFares", () => {
it("should return the correct amounts and currency for an itinerary with TNC", () => {
const fareResult = calculateTncFares(tncItinerary, true);
expect(fareResult.currencyCode).toEqual("USD");
expect(fareResult.maxTNCFare).toEqual(19);
expect(fareResult.minTNCFare).toEqual(17);
expect(fareResult.maxTNCFare).toEqual(38);
expect(fareResult.minTNCFare).toEqual(34);
});
});

Expand Down
32 changes: 23 additions & 9 deletions packages/core-utils/src/itinerary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {
return isAdvanceBookingRequired(leg.dropOffBookingInfo);
}

export function isRideshareLeg(leg: Leg): boolean {
return !!leg.rideHailingEstimate?.provider?.id;
}

export function isWalk(mode: string): boolean {
if (!mode) return false;

Expand Down Expand Up @@ -193,16 +197,26 @@ export function toSentenceCase(str: string): string {
*/
export function getCompanyFromLeg(leg: Leg): string {
if (!leg) return null;
const { from, mode, rentedBike, rentedCar, rentedVehicle, tncData } = leg;
const {
from,
mode,
rentedBike,
rentedCar,
rentedVehicle,
rideHailingEstimate
} = leg;
if (mode === "CAR" && rentedCar) {
return from.networks[0];
}
if (mode === "CAR" && tncData) {
return tncData.company;
if (mode === "CAR" && rideHailingEstimate) {
return rideHailingEstimate.provider.id;
}
if (mode === "BICYCLE" && rentedBike && from.networks) {
return from.networks[0];
}
if (from.rentalVehicle) {
return from.rentalVehicle.network;
}
if (
(mode === "MICROMOBILITY" || mode === "SCOOTER") &&
rentedVehicle &&
Expand Down Expand Up @@ -440,15 +454,15 @@ export function calculateTncFares(
itinerary: ItineraryOnlyLegsRequired
): TncFare {
return itinerary.legs
.filter(leg => leg.mode === "CAR" && leg.hailedCar && leg.tncData)
.filter(leg => leg.mode === "CAR" && leg.rideHailingEstimate)
.reduce(
({ maxTNCFare, minTNCFare }, { tncData }) => {
const { currency, maxCost, minCost } = tncData;
({ maxTNCFare, minTNCFare }, { rideHailingEstimate }) => {
const { minPrice, maxPrice } = rideHailingEstimate;
return {
// Assumes a single currency for entire itinerary.
currencyCode: currency,
maxTNCFare: maxTNCFare + maxCost,
minTNCFare: minTNCFare + minCost
currencyCode: minPrice.currency.code,
maxTNCFare: maxTNCFare + maxPrice.amount,
minTNCFare: minTNCFare + minPrice.amount
};
},
{
Expand Down
Loading

0 comments on commit 118d5fe

Please sign in to comment.