refactor: replace prismaMock with BookingRepository mock in checkDurationLimits tests (#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>
This commit is contained in:
co-authored by
Devin AI
parent
e98f279f64
commit
386f60ca6d
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user