@opentripplanner/core-utils 9.0.0-alpha.30 → 9.0.0-alpha.32
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/itinerary.js +50 -0
- package/esm/itinerary.js.map +1 -1
- package/esm/profile.js +1 -1
- package/esm/profile.js.map +1 -1
- package/esm/query-gen.js +1 -1
- package/lib/itinerary.d.ts +1 -0
- package/lib/itinerary.d.ts.map +1 -1
- package/lib/itinerary.js +53 -1
- package/lib/itinerary.js.map +1 -1
- package/lib/profile.js +1 -1
- package/lib/profile.js.map +1 -1
- package/lib/query-gen.js +1 -1
- package/package.json +1 -1
- package/src/__tests__/__mocks__/fare-products-itinerary.json +1283 -0
- package/src/__tests__/itinerary.js +52 -0
- package/src/itinerary.ts +45 -0
- package/src/otpSchema.json +666 -2825
- package/src/planQuery.graphql +14 -2
- package/src/profile.js +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
calculateTncFares,
|
|
3
3
|
getCompanyFromLeg,
|
|
4
4
|
getDisplayedStopId,
|
|
5
|
+
getLegCost,
|
|
5
6
|
isTransit
|
|
6
7
|
} from "../itinerary";
|
|
7
8
|
|
|
@@ -86,4 +87,55 @@ describe("util > itinerary", () => {
|
|
|
86
87
|
expect(getDisplayedStopId(basePlace)).toBeFalsy();
|
|
87
88
|
});
|
|
88
89
|
});
|
|
90
|
+
|
|
91
|
+
describe("getLegCost", () => {
|
|
92
|
+
it("should return the total cost for a leg", () => {
|
|
93
|
+
const leg = {
|
|
94
|
+
fareProducts: [
|
|
95
|
+
{
|
|
96
|
+
product: {
|
|
97
|
+
medium: { id: "cash" },
|
|
98
|
+
riderCategory: { id: "regular" },
|
|
99
|
+
name: "rideCost",
|
|
100
|
+
price: { amount: 200, currency: "USD" }
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
};
|
|
105
|
+
const result = getLegCost(leg, "cash", "regular");
|
|
106
|
+
expect(result.price).toEqual({ amount: 200, currency: "USD" });
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("should return the transfer discount amount if a transfer was used", () => {
|
|
110
|
+
const leg = {
|
|
111
|
+
fareProducts: [
|
|
112
|
+
{
|
|
113
|
+
product: {
|
|
114
|
+
medium: { id: "cash" },
|
|
115
|
+
riderCategory: { id: "regular" },
|
|
116
|
+
name: "rideCost",
|
|
117
|
+
price: { amount: 200, currency: "USD" }
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
product: {
|
|
122
|
+
name: "transfer",
|
|
123
|
+
price: { amount: 50, currency: "USD" },
|
|
124
|
+
medium: { id: "cash" },
|
|
125
|
+
riderCategory: { id: "regular" }
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
};
|
|
130
|
+
const result = getLegCost(leg, "cash", "regular");
|
|
131
|
+
expect(result.price).toEqual({ amount: 200, currency: "USD" });
|
|
132
|
+
expect(result.transferAmount).toEqual({ amount: 50, currency: "USD" });
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("should return undefined if no fare products exist on the leg", () => {
|
|
136
|
+
const leg = {};
|
|
137
|
+
const result = getLegCost(leg, "cash", "regular");
|
|
138
|
+
expect(result.price).toBeUndefined();
|
|
139
|
+
});
|
|
140
|
+
});
|
|
89
141
|
});
|
package/src/itinerary.ts
CHANGED
|
@@ -614,3 +614,48 @@ export function getItineraryCost(
|
|
|
614
614
|
{ amount: 0, currency: null }
|
|
615
615
|
);
|
|
616
616
|
}
|
|
617
|
+
|
|
618
|
+
const pickupDropoffTypeToOtp1 = otp2Type => {
|
|
619
|
+
switch (otp2Type) {
|
|
620
|
+
case "COORDINATE_WITH_DRIVER":
|
|
621
|
+
return "coordinateWithDriver";
|
|
622
|
+
case "CALL_AGENCY":
|
|
623
|
+
return "mustPhone";
|
|
624
|
+
case "SCHEDULED":
|
|
625
|
+
return "scheduled";
|
|
626
|
+
case "NONE":
|
|
627
|
+
return "none";
|
|
628
|
+
default:
|
|
629
|
+
return null;
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
export const convertGraphQLResponseToLegacy = (leg: any): any => ({
|
|
634
|
+
...leg,
|
|
635
|
+
agencyBrandingUrl: leg.agency?.url,
|
|
636
|
+
agencyName: leg.agency?.name,
|
|
637
|
+
agencyUrl: leg.agency?.url,
|
|
638
|
+
alightRule: pickupDropoffTypeToOtp1(leg.dropoffType),
|
|
639
|
+
boardRule: pickupDropoffTypeToOtp1(leg.pickupType),
|
|
640
|
+
dropOffBookingInfo: {
|
|
641
|
+
latestBookingTime: leg.dropOffBookingInfo
|
|
642
|
+
},
|
|
643
|
+
from: {
|
|
644
|
+
...leg.from,
|
|
645
|
+
stopCode: leg.from.stop?.code,
|
|
646
|
+
stopId: leg.from.stop?.gtfsId
|
|
647
|
+
},
|
|
648
|
+
route: leg.route?.shortName,
|
|
649
|
+
routeColor: leg.route?.color,
|
|
650
|
+
routeId: leg.route?.id,
|
|
651
|
+
routeLongName: leg.route?.longName,
|
|
652
|
+
routeShortName: leg.route?.shortName,
|
|
653
|
+
routeTextColor: leg.route?.textColor,
|
|
654
|
+
to: {
|
|
655
|
+
...leg.to,
|
|
656
|
+
stopCode: leg.to.stop?.code,
|
|
657
|
+
stopId: leg.to.stop?.gtfsId
|
|
658
|
+
},
|
|
659
|
+
tripHeadsign: leg.trip?.tripHeadsign,
|
|
660
|
+
tripId: leg.trip?.gtfsId
|
|
661
|
+
});
|