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.

61 lines (48 loc) 1.39 kB
import { describe, it, expect } from "vitest"; import { FastifyRequest } from "fastify"; import { AbstractRouteHandler, Application, ConfigApplication, HookHandler, HookHandlerName, Request, } from "../../../../../src/micro-service/architecture/application"; class DummyHookHandler implements HookHandler { public name: HookHandlerName = "onRequest"; async execute(_: FastifyRequest): Promise<void> {} } import { FastifyReply } from "fastify"; class DummyRouteHandler extends AbstractRouteHandler { constructor() { super({ url: "/", schema: {}, method: "GET", }); } handler(_: Request, __: FastifyReply): void | Promise<void> { // Dummy implementation return; } } const fakeConfig: ConfigApplication = { entryPoints: { rest: { hookHandlers: [DummyHookHandler], routeHandlers: [DummyRouteHandler], }, }, }; describe("Application", () => { it("should register hook and route handlers on start", () => { const app = new Application(fakeConfig); expect(app.hookHandlers).toHaveLength(0); expect(app.routeHandlers).toHaveLength(0); app.start(); expect(app.hookHandlers).toHaveLength(1); expect(app.routeHandlers).toHaveLength(1); expect(app.hookHandlers[0]).toBeInstanceOf(DummyHookHandler); expect(app.routeHandlers[0]).toBeInstanceOf(DummyRouteHandler); }); });