Skip to content

Commit

Permalink
fix(core-utils): Add helper func getLegRouteLongName.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Aug 22, 2023
1 parent 62806ca commit 6c3bc38
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 19 additions & 2 deletions packages/core-utils/src/__tests__/itinerary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getDisplayedStopId,
getItineraryCost,
getLegCost,
getLegRouteLongName,
getLegRouteShortName,
isTransit
} from "../itinerary";
Expand Down Expand Up @@ -182,14 +183,14 @@ describe("util > itinerary", () => {
});
});
describe("getLegRouteShortName", () => {
it("should extract a route number from an OTP1 leg", () => {
it("should extract a route short name from an OTP1 leg", () => {
expect(getLegRouteShortName({ route: "15" })).toBe("15");
expect(getLegRouteShortName({ route: "15", routeShortName: "31" })).toBe(
"31"
);
});

it("should extract a route number from an OTP2 leg", () => {
it("should extract a route short name from an OTP2 leg", () => {
expect(
getLegRouteShortName({
route: { id: "id15", shortName: "15" },
Expand All @@ -198,4 +199,20 @@ describe("util > itinerary", () => {
).toBe("15");
});
});
describe("getLegRouteLongName", () => {
it("should extract a route long name from an OTP1 leg", () => {
expect(getLegRouteLongName({ route: "15" })).toBeUndefined();
expect(
getLegRouteLongName({ route: "15", routeLongName: "Candler Road" })
).toBe("Candler Road");
});
it("should extract a route long name from an OTP2 leg", () => {
expect(
getLegRouteLongName({
route: { id: "id15", longName: "15" },
routeLongName: "31"
})
).toBe("15");
});
});
});
8 changes: 8 additions & 0 deletions packages/core-utils/src/itinerary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,3 +692,11 @@ export const getLegRouteShortName = (
}
return route?.shortName;
};

/** Extract the route ling name for a leg returned from OTP1 or OTP2. */
export const getLegRouteLongName = (
leg: Pick<Leg, "route" | "routeLongName">
): string => {
const { route, routeLongName } = leg;
return typeof route === "string" ? routeLongName : route?.longName;
};

0 comments on commit 6c3bc38

Please sign in to comment.