* feat - Restrict same email to create more than 'n' active bookings at a time * updated checkbookerbookinglimit function * type fix * minor change * import fix * minor fixes * back to null on disable * back * type check * managed edge cases * chore: name changes * name changes * fix * minor change * changed name * use default value for maxactivebookingsperbooker, and some minor changes * disabling bookerbooking limit for recurring event * disabling bookerbooking limit for recurring event * type fix * ui fix and backend eventtype update check * Add `maxActiveBookingPerBookerOfferReschedule` to schema * Create `MaxActiveBookingsPerBookerController` and offer reschedule option * Add offer reschedule to event type form data * Pass data through to HttpError * When checking max bookings, return last booking info if applicable * removed unused code * minor changes * update validation * chore * Do not check booking limits if rescheduling * Add data for reschedule * Add reschedule specific error code * On maximum booking error, write to booker store reschedule params * Add translations for error codes * Write to error message previous booking time * minor fix * Write to error message previous booking time * Type fixes * Clean up comment * Refactor eventType update errors * Typo fix * Type fix * Type fix * Type fix * Fix test * Fix test * Add migration * Addressed feedback and missed merges --------- Co-authored-by: romit <romitgabani@icloud.com>
88 lines
2.6 KiB
TypeScript
88 lines
2.6 KiB
TypeScript
import prismock from "../../../../../../tests/libs/__mocks__/prisma";
|
|
|
|
import type { Request, Response } from "express";
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
import { createMocks } from "node-mocks-http";
|
|
import { describe, expect, test } from "vitest";
|
|
|
|
import dayjs from "@calcom/dayjs";
|
|
|
|
import handler from "./_get";
|
|
|
|
type CustomNextApiRequest = NextApiRequest & Request;
|
|
type CustomNextApiResponse = NextApiResponse & Response;
|
|
|
|
function buildMockData() {
|
|
prismock.user.create({
|
|
data: {
|
|
id: 1,
|
|
username: "test",
|
|
name: "Test User",
|
|
email: "test@example.com",
|
|
},
|
|
});
|
|
prismock.eventType.create({
|
|
data: {
|
|
id: 1,
|
|
slug: "test",
|
|
length: 30,
|
|
title: "Test Event Type",
|
|
userId: 1,
|
|
},
|
|
});
|
|
}
|
|
|
|
describe("GET /api/slots", () => {
|
|
describe("Errors", () => {
|
|
test("Missing required data", async () => {
|
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
|
method: "GET",
|
|
});
|
|
|
|
await handler(req, res);
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
});
|
|
});
|
|
|
|
describe("Success", () => {
|
|
describe("Regular event-type", () => {
|
|
test("Returns and event type available slots", async () => {
|
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
|
method: "GET",
|
|
query: {
|
|
eventTypeId: 1,
|
|
startTime: dayjs().format(),
|
|
endTime: dayjs().add(1, "day").format(),
|
|
usernameList: "test",
|
|
},
|
|
prisma: prismock,
|
|
});
|
|
buildMockData();
|
|
await handler(req, res);
|
|
console.log({ statusCode: res._getStatusCode(), data: JSON.parse(res._getData()) });
|
|
const response = JSON.parse(res._getData());
|
|
expect(response.slots).toEqual(expect.objectContaining({}));
|
|
});
|
|
test("Returns and event type available slots with passed timeZone", async () => {
|
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
|
method: "GET",
|
|
query: {
|
|
eventTypeId: 1,
|
|
startTime: dayjs().format(),
|
|
endTime: dayjs().add(1, "day").format(),
|
|
usernameList: "test",
|
|
timeZone: "UTC",
|
|
},
|
|
prisma: prismock,
|
|
});
|
|
buildMockData();
|
|
await handler(req, res);
|
|
console.log({ statusCode: res._getStatusCode(), data: JSON.parse(res._getData()) });
|
|
const response = JSON.parse(res._getData());
|
|
expect(response.slots).toEqual(expect.objectContaining({}));
|
|
});
|
|
});
|
|
});
|
|
});
|