From 05a5f674f1821b6419260a452a04f1fc03779271 Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Mon, 9 Dec 2024 06:29:57 +0100 Subject: [PATCH] Remove any --- backend/src/bookings/bookings.module.spec.ts | 36 +++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/backend/src/bookings/bookings.module.spec.ts b/backend/src/bookings/bookings.module.spec.ts index d7203fe..0958aa5 100644 --- a/backend/src/bookings/bookings.module.spec.ts +++ b/backend/src/bookings/bookings.module.spec.ts @@ -1,23 +1,36 @@ import { BookingsModule } from "./bookings.module"; import { TypeOrmModule } from "@nestjs/typeorm"; import { BookingsService } from "./bookings.service"; +import { DynamicModule, ForwardReference, Type } from "@nestjs/common"; + +type ModuleImport = + | Type + | DynamicModule + | Promise + | ForwardReference; describe("BookingsModule", () => { it("should have correct module metadata", () => { // Get module metadata directly from the decorator - const moduleDecorator = Reflect.getMetadata("imports", BookingsModule); + const moduleDecorator = Reflect.getMetadata( + "imports", + BookingsModule + ) as ModuleImport[]; // Check TypeOrmModule.forFeature const typeOrmFeature = moduleDecorator.find( - (item: any) => - item && typeof item === "object" && item.module === TypeOrmModule + (item): item is DynamicModule => + item !== null && + typeof item === "object" && + "module" in item && + item.module === TypeOrmModule ); expect(typeOrmFeature).toBeDefined(); // Get all module names const moduleNames = moduleDecorator - .map((item: any) => { - if (item && typeof item === "function") { + .map((item): string | null => { + if (typeof item === "function") { return item.name; } if (item && typeof item === "object" && "name" in item) { @@ -25,7 +38,7 @@ describe("BookingsModule", () => { } return null; }) - .filter(Boolean); + .filter((name): name is string => Boolean(name)); // Check for expected modules const expectedModules = [ @@ -40,13 +53,18 @@ describe("BookingsModule", () => { }); it("should export BookingsService and TypeOrmModule", () => { - const exports = Reflect.getMetadata("exports", BookingsModule); + const exports = Reflect.getMetadata("exports", BookingsModule) as Array< + Type | DynamicModule + >; expect(exports).toContain(BookingsService); const hasTypeOrmExport = exports.some( - (exp: any) => + (exp): boolean => exp === TypeOrmModule || - (exp && typeof exp === "object" && exp.module === TypeOrmModule) + (exp !== null && + typeof exp === "object" && + "module" in exp && + exp.module === TypeOrmModule) ); expect(hasTypeOrmExport).toBe(true); });