* 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 <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
43 lines
1.1 KiB
TypeScript
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);
|
|
});
|
|
});
|