UNPKG

@sentzunhat/zacatl

Version:

A modular, high-performance TypeScript microservice framework for Node.js, featuring layered architecture, dependency injection, and robust validation for building scalable APIs and distributed systems.

46 lines (37 loc) 1.21 kB
import { describe, it, expect, vi } from "vitest"; import i18n from "i18n"; import { PostRouteHandler, Request, } from "../../../../../../../../src/micro-service/architecture/application"; import { createFakeFastifyReply, createFakeFastifyRequest, } from "../../../../../../helpers/common/common"; class TestPostRouteHandler extends PostRouteHandler<{}, {}, {}, {}> { constructor() { super({ url: "/post-test", schema: {}, // Use an empty schema for test purposes. }); } handler(_: Request<{}, {}, {}>): {} | Promise<{}> { // Dummy implementation return {}; } } describe("PostRouteHandler", () => { it("executes POST handler and sends proper response", async () => { vi.spyOn(i18n, "__").mockReturnValue("Default success POST"); const testHandler = new TestPostRouteHandler(); const fakeRequest = createFakeFastifyRequest() as Request<{}, {}, {}>; const fakeReply = createFakeFastifyReply(); await testHandler.execute(fakeRequest, fakeReply); expect(fakeReply.code).toHaveBeenCalledWith(200); expect(fakeReply.send).toHaveBeenCalledWith({ ok: true, message: "Default success POST", data: {}, }); }); });