WIP
This commit is contained in:
parent
7b43ac4558
commit
2ba9463f1e
|
@ -37,7 +37,7 @@ const timeout = process.env.CI ? 5000 : 20000;
|
||||||
describe.sequential("handleNewBooking", () => {
|
describe.sequential("handleNewBooking", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Required to able to generate token in email in some cases
|
// Required to able to generate token in email in some cases
|
||||||
process.env.CALENDSO_ENCRYPTION_KEY="abcdefghjnmkljhjklmnhjklkmnbhjui"
|
process.env.CALENDSO_ENCRYPTION_KEY = "abcdefghjnmkljhjklmnhjklkmnbhjui";
|
||||||
mockNoTranslations();
|
mockNoTranslations();
|
||||||
mockEnableEmailFeature();
|
mockEnableEmailFeature();
|
||||||
globalThis.testEmails = [];
|
globalThis.testEmails = [];
|
||||||
|
@ -573,8 +573,7 @@ describe.sequential("handleNewBooking", () => {
|
||||||
expectWebhookToHaveBeenCalledWith("http://my-webhook.example.com", {
|
expectWebhookToHaveBeenCalledWith("http://my-webhook.example.com", {
|
||||||
triggerEvent: "BOOKING_CREATED",
|
triggerEvent: "BOOKING_CREATED",
|
||||||
payload: {
|
payload: {
|
||||||
metadata: {
|
metadata: {},
|
||||||
},
|
|
||||||
responses: {
|
responses: {
|
||||||
name: { label: "your_name", value: "Booker" },
|
name: { label: "your_name", value: "Booker" },
|
||||||
email: { label: "email_address", value: "booker@example.com" },
|
email: { label: "email_address", value: "booker@example.com" },
|
||||||
|
|
|
@ -551,6 +551,8 @@ async function getBookingData({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("🚀 ~ file: handleNewBooking.ts:555 ~ req.body:", req.body);
|
||||||
|
|
||||||
const reqBody = await bookingDataSchema.parseAsync(req.body);
|
const reqBody = await bookingDataSchema.parseAsync(req.body);
|
||||||
|
|
||||||
// Work with Typescript to require reqBody.end
|
// Work with Typescript to require reqBody.end
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
import { createMocks } from "node-mocks-http";
|
import { createMocks } from "node-mocks-http";
|
||||||
import { test } from "vitest";
|
import { test } from "vitest";
|
||||||
|
|
||||||
// import { default as handleNewBooking } from "@calcom/features/bookings/lib/handleNewBooking";
|
// import { default as handleNewBooking } from "@calcom/features/bookings/lib/handleNewBooking";
|
||||||
// import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
import { getBooker, getDate } from "@calcom/web/test/utils/bookingScenario";
|
import { getDate } from "@calcom/web/test/utils/bookingScenario";
|
||||||
|
|
||||||
type CustomNextApiRequest = NextApiRequest & Request;
|
type CustomNextApiRequest = NextApiRequest & Request;
|
||||||
type CustomNextApiResponse = NextApiResponse & Response;
|
type CustomNextApiResponse = NextApiResponse & Response;
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
// const prisma = new PrismaClient();
|
||||||
|
|
||||||
export function withPrisma(handler: any) {
|
export function withPrisma(handler: any) {
|
||||||
return async (req: any, res: any) => {
|
return async (req: any, res: any) => {
|
||||||
|
@ -24,10 +23,10 @@ export function withPrisma(handler: any) {
|
||||||
|
|
||||||
test("handleNewBooking", async () => {
|
test("handleNewBooking", async () => {
|
||||||
const handleNewBooking = (await import("@calcom/features/bookings/lib/handleNewBooking")).default;
|
const handleNewBooking = (await import("@calcom/features/bookings/lib/handleNewBooking")).default;
|
||||||
const booker = getBooker({
|
// const booker = getBooker({
|
||||||
email: "booker@example.com",
|
// email: "booker@example.com",
|
||||||
name: "Booker",
|
// name: "Booker",
|
||||||
});
|
// });
|
||||||
|
|
||||||
// const organizer = getOrganizer({
|
// const organizer = getOrganizer({
|
||||||
// name: "Organizer",
|
// name: "Organizer",
|
||||||
|
@ -51,21 +50,35 @@ test("handleNewBooking", async () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockBookingData = getMockRequestDataForBooking({
|
// const mockBookingData = getMockRequestDataForBooking({
|
||||||
data: {
|
// data: {
|
||||||
eventTypeId: pro30MinEventType?.id,
|
// eventTypeId: pro30MinEventType?.id,
|
||||||
responses: {
|
// responses: {
|
||||||
email: booker.email,
|
// email: booker.email,
|
||||||
name: booker.name,
|
// name: booker.name,
|
||||||
location: { optionValue: "", value: "integrations:daily" },
|
// location: { optionValue: "", value: "integrations:daily" },
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
|
|
||||||
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: mockBookingData,
|
body: {
|
||||||
prisma,
|
eventTypeId: pro30MinEventType?.id,
|
||||||
|
responses: {
|
||||||
|
email: "booker@example.com",
|
||||||
|
name: "Booker",
|
||||||
|
location: { optionValue: "", value: "integrations:daily" },
|
||||||
|
},
|
||||||
|
start: `${getDate({ dateIncrement: 1 }).dateString}T04:00:00.000Z`,
|
||||||
|
end: `${getDate({ dateIncrement: 1 }).dateString}T04:30:00.000Z`,
|
||||||
|
timeZone: "Asia/Calcutta",
|
||||||
|
language: "en",
|
||||||
|
metadata: {},
|
||||||
|
hasHashedBookingLink: false,
|
||||||
|
hashedLink: null,
|
||||||
|
},
|
||||||
|
// prisma,
|
||||||
});
|
});
|
||||||
// console.log("🚀 ~ file: handleNewBooking.test.ts:56 ~ test ~ prisma:", prisma);
|
// console.log("🚀 ~ file: handleNewBooking.test.ts:56 ~ test ~ prisma:", prisma);
|
||||||
|
|
||||||
|
@ -75,13 +88,13 @@ test("handleNewBooking", async () => {
|
||||||
// prisma,
|
// prisma,
|
||||||
// });
|
// });
|
||||||
|
|
||||||
withPrisma(async (req: NextApiRequest, res: NextApiResponse) => {
|
// withPrisma(async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
// Your code here
|
// // Your code here
|
||||||
handleNewBooking(req);
|
// handleNewBooking(req);
|
||||||
})(req, res);
|
// })(req, res);
|
||||||
|
|
||||||
// const createdBooking = await handleNewBooking(req);
|
const createdBooking = await handleNewBooking(req);
|
||||||
// console.log("🚀 ~ file: handleNewBooking.test.ts:49 ~ test ~ createdBooking:", createdBooking);
|
console.log("🚀 ~ file: handleNewBooking.test.ts:49 ~ test ~ createdBooking:", createdBooking);
|
||||||
});
|
});
|
||||||
|
|
||||||
function createMockNextJsRequest(...args: Parameters<typeof createMocks>) {
|
function createMockNextJsRequest(...args: Parameters<typeof createMocks>) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user