Skip to content

Commit

Permalink
Add prior centennial reserve button support
Browse files Browse the repository at this point in the history
  • Loading branch information
villasv committed Aug 18, 2024
1 parent 7a8faaf commit 41ff6cc
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/(aspects)/cycle/packing/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ to SMONEĆTEN via Swartz Bay Road it's about 3 km. The downside of this campsite
is being next to a highway; depending on the campsite position it's possible to
hear traffic noise.

##### Prior Centennial
##### Prior Centennial <ParkReserveLink park={Park.PriorCentennial} />

##### Pender Island

Expand Down
51 changes: 37 additions & 14 deletions projects/outdoors/reservations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum Park {
FortLangleyNHS,
SMONEĆTEN,
PriorCentennial,
}

export enum Org {
Expand All @@ -23,24 +24,24 @@ export enum Category {
BackcountryZone = 7,
}

export enum EquipmentType {
TentOrVehicle = "-32768",
TentsOnly = "-32767",
export enum EquipmentClass {
Frontcountry = "-32768",
Backcountry = "-32767",
}

export enum TentOrVehicleSubtype {
export enum FrontcountryEquip {
SmallTent = "-32768",
MediumTent = "-32767",
LargeTent = "-32766",
VanOrPickup = "-32765",
}

export interface TentOrVehicleSpec {
equipment: EquipmentType.TentOrVehicle;
subtype: TentOrVehicleSubtype[];
export interface FrontcountryEquipSpec {
type: EquipmentClass.Frontcountry;
subtype: FrontcountryEquip[];
}

export type EquipmentSpec = TentOrVehicleSpec;
export type EquipmentSpec = FrontcountryEquipSpec;

export interface ParkInfo {
org: Org;
Expand Down Expand Up @@ -68,7 +69,8 @@ export function getReservationUrl({
checkOutDate,
searchTime,
}: ParkReserveParams): string {
const { org, group, category, mapId, resourceLocationId } = getParkInfo(park);
const { org, group, category, mapId, resourceLocationId, equipment } =
getParkInfo(park);
const url = new URL(baseUrl(org));
url.searchParams.set("searchTabGroupId", group.toString());
url.searchParams.set("bookingCategoryId", category.toString());
Expand All @@ -93,7 +95,14 @@ export function getReservationUrl({
(searchTime ?? new Date()).toLocaleString("sv").replace(" ", "T")
);
url.searchParams.set("flexibleSearch", "[false,false,null,1]"); // TODO how to use this?
url.searchParams.set("filterData", '{"-32756":"[[1],0,0,0]"}'); // TODO how to use this?

if (equipment) {
url.searchParams.set("equipmentId", equipment.type);
url.searchParams.set("subEquipmentId", equipment.subtype[0]);
url.searchParams.set("filterData", "{}");
} else {
url.searchParams.set("filterData", '{"-32756":"[[1],0,0,0]"}'); // TODO how to use this?
}
return url.toString();
}

Expand All @@ -106,6 +115,15 @@ function baseUrl(org: Org): string {
}
}

const _defaultEquipSpec: EquipmentSpec = {
type: EquipmentClass.Frontcountry,
subtype: [
FrontcountryEquip.SmallTent,
FrontcountryEquip.MediumTent,
FrontcountryEquip.LargeTent,
],
};

const PARKS: Record<Park, ParkInfo> = {
[Park.FortLangleyNHS]: {
org: Org.ParksCanada,
Expand All @@ -120,10 +138,15 @@ const PARKS: Record<Park, ParkInfo> = {
category: Category.Campsite,
mapId: "-2147483477",
resourceLocationId: "-2147483601",
equipment: {
equipment: EquipmentType.TentOrVehicle,
subtype: [TentOrVehicleSubtype.SmallTent],
},
equipment: _defaultEquipSpec,
},
[Park.PriorCentennial]: {
org: Org.ParksCanada,
group: Group.Frontcountry,
category: Category.Campsite,
mapId: "-2147483475",
resourceLocationId: "-2147483600",
equipment: _defaultEquipSpec,
},
};

Expand Down
22 changes: 21 additions & 1 deletion projects/outdoors/reserve-link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,28 @@ describe(getReservationUrl.name, () => {
"&mapId=-2147483477",
"&resourceLocationId=-2147483601",
...defaultParams,
"&filterData=%7B%7D&equipmentId=-32768",
"&equipmentId=-32768", // tent or vehicle
"&subEquipmentId=-32768", // small tent
"&filterData=%7B%7D", // no filter
].join("");
expect(url).toBe(expectedUrl);
});

it("should work for Prior Centennial", () => {
const url = getReservationUrl({
park: Park.PriorCentennial,
...defaultArgs,
});
const expectedUrl = [
"https://reservation.pc.gc.ca/create-booking/results",
"?searchTabGroupId=0",
"&bookingCategoryId=0",
"&mapId=-2147483475",
"&resourceLocationId=-2147483600",
...defaultParams,
"&equipmentId=-32768",
"&subEquipmentId=-32768",
"&filterData=%7B%7D",
].join("");
expect(url).toBe(expectedUrl);
});
Expand Down

0 comments on commit 41ff6cc

Please sign in to comment.