fix: Enable feature for embeds when 100 pc is set (#20003)

* Enable feature for embeds when 100 pc is set

* Dont consider reserved status for quick availability check
This commit is contained in:
Hariom Balhara authored and GitHub committed 2025-03-13 17:16:43 +05:30
1 parent 837349e3d3
commit 209a401113
4 files changed
+17 -2

No files matched your search

@@ -81,9 +81,10 @@ describe("isVisitorWithinPercentage", () => {
});
// Test for fallback to random behavior when no UUID is provided
it("should not enable feature when UUID is notavailable", () => {
it("should not enable feature when UUID is not available unless the feature is 100% enabled", () => {
mockGetCookie({ expectedUid: undefined });
expect(isVisitorWithinPercentage({ percentage: 50 })).toBe(false);
expect(isVisitorWithinPercentage({ percentage: 100 })).toBe(true);
});
it("should disable the feature when percentage is 0", () => {
@@ -8,6 +8,12 @@ export const isVisitorWithinPercentage = ({ percentage }: { percentage: number }
if (process.env.NEXT_PUBLIC_IS_E2E) {
return true;
}
// Because uid cookie is known to be not accessible in third party context inside embed(in some cases), we could just return true if the feature is 100% enabled
// It ensures that when the feature is 100% enabled, it is enabled in embeds too
if (percentage >= 100) {
return true;
}
// TODO: The cookie is currently set when a timeslot is selected but we plan to create it on visitor's visit itself
// Current purpose is to identify the visitor who reserved a timeslot but could be used for feature rollout and other UX improvements(like if duplicate booking is attempted by the same person)
const visitorId = getCookie("uid");
@@ -55,7 +55,14 @@ export const isAvailableHandler = async ({
if (isReserved) {
return {
...slot,
status: "reserved" as const,
// Consider reserved slots as available till we fix issues with reserved slots
// 1. Reservation must be attempted only if the cookie is set. reservation endpoint shouldn't create the cookie itself. It should skip reservation if there is no cookie in request
// 2. We could consider reducing the reservation time.
// 3. There could still be a problem that if multiple people on the same booking page try to book the same slot only one would be successful and other would be not and when they try to select some other slot, similarly only one would be successful and rest won't.
// This could cause frustration for users because they would see the slot as available but when they try to book it, it is not available(Note we fetch the status of the selected slot only). This would be most common for first available slot
// Maybe we want to reserve the slot when confirm button is clicked because in cases where it takes long time to book, it could disable the confirm button earlier.
status: "available" as const,
realStatus: "reserved" as const,
};
}
@@ -18,6 +18,7 @@ export const ZIsAvailableOutputSchema = z.object({
utcStartIso: z.string(),
utcEndIso: z.string(),
status: z.enum(["available", "reserved", "minBookNoticeViolation", "slotInPast"]),
realStatus: z.enum(["available", "reserved", "minBookNoticeViolation", "slotInPast"]).optional(),
})
),
});