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.

63 lines (53 loc) 1.44 kB
import { describe, it, expect, vi } from "vitest"; import i18n from "i18n"; import { createFakeFastifyReply, createFakeFastifyRequest, } from "../../../../../../helpers/common/common"; import { AbstractRouteHandler, Request, } from "../../../../../../../../src/micro-service/architecture/application"; class TestRouteHandler extends AbstractRouteHandler< void, // Body Record<string, string>, // Querystring void, // Params void // Response > { constructor() { super({ url: "/", schema: {}, method: "GET", }); } handler( _: Request< void, // Body Record<string, string>, // Querystring void // Params > ): void | Promise<void> { // Dummy implementation return; } } describe("AbstractRouteHandler", () => { it("executes the handler and sends the proper response", async () => { vi.spyOn(i18n, "__").mockReturnValue("Default success"); const fakeRequest = createFakeFastifyRequest() as Request< void, // Body Record<string, string>, // Querystring void // Params >; const fakeReply: any = createFakeFastifyReply(); const testHandler = new TestRouteHandler(); await testHandler.execute(fakeRequest, fakeReply); expect(fakeReply.code).toHaveBeenCalledWith(200); expect(fakeReply.send).toHaveBeenCalledWith({ ok: true, message: "Default success", data: undefined, }); }); });