From 16d2685647631471d1376c8780412fa025754b33 Mon Sep 17 00:00:00 2001
From: shreyvishal <shreya.vishal@eminds.ai>
Date: Thu, 11 Jan 2024 19:24:18 +0530
Subject: [PATCH] Fixed: Some Change

---
 package.json                               |  1 +
 src/middleware/errorhandler.middleware.ts  | 49 +++++++++++-------
 src/test/industry-4.0/industry-4.0.spec.ts | 58 +++-------------------
 tsconfig.json                              |  5 +-
 4 files changed, 43 insertions(+), 70 deletions(-)

diff --git a/package.json b/package.json
index 6d18954..28b8a81 100644
--- a/package.json
+++ b/package.json
@@ -38,6 +38,7 @@
     "@types/express": "^4.17.21",
     "@types/ini": "^1.3.33",
     "@types/jest": "^29.5.11",
+    "@types/node": "^20.11.0",
     "@types/uuid": "^9.0.7",
     "jest": "^29.7.0",
     "nodemon": "^3.0.1",
diff --git a/src/middleware/errorhandler.middleware.ts b/src/middleware/errorhandler.middleware.ts
index 3fbf2bb..2a1d265 100644
--- a/src/middleware/errorhandler.middleware.ts
+++ b/src/middleware/errorhandler.middleware.ts
@@ -1,25 +1,36 @@
-import { inject, injectable } from 'inversify';
-import { Request, Response, NextFunction } from 'express';
-import { AppLogger } from '../app/app.logger';
-import { AxiosError } from 'axios';
-import { TLService } from '../tl/tl.service';
+import { inject, injectable } from "inversify";
+import { Request, Response, NextFunction } from "express";
+import { AppLogger } from "../app/app.logger";
+import { AxiosError } from "axios";
+import { TLService } from "../tl/tl.service";
 
 @injectable()
 export class ErrorHandlerMiddleware {
-    constructor(@inject(AppLogger) private logger: AppLogger, @inject(TLService) private tlService: TLService) { }
+  constructor(
+    @inject(AppLogger) private logger: AppLogger,
+    @inject(TLService) private tlService: TLService
+  ) {}
 
-    public async handleError(error: Error | AxiosError, req: Request, res: Response, next: NextFunction) {
-        const { response } = error as AxiosError;
-        if (response?.status === 400) {
-            const transformedResponse = await this.tlService.transform(response.data, "ps_error");
-            return res.status(response.status).json(transformedResponse);
-        }
-        this.logger.error("%s", error.stack);
-        const statusCode = res.statusCode === 200 ? 500 : res.statusCode;
-        res.status(statusCode).json({
-            error: {
-                message: error.message
-            },
-        });
+  public async handleError(
+    error: Error | AxiosError,
+    req: Request,
+    res: Response,
+    next: NextFunction
+  ) {
+    const { response } = error as AxiosError;
+    if (response?.status === 400) {
+      const transformedResponse = await this.tlService.transform(
+        response.data,
+        "ps_error"
+      );
+      return res.status(response.status).json(transformedResponse);
     }
+    this.logger.error("%s", error.stack);
+    const statusCode = res.statusCode === 200 ? 500 : res.statusCode;
+    res.status(statusCode).json({
+      error: {
+        message: error.message
+      }
+    });
+  }
 }
diff --git a/src/test/industry-4.0/industry-4.0.spec.ts b/src/test/industry-4.0/industry-4.0.spec.ts
index 96ca452..4dbd609 100644
--- a/src/test/industry-4.0/industry-4.0.spec.ts
+++ b/src/test/industry-4.0/industry-4.0.spec.ts
@@ -1,59 +1,17 @@
 import "reflect-metadata";
-import { describe, it, expect, beforeEach } from "@jest/globals";
-import { Container } from "inversify";
-import { GCLController } from "../../gcl/gcl.controller";
-import { GCLService } from "../../gcl/gcl.service";
-import { XInputService } from "../../x-input/x-input.service";
-import { TLService } from "../../tl/tl.service";
-import { AppLogger } from "../../app/app.logger";
-import { PSClientService } from "../../psclient/psclient.service";
-import { ConfigService } from "../../config/config.service";
-import HttpClient from "../../httpclient/http.service";
-import { ErrorHandlerMiddleware } from "../../middleware/errorhandler.middleware";
+import { describe, it, expect, beforeEach, jest } from "@jest/globals";
 
-const container = new Container();
-// container.bind();
+import { container } from "../../inversify/inversify.config";
+import { GCLController } from "../../gcl/gcl.controller";
 
 describe("GCL Controller Testing", () => {
-  // let appLogger = new AppLogger();
-  // let configService = new ConfigService();
-  // let httpClient = new HttpClient(appLogger);
-  // let xinputService = new XInputService(appLogger, httpClient);
-  // let psClientService = new PSClientService(configService, httpClient);
-  // let tlService = new TLService(appLogger);
-  // let gclService = new GCLService(tlService, psClientService);
-  // let gclController = new GCLController(gclService, xinputService);
-  // let errorHandlerMiddleware = new ErrorHandlerMiddleware(appLogger, tlService);
-
-  let container: Container;
+  beforeEach(async () => {});
 
-  beforeEach(async () => {
-    container = new Container();
-    container.bind<GCLController>(GCLController).toSelf();
-    container.bind<GCLService>(GCLService).toSelf();
-
-    // appLogger = new AppLogger();
-    // configService = new ConfigService();
-    // httpClient = new HttpClient(appLogger);
-    // xinputService = new XInputService(appLogger, httpClient);
-    // psClientService = new PSClientService(configService, httpClient);
-    // tlService = new TLService(appLogger);
-    // gclService = new GCLService(tlService, psClientService);
-    // gclController = new GCLController(gclService, xinputService);
-    // errorHandlerMiddleware = new ErrorHandlerMiddleware(appLogger, tlService);
-  });
+  it("should be defined", async () => {
+    let controller = container.resolve(GCLController);
 
-  it("should be defined", () => {
-    // let controller = container.resolve(GCLController);
-    let service = container.resolve(GCLService);
+    console.log("======>Hello");
 
-    // const errorHandlerMiddleware = container.get<ErrorHandlerMiddleware>(
-    //     ErrorHandlerMiddleware
-    //   );
-    //   this.app.use(
-    //     errorHandlerMiddleware.handleError.bind(errorHandlerMiddleware)
-    //   );
-    console.log("======>", service);
-    expect(service).toBeDefined();
+    expect(controller).toEqual({});
   });
 });
diff --git a/tsconfig.json b/tsconfig.json
index 34e70f7..464dd74 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -34,7 +34,10 @@
     // "paths": {},                                      /* Specify a set of entries that re-map imports to additional lookup locations. */
     // "rootDirs": [],                                   /* Allow multiple folders to be treated as one when resolving modules. */
     // "typeRoots": [],                                  /* Specify multiple folders that act like './node_modules/@types'. */
-    // "types": [],                                      /* Specify type package names to be included without being referenced in a source file. */
+    "types": [
+      "node",
+      "reflect-metadata"
+    ] /* Specify type package names to be included without being referenced in a source file. */,
     // "allowUmdGlobalAccess": true,                     /* Allow accessing UMD globals from modules. */
     // "moduleSuffixes": [],                             /* List of file name suffixes to search when resolving a module. */
     "resolveJsonModule": true /* Enable importing .json files. */,
-- 
GitLab