Skip to content

Scheduling infrastructure for absolutely everyone.

refactor: replace prismaMock with BookingRepository mock in checkDurationLimits tests (#24050)

Keith Williams386f60ca6d0e
diff --git a/apps/web/test/lib/checkDurationLimits.test.ts b/apps/web/test/lib/checkDurationLimits.test.ts
index 52a5877e040..f90254791bb 100644
--- a/apps/web/test/lib/checkDurationLimits.test.ts
+++ b/apps/web/test/lib/checkDurationLimits.test.ts
@@ -1,6 +1,4 @@
-import prismaMock from "../../../../tests/libs/__mocks__/prismaMock";
-
-import { describe, expect, it } from "vitest";
+import { describe, expect, it, vi } from "vitest";
import dayjs from "@calcom/dayjs";
import {
@@ -9,6 +7,13 @@ import {
} from "@calcom/lib/intervalLimits/server/checkDurationLimits";
import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateIntervalLimitOrder";
+const mockGetTotalBookingDuration = vi.fn();
+vi.mock("@calcom/lib/server/repository/booking", () => ({
+ BookingRepository: vi.fn().mockImplementation(() => ({
+ getTotalBookingDuration: mockGetTotalBookingDuration,
+ })),
+}));
+
type MockData = {
id: number;
startDate: Date;
@@ -22,19 +27,19 @@ const MOCK_DATA: MockData = {
// Path: apps/web/test/lib/checkDurationLimits.ts
describe("Check Duration Limits Tests", () => {
it("Should return no errors if limit is not reached", async () => {
- prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 0 }]);
+ mockGetTotalBookingDuration.mockResolvedValue(0);
await expect(
checkDurationLimits({ PER_DAY: 60 }, MOCK_DATA.startDate, MOCK_DATA.id)
).resolves.toBeTruthy();
});
it("Should throw an error if limit is reached", async () => {
- prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 60 }]);
+ mockGetTotalBookingDuration.mockResolvedValue(60);
await expect(
checkDurationLimits({ PER_DAY: 60 }, MOCK_DATA.startDate, MOCK_DATA.id)
).rejects.toThrowError();
});
it("Should pass with multiple duration limits", async () => {
- prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 30 }]);
+ mockGetTotalBookingDuration.mockResolvedValue(30);
await expect(
checkDurationLimits(
{
@@ -47,7 +52,7 @@ describe("Check Duration Limits Tests", () => {
).resolves.toBeTruthy();
});
it("Should pass with multiple duration limits with one undefined", async () => {
- prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 30 }]);
+ mockGetTotalBookingDuration.mockResolvedValue(30);
await expect(
checkDurationLimits(
{
@@ -60,7 +65,7 @@ describe("Check Duration Limits Tests", () => {
).resolves.toBeTruthy();
});
it("Should return no errors if limit is not reached with multiple bookings", async () => {
- prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 60 }]);
+ mockGetTotalBookingDuration.mockResolvedValue(60);
await expect(
checkDurationLimits(
{
@@ -73,7 +78,7 @@ describe("Check Duration Limits Tests", () => {
).resolves.toBeTruthy();
});
it("Should throw an error if one of the limit is reached with multiple bookings", async () => {
- prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 90 }]);
+ mockGetTotalBookingDuration.mockResolvedValue(90);
await expect(
checkDurationLimits(
{
@@ -90,7 +95,7 @@ describe("Check Duration Limits Tests", () => {
// Path: apps/web/test/lib/checkDurationLimits.ts
describe("Check Duration Limit Tests", () => {
it("Should return no busyTimes and no error if limit is not reached", async () => {
- prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 60 }]);
+ mockGetTotalBookingDuration.mockResolvedValue(60);
await expect(
checkDurationLimit({
key: "PER_DAY",