test: replace prismaMock with BookingRepository mock in checkBookingLimits tests (#24152)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Keith WilliamsandDevin AI authored and GitHub committed 2025-09-29 23:34:20 +00:00
1 parent 259e480baa
commit d29477349a
1 file changed
+14 -10
+14 -10
View File
@@ -1,12 +1,17 @@
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 { getCheckBookingLimitsService } from "@calcom/lib/di/containers/BookingLimits";
import type { IntervalLimit } from "@calcom/lib/intervalLimits/intervalLimitSchema";
import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateIntervalLimitOrder";
const mockCountBookingsByEventTypeAndDateRange = vi.fn();
vi.mock("@calcom/lib/server/repository/booking", () => ({
BookingRepository: vi.fn().mockImplementation(() => ({
countBookingsByEventTypeAndDateRange: mockCountBookingsByEventTypeAndDateRange,
})),
}));
type Mockdata = {
id: number;
startDate: Date;
@@ -25,21 +30,20 @@ const checkBookingLimitsService = getCheckBookingLimitsService();
describe("Check Booking Limits Tests", () => {
it("Should return no errors", async () => {
prismaMock.booking.count.mockResolvedValue(0);
mockCountBookingsByEventTypeAndDateRange.mockResolvedValue(0);
expect(
checkBookingLimitsService.checkBookingLimits(MOCK_DATA.bookingLimits, MOCK_DATA.startDate, MOCK_DATA.id)
).resolves.toBeTruthy();
});
it("Should throw an error", async () => {
// Mock there being two a day
prismaMock.booking.count.mockResolvedValue(2);
mockCountBookingsByEventTypeAndDateRange.mockResolvedValue(2);
expect(
checkBookingLimitsService.checkBookingLimits(MOCK_DATA.bookingLimits, MOCK_DATA.startDate, MOCK_DATA.id)
).rejects.toThrowError();
});
it("Should pass with multiple booking limits", async () => {
prismaMock.booking.count.mockResolvedValue(0);
mockCountBookingsByEventTypeAndDateRange.mockResolvedValue(0);
expect(
checkBookingLimitsService.checkBookingLimits(
{
@@ -52,7 +56,7 @@ describe("Check Booking Limits Tests", () => {
).resolves.toBeTruthy();
});
it("Should pass with multiple booking limits with one undefined", async () => {
prismaMock.booking.count.mockResolvedValue(0);
mockCountBookingsByEventTypeAndDateRange.mockResolvedValue(0);
expect(
checkBookingLimitsService.checkBookingLimits(
@@ -66,7 +70,7 @@ describe("Check Booking Limits Tests", () => {
).resolves.toBeTruthy();
});
it("Should handle multiple limits correctly", async () => {
prismaMock.booking.count.mockResolvedValue(1);
mockCountBookingsByEventTypeAndDateRange.mockResolvedValue(1);
expect(
checkBookingLimitsService.checkBookingLimit({
key: "PER_DAY",
@@ -75,7 +79,7 @@ describe("Check Booking Limits Tests", () => {
eventId: MOCK_DATA.id,
})
).resolves.not.toThrow();
prismaMock.booking.count.mockResolvedValue(3);
mockCountBookingsByEventTypeAndDateRange.mockResolvedValue(3);
expect(
checkBookingLimitsService.checkBookingLimit({
key: "PER_WEEK",