Skip to content

Commit 386f60c

Browse files
refactor: replace prismaMock with BookingRepository mock in checkDurationLimits tests (calcom#24050)
- Replace prismaMock. mocks with BookingRepository.getTotalBookingDuration mocks - Update return values from [{ totalMinutes: X }] to X to match repository method signature - Follow existing repository mocking pattern used in other test files - All tests pass with the new mocking approach Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent e98f279 commit 386f60c

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

apps/web/test/lib/checkDurationLimits.test.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import prismaMock from "../../../../tests/libs/__mocks__/prismaMock";
2-
3-
import { describe, expect, it } from "vitest";
1+
import { describe, expect, it, vi } from "vitest";
42

53
import dayjs from "@calcom/dayjs";
64
import {
@@ -9,6 +7,13 @@ import {
97
} from "@calcom/lib/intervalLimits/server/checkDurationLimits";
108
import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateIntervalLimitOrder";
119

10+
const mockGetTotalBookingDuration = vi.fn();
11+
vi.mock("@calcom/lib/server/repository/booking", () => ({
12+
BookingRepository: vi.fn().mockImplementation(() => ({
13+
getTotalBookingDuration: mockGetTotalBookingDuration,
14+
})),
15+
}));
16+
1217
type MockData = {
1318
id: number;
1419
startDate: Date;
@@ -22,19 +27,19 @@ const MOCK_DATA: MockData = {
2227
// Path: apps/web/test/lib/checkDurationLimits.ts
2328
describe("Check Duration Limits Tests", () => {
2429
it("Should return no errors if limit is not reached", async () => {
25-
prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 0 }]);
30+
mockGetTotalBookingDuration.mockResolvedValue(0);
2631
await expect(
2732
checkDurationLimits({ PER_DAY: 60 }, MOCK_DATA.startDate, MOCK_DATA.id)
2833
).resolves.toBeTruthy();
2934
});
3035
it("Should throw an error if limit is reached", async () => {
31-
prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 60 }]);
36+
mockGetTotalBookingDuration.mockResolvedValue(60);
3237
await expect(
3338
checkDurationLimits({ PER_DAY: 60 }, MOCK_DATA.startDate, MOCK_DATA.id)
3439
).rejects.toThrowError();
3540
});
3641
it("Should pass with multiple duration limits", async () => {
37-
prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 30 }]);
42+
mockGetTotalBookingDuration.mockResolvedValue(30);
3843
await expect(
3944
checkDurationLimits(
4045
{
@@ -47,7 +52,7 @@ describe("Check Duration Limits Tests", () => {
4752
).resolves.toBeTruthy();
4853
});
4954
it("Should pass with multiple duration limits with one undefined", async () => {
50-
prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 30 }]);
55+
mockGetTotalBookingDuration.mockResolvedValue(30);
5156
await expect(
5257
checkDurationLimits(
5358
{
@@ -60,7 +65,7 @@ describe("Check Duration Limits Tests", () => {
6065
).resolves.toBeTruthy();
6166
});
6267
it("Should return no errors if limit is not reached with multiple bookings", async () => {
63-
prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 60 }]);
68+
mockGetTotalBookingDuration.mockResolvedValue(60);
6469
await expect(
6570
checkDurationLimits(
6671
{
@@ -73,7 +78,7 @@ describe("Check Duration Limits Tests", () => {
7378
).resolves.toBeTruthy();
7479
});
7580
it("Should throw an error if one of the limit is reached with multiple bookings", async () => {
76-
prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 90 }]);
81+
mockGetTotalBookingDuration.mockResolvedValue(90);
7782
await expect(
7883
checkDurationLimits(
7984
{
@@ -90,7 +95,7 @@ describe("Check Duration Limits Tests", () => {
9095
// Path: apps/web/test/lib/checkDurationLimits.ts
9196
describe("Check Duration Limit Tests", () => {
9297
it("Should return no busyTimes and no error if limit is not reached", async () => {
93-
prismaMock.$queryRaw.mockResolvedValue([{ totalMinutes: 60 }]);
98+
mockGetTotalBookingDuration.mockResolvedValue(60);
9499
await expect(
95100
checkDurationLimit({
96101
key: "PER_DAY",

0 commit comments

Comments
 (0)