Files
calendar/packages/lib/server/defaultHandler.test.ts
7fbeeae25b fix: event type not found 400 and other (#23904)
* fix: various fixes specifically to event-types

* Revamp error handling a little; highly flawed

* fix: Test cases that depended on defaultResponder behaviour

---------

Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Morgan <[email protected]>
2025-09-18 18:56:00 +00:00

43 lines
1.1 KiB
TypeScript

import { createMocks } from "node-mocks-http";
import { describe, it, expect, vi, afterEach } from "vitest";
import { defaultHandler } from "./defaultHandler";
describe("defaultHandler Test Suite", () => {
afterEach(() => {
vi.clearAllMocks();
});
it("should return 405 for unsupported HTTP methods", async () => {
const handlers = {};
const handler = defaultHandler(handlers);
const { req, res } = createMocks({
method: "PATCH", // Unsupported method here
});
await handler(req, res);
expect(res._getStatusCode()).toBe(405);
expect(res._getJSONData()).toEqual({
message: "Method Not Allowed (Allow: )",
});
});
it("should call the correct handler for a supported method", async () => {
const getHandler = vi.fn().mockResolvedValue(null);
const handlers = {
GET: { default: getHandler },
};
const handler = defaultHandler(handlers);
const { req, res } = createMocks({
method: "GET",
});
await handler(req, res);
expect(getHandler).toHaveBeenCalledWith(req, res);
});
});