Files
formbricks/apps/web/modules/survey/follow-ups/lib/utils.test.ts
T
2025-10-28 09:04:22 +00:00

45 lines
1.6 KiB
TypeScript

import { beforeEach, describe, expect, test, vi } from "vitest";
import { TOrganizationBillingPlan } from "@formbricks/types/organizations";
import * as constants from "@/lib/constants";
import { getSurveyFollowUpsPermission } from "./utils";
vi.mock("@/lib/constants", async () => {
const actual = (await vi.importActual("@/lib/constants")) as any;
return {
...actual,
IS_FORMBRICKS_CLOUD: true,
PROJECT_FEATURE_KEYS: {
FREE: "free",
STARTUP: "startup",
CUSTOM: "custom",
},
};
});
describe("getSurveyFollowUpsPermission", () => {
beforeEach(() => {
vi.spyOn(constants, "IS_FORMBRICKS_CLOUD", "get").mockReturnValue(true);
});
test("should return false for free plan on Formbricks Cloud", async () => {
const result = await getSurveyFollowUpsPermission("free" as TOrganizationBillingPlan);
expect(result).toBe(false);
});
test("should return false for startup plan on Formbricks Cloud", async () => {
const result = await getSurveyFollowUpsPermission("startup" as TOrganizationBillingPlan);
expect(result).toBe(false);
});
test("should return true for custom plan on Formbricks Cloud", async () => {
const result = await getSurveyFollowUpsPermission("custom" as TOrganizationBillingPlan);
expect(result).toBe(true);
});
test("should return true for any plan when not on Formbricks Cloud", async () => {
vi.spyOn(constants, "IS_FORMBRICKS_CLOUD", "get").mockReturnValue(false);
const result = await getSurveyFollowUpsPermission("free" as TOrganizationBillingPlan);
expect(result).toBe(true);
});
});