Files
calendar/tests/event-types/event-type.index.test.ts
T
2022-03-30 14:17:55 +02:00

33 lines
1.2 KiB
TypeScript

import handleApiKeys from "@api/event-types";
import { createMocks } from "node-mocks-http";
import prisma from "@calcom/prisma";
// import {stringifyISODate} from "@lib/utils/stringifyISODate";
describe("GET /api/event-types without any params", () => {
it("returns a message with the specified eventTypes", async () => {
const { req, res } = createMocks({
method: "GET",
query: {},
});
const eventTypes = await prisma.eventType.findMany();
await handleApiKeys(req, res);
expect(res._getStatusCode()).toBe(200);
// eventTypes = eventTypes.map(eventType => (eventType = {...eventType, createdAt: stringifyISODate(eventType?.createdAt), expiresAt: stringifyISODate(eventType?.expiresAt)}));
expect(JSON.parse(res._getData())).toStrictEqual(JSON.parse(JSON.stringify({ data: { ...eventTypes } })));
});
});
describe("POST /api/event-types/ fails, only GET allowed", () => {
it("returns a message with the specified eventTypes", async () => {
const { req, res } = createMocks({
method: "POST", // This POST method is not allowed
});
await handleApiKeys(req, res);
expect(res._getStatusCode()).toBe(405);
expect(JSON.parse(res._getData())).toStrictEqual({ message: "Only GET Method allowed" });
});
});