From 61fd708a9ce598409560a4b72c405c86019d4300 Mon Sep 17 00:00:00 2001 From: Lawrence Lau Date: Wed, 13 Dec 2023 16:03:06 -0800 Subject: [PATCH 1/9] starting the absolute paths --- express-api/controllers/index.ts | 2 +- express-api/middleware/index.ts | 4 ++-- express-api/tests/integration/health/getHealth.test.ts | 2 +- .../tests/unit/controllers/healthController.test.ts | 2 +- express-api/tsconfig.json | 7 +++++++ 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/express-api/controllers/index.ts b/express-api/controllers/index.ts index e4e52ad3af..1cbd3b5f6d 100644 --- a/express-api/controllers/index.ts +++ b/express-api/controllers/index.ts @@ -1,4 +1,4 @@ -import { healthCheck } from './healthController'; +import { healthCheck } from '@controllers/healthController'; export default { healthCheck, diff --git a/express-api/middleware/index.ts b/express-api/middleware/index.ts index 051d3097c4..7d75ee7aa1 100644 --- a/express-api/middleware/index.ts +++ b/express-api/middleware/index.ts @@ -1,5 +1,5 @@ -import headerHandler from './headerHandler'; -import morganMiddleware from './morganHttpLogging'; +import headerHandler from '@middleware/headerHandler'; +import morganMiddleware from '@middleware/morganHttpLogging'; export default { headerHandler, diff --git a/express-api/tests/integration/health/getHealth.test.ts b/express-api/tests/integration/health/getHealth.test.ts index 08cb29b9b2..4c9ec53748 100644 --- a/express-api/tests/integration/health/getHealth.test.ts +++ b/express-api/tests/integration/health/getHealth.test.ts @@ -1,4 +1,4 @@ -import app from '../../../express'; +import app from 'express'; import supertest from 'supertest'; const request = supertest(app); diff --git a/express-api/tests/unit/controllers/healthController.test.ts b/express-api/tests/unit/controllers/healthController.test.ts index 3e5c1c022a..037e47c28f 100644 --- a/express-api/tests/unit/controllers/healthController.test.ts +++ b/express-api/tests/unit/controllers/healthController.test.ts @@ -1,4 +1,4 @@ -import controllers from '../../../controllers'; +import controllers from '@controllers/index'; import { Request, Response } from 'express'; describe('UNIT - Testing controller for /health routes', () => { diff --git a/express-api/tsconfig.json b/express-api/tsconfig.json index 583f908e4c..79eed8ba0a 100644 --- a/express-api/tsconfig.json +++ b/express-api/tsconfig.json @@ -1,5 +1,12 @@ { "compilerOptions": { + "baseUrl": ".", + "paths": { + "@middleware/*": ["./middleware/*"], + "@controllers/*": ["./controllers/*"], + "@constants/*": ["./constants/*"], + "*": ["./src/*"] // Include a wildcard path for general source files + }, "module": "commonjs", "esModuleInterop": true, "target": "es2022", From 62511236174f738e3976ea34832e56191d9d5684 Mon Sep 17 00:00:00 2001 From: dbarkowsky Date: Wed, 20 Dec 2023 14:18:17 -0800 Subject: [PATCH 2/9] changes to paths... runs locally, not container or tests --- express-api/Dockerfile | 7 +++--- express-api/constants/index.ts | 8 ------ express-api/jest.config.ts | 25 +++++++++++++++---- express-api/package.json | 5 ++-- express-api/routes/index.ts | 9 ------- express-api/{ => src}/appDataSource.ts | 2 +- express-api/src/constants/index.ts | 8 ++++++ express-api/{ => src}/constants/networking.ts | 0 express-api/{ => src}/constants/switches.ts | 0 .../{ => src}/controllers/healthController.ts | 0 express-api/{ => src}/controllers/index.ts | 0 .../{ => src}/controllers/ltsa/ILtsaOrder.ts | 0 .../controllers/ltsa/ltsaController.ts | 2 +- express-api/{ => src}/express.ts | 12 ++++----- .../{ => src}/middleware/headerHandler.ts | 0 express-api/{ => src}/middleware/index.ts | 0 .../middleware/keycloak/keycloakOptions.ts | 2 +- .../{ => src}/middleware/morganHttpLogging.ts | 2 +- express-api/{ => src}/routes/healthRouter.ts | 2 +- express-api/src/routes/index.ts | 9 +++++++ express-api/{ => src}/routes/ltsaRouter.ts | 2 +- express-api/{ => src}/server.ts | 8 +++--- .../{ => src}/swagger/swagger-output.json | 9 +++---- express-api/{ => src}/swagger/swagger.mjs | 0 .../typeorm/utilities/CustomWinstonLogger.ts | 2 +- .../{ => src}/utilities/stubResponse.ts | 0 .../{ => src}/utilities/winstonLogger.ts | 2 +- .../tests/integration/express/express.test.ts | 2 +- .../integration/health/getHealth.test.ts | 2 +- .../tests/integration/ltsa/getLtsa.test.ts | 4 +-- .../middleware/headerHandler.test.ts | 2 +- .../unit/controllers/healthController.test.ts | 2 +- .../controllers/ltsa/ltsaController.test.ts | 2 +- .../keycloak/keycloakOptions.test.ts | 4 +-- .../tests/unit/utilities/stubResponse.test.ts | 2 +- .../unit/utilities/winstonLogger.test.ts | 2 +- express-api/tsconfig.json | 12 ++++++--- 37 files changed, 84 insertions(+), 66 deletions(-) delete mode 100644 express-api/constants/index.ts delete mode 100644 express-api/routes/index.ts rename express-api/{ => src}/appDataSource.ts (90%) create mode 100644 express-api/src/constants/index.ts rename express-api/{ => src}/constants/networking.ts (100%) rename express-api/{ => src}/constants/switches.ts (100%) rename express-api/{ => src}/controllers/healthController.ts (100%) rename express-api/{ => src}/controllers/index.ts (100%) rename express-api/{ => src}/controllers/ltsa/ILtsaOrder.ts (100%) rename express-api/{ => src}/controllers/ltsa/ltsaController.ts (90%) rename express-api/{ => src}/express.ts (84%) rename express-api/{ => src}/middleware/headerHandler.ts (100%) rename express-api/{ => src}/middleware/index.ts (100%) rename express-api/{ => src}/middleware/keycloak/keycloakOptions.ts (87%) rename express-api/{ => src}/middleware/morganHttpLogging.ts (95%) rename express-api/{ => src}/routes/healthRouter.ts (80%) create mode 100644 express-api/src/routes/index.ts rename express-api/{ => src}/routes/ltsaRouter.ts (81%) rename express-api/{ => src}/server.ts (72%) rename express-api/{ => src}/swagger/swagger-output.json (84%) rename express-api/{ => src}/swagger/swagger.mjs (100%) rename express-api/{ => src}/typeorm/utilities/CustomWinstonLogger.ts (96%) rename express-api/{ => src}/utilities/stubResponse.ts (100%) rename express-api/{ => src}/utilities/winstonLogger.ts (94%) diff --git a/express-api/Dockerfile b/express-api/Dockerfile index ff2f6193b9..9117d124fe 100644 --- a/express-api/Dockerfile +++ b/express-api/Dockerfile @@ -13,8 +13,8 @@ ENV CONTAINERIZED=true # Copy files, excluding those in .dockerignore COPY . . -# Install TypeScript. Needed for build process. -RUN npm i -D typescript +# Install packages. Needed for build process. +RUN npm i # Generate swagger-output RUN npm run swagger @@ -34,6 +34,7 @@ ENV NODE_ENV=production ENV CONTAINERIZED=true # Install packages. Needed even for compiled build. +# Only installs non-dev dependencies COPY package.json . RUN npm i @@ -44,5 +45,5 @@ RUN apt-get install -y curl # Copy compiled build from base COPY --from=base /express-api/dist . -CMD [ "node", "server.js" ] +CMD [ "node", "src/server.js" ] diff --git a/express-api/constants/index.ts b/express-api/constants/index.ts deleted file mode 100644 index 4552fdde77..0000000000 --- a/express-api/constants/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import networking from './networking'; -import switches from './switches'; - -const constants = { - ...networking, - ...switches, -}; -export default constants; diff --git a/express-api/jest.config.ts b/express-api/jest.config.ts index 71bacd9b11..cc89a89bca 100644 --- a/express-api/jest.config.ts +++ b/express-api/jest.config.ts @@ -8,16 +8,31 @@ const jestConfig: JestConfigWithTsJest = { 'ts-jest', { // ts-jest configuration goes here + tsconfig: { + baseUrl: "src", + paths: { + "@constants/*": ["src/constants/*"], + "@controllers/*": ["src/controllers/*"], + "@middleware/*": ["src/middleware/*"], + "@routes/*": ["src/routes/*"], + "@swagger/*": ["src/swagger/*"], + "@typeorm/*": ["src/typeorm/*"], + "@utilities/*": ["src/utilities/*"], + "@*": ["src/*"] // Include a wildcard path for general source files + }, + + + } }, ], }, collectCoverage: true, collectCoverageFrom: [ - 'controllers/**/*.ts', - 'middleware/**/*.ts', - 'utilities/**/*.ts', - 'routes/**/*.ts', - 'express.ts', + 'src/controllers/**/*.ts', + 'src/middleware/**/*.ts', + 'src/utilities/**/*.ts', + 'src/routes/**/*.ts', + 'src/express.ts', ], coveragePathIgnorePatterns: ['index.ts'], coverageReporters: [['lcov', { projectRoot: '..' }]], diff --git a/express-api/package.json b/express-api/package.json index 19c98a244a..21af40abc6 100644 --- a/express-api/package.json +++ b/express-api/package.json @@ -4,7 +4,7 @@ "description": "", "main": "server.ts", "scripts": { - "dev": "nodemon --exec ts-node -r dotenv/config server.ts dotenv_config_path=../.env", + "dev": "nodemon --exec ts-node -r tsconfig-paths/register -r dotenv/config ./src/server.ts dotenv_config_path=../.env", "build": "tsc", "lint": "eslint './' --ext .ts,.js", "lint:fix": "npm run lint -- --fix", @@ -14,7 +14,7 @@ "coverage": "jest --coverage", "test:unit": "jest --testPathPattern=/tests/unit", "test:integration": "jest --testPathPattern=/tests/integration", - "swagger": "node ./swagger/swagger.mjs" + "swagger": "node ./src/swagger/swagger.mjs" }, "author": "", "license": "ISC", @@ -57,6 +57,7 @@ "swagger-autogen": "2.23.7", "ts-jest": "29.1.1", "ts-node": "10.9.1", + "tsconfig-paths": "4.2.0", "typescript": "5.2.2" } } diff --git a/express-api/routes/index.ts b/express-api/routes/index.ts deleted file mode 100644 index cbf820d56c..0000000000 --- a/express-api/routes/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import ltsaRouter from './ltsaRouter'; -import healthRouter from './healthRouter'; - -const router = { - healthRouter, - ltsaRouter, -}; - -export default router; diff --git a/express-api/appDataSource.ts b/express-api/src/appDataSource.ts similarity index 90% rename from express-api/appDataSource.ts rename to express-api/src/appDataSource.ts index 67daf5e4d1..44c2ad41eb 100644 --- a/express-api/appDataSource.ts +++ b/express-api/src/appDataSource.ts @@ -1,5 +1,5 @@ import { DataSource } from 'typeorm'; -import { CustomWinstonLogger } from './typeorm/utilities/CustomWinstonLogger'; +import { CustomWinstonLogger } from '@typeorm/utilities/CustomWinstonLogger'; const { POSTGRES_USER, diff --git a/express-api/src/constants/index.ts b/express-api/src/constants/index.ts new file mode 100644 index 0000000000..bc39ae5e55 --- /dev/null +++ b/express-api/src/constants/index.ts @@ -0,0 +1,8 @@ +import networking from '@constants/networking'; +import switches from '@constants/switches'; + +const constants = { + ...networking, + ...switches, +}; +export default constants; diff --git a/express-api/constants/networking.ts b/express-api/src/constants/networking.ts similarity index 100% rename from express-api/constants/networking.ts rename to express-api/src/constants/networking.ts diff --git a/express-api/constants/switches.ts b/express-api/src/constants/switches.ts similarity index 100% rename from express-api/constants/switches.ts rename to express-api/src/constants/switches.ts diff --git a/express-api/controllers/healthController.ts b/express-api/src/controllers/healthController.ts similarity index 100% rename from express-api/controllers/healthController.ts rename to express-api/src/controllers/healthController.ts diff --git a/express-api/controllers/index.ts b/express-api/src/controllers/index.ts similarity index 100% rename from express-api/controllers/index.ts rename to express-api/src/controllers/index.ts diff --git a/express-api/controllers/ltsa/ILtsaOrder.ts b/express-api/src/controllers/ltsa/ILtsaOrder.ts similarity index 100% rename from express-api/controllers/ltsa/ILtsaOrder.ts rename to express-api/src/controllers/ltsa/ILtsaOrder.ts diff --git a/express-api/controllers/ltsa/ltsaController.ts b/express-api/src/controllers/ltsa/ltsaController.ts similarity index 90% rename from express-api/controllers/ltsa/ltsaController.ts rename to express-api/src/controllers/ltsa/ltsaController.ts index 619d08e59d..3c5de40a7d 100644 --- a/express-api/controllers/ltsa/ltsaController.ts +++ b/express-api/src/controllers/ltsa/ltsaController.ts @@ -1,5 +1,5 @@ import { Request, Response } from 'express'; -import { stubResponse } from '../../utilities/stubResponse'; +import { stubResponse } from '@utilities/stubResponse'; /** * @description Used to retrieve property information from LTSA. diff --git a/express-api/express.ts b/express-api/src/express.ts similarity index 84% rename from express-api/express.ts rename to express-api/src/express.ts index fc68a7bcab..67f5906941 100644 --- a/express-api/express.ts +++ b/express-api/src/express.ts @@ -5,12 +5,12 @@ import compression from 'compression'; import cors from 'cors'; import rateLimit from 'express-rate-limit'; import { keycloak, protectedRoute } from '@bcgov/citz-imb-kc-express'; -import router from './routes'; -import middleware from './middleware'; -import constants from './constants'; -import { KEYCLOAK_OPTIONS } from './middleware/keycloak/keycloakOptions'; +import router from '@routes'; +import middleware from '@middleware'; +import constants from '@constants'; +import { KEYCLOAK_OPTIONS } from '@middleware/keycloak/keycloakOptions'; import swaggerUi from 'swagger-ui-express'; -import swaggerJSON from './swagger/swagger-output.json'; +import swaggerJSON from '@swagger/swagger-output.json'; const app: Application = express(); @@ -19,7 +19,7 @@ const { TESTING, FRONTEND_URL } = constants; // Express Rate Limiter Configuration export const limiter = rateLimit({ windowMs: 15 * 60 * 1000, // 15 minutes - max: 1000, // Limit each IP to 100 requests per `window` (here, per 15 minutes) + max: 1000, // Limit each IP to 1000 requests per `window` (here, per 15 minutes) standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers legacyHeaders: false, // Disable the `X-RateLimit-*` headers }); diff --git a/express-api/middleware/headerHandler.ts b/express-api/src/middleware/headerHandler.ts similarity index 100% rename from express-api/middleware/headerHandler.ts rename to express-api/src/middleware/headerHandler.ts diff --git a/express-api/middleware/index.ts b/express-api/src/middleware/index.ts similarity index 100% rename from express-api/middleware/index.ts rename to express-api/src/middleware/index.ts diff --git a/express-api/middleware/keycloak/keycloakOptions.ts b/express-api/src/middleware/keycloak/keycloakOptions.ts similarity index 87% rename from express-api/middleware/keycloak/keycloakOptions.ts rename to express-api/src/middleware/keycloak/keycloakOptions.ts index 564061b4ef..833c0e9c5e 100644 --- a/express-api/middleware/keycloak/keycloakOptions.ts +++ b/express-api/src/middleware/keycloak/keycloakOptions.ts @@ -1,5 +1,5 @@ import { KCOptions, KeycloakUser } from '@bcgov/citz-imb-kc-express'; -import logger from '../../utilities/winstonLogger'; +import logger from '@utilities/winstonLogger'; export const KEYCLOAK_OPTIONS: KCOptions = { afterUserLogin: (user: KeycloakUser) => { diff --git a/express-api/middleware/morganHttpLogging.ts b/express-api/src/middleware/morganHttpLogging.ts similarity index 95% rename from express-api/middleware/morganHttpLogging.ts rename to express-api/src/middleware/morganHttpLogging.ts index 43a16f8167..3f23e84497 100644 --- a/express-api/middleware/morganHttpLogging.ts +++ b/express-api/src/middleware/morganHttpLogging.ts @@ -1,5 +1,5 @@ import morgan from 'morgan'; -import logger from '../utilities/winstonLogger'; +import logger from '@utilities/winstonLogger'; /** * Middleware function that configures Morgan to use a custom logger with the http severity. diff --git a/express-api/routes/healthRouter.ts b/express-api/src/routes/healthRouter.ts similarity index 80% rename from express-api/routes/healthRouter.ts rename to express-api/src/routes/healthRouter.ts index a026422797..3c8757c0fa 100644 --- a/express-api/routes/healthRouter.ts +++ b/express-api/src/routes/healthRouter.ts @@ -1,4 +1,4 @@ -import controllers from '../controllers'; +import controllers from '@controllers'; import express from 'express'; const router = express.Router(); diff --git a/express-api/src/routes/index.ts b/express-api/src/routes/index.ts new file mode 100644 index 0000000000..101e3661ff --- /dev/null +++ b/express-api/src/routes/index.ts @@ -0,0 +1,9 @@ +import ltsaRouter from '@routes/ltsaRouter'; +import healthRouter from '@routes/healthRouter'; + +const router = { + healthRouter, + ltsaRouter, +}; + +export default router; diff --git a/express-api/routes/ltsaRouter.ts b/express-api/src/routes/ltsaRouter.ts similarity index 81% rename from express-api/routes/ltsaRouter.ts rename to express-api/src/routes/ltsaRouter.ts index 0ae3b77d2e..486d56da92 100644 --- a/express-api/routes/ltsaRouter.ts +++ b/express-api/src/routes/ltsaRouter.ts @@ -1,4 +1,4 @@ -import controllers from '../controllers'; +import controllers from '@controllers'; import express from 'express'; const router = express.Router(); diff --git a/express-api/server.ts b/express-api/src/server.ts similarity index 72% rename from express-api/server.ts rename to express-api/src/server.ts index d4f0e11e7a..95dac3d456 100644 --- a/express-api/server.ts +++ b/express-api/src/server.ts @@ -1,7 +1,7 @@ -import logger from './utilities/winstonLogger'; -import constants from './constants'; -import app from './express'; -import { AppDataSource } from './appDataSource'; +import logger from '@utilities/winstonLogger'; +import constants from '@constants'; +import app from '@express'; +import { AppDataSource } from '@appDataSource'; const { API_PORT } = constants; diff --git a/express-api/swagger/swagger-output.json b/express-api/src/swagger/swagger-output.json similarity index 84% rename from express-api/swagger/swagger-output.json rename to express-api/src/swagger/swagger-output.json index 695c6df6ab..af5be45c9a 100644 --- a/express-api/swagger/swagger-output.json +++ b/express-api/src/swagger/swagger-output.json @@ -22,13 +22,10 @@ "paths": { "/health": { "get": { - "tags": [ - "Health" - ], - "description": "Returns a 200 (OK) status if API is reached.", + "description": "", "responses": { - "200": { - "description": "OK" + "default": { + "description": "" } } } diff --git a/express-api/swagger/swagger.mjs b/express-api/src/swagger/swagger.mjs similarity index 100% rename from express-api/swagger/swagger.mjs rename to express-api/src/swagger/swagger.mjs diff --git a/express-api/typeorm/utilities/CustomWinstonLogger.ts b/express-api/src/typeorm/utilities/CustomWinstonLogger.ts similarity index 96% rename from express-api/typeorm/utilities/CustomWinstonLogger.ts rename to express-api/src/typeorm/utilities/CustomWinstonLogger.ts index 4f2347314c..e5d08d6d6f 100644 --- a/express-api/typeorm/utilities/CustomWinstonLogger.ts +++ b/express-api/src/typeorm/utilities/CustomWinstonLogger.ts @@ -1,5 +1,5 @@ import { AbstractLogger, LogLevel, LogMessage } from 'typeorm'; -import logger from '../../utilities/winstonLogger'; +import logger from '@utilities/winstonLogger'; export class CustomWinstonLogger extends AbstractLogger { /** diff --git a/express-api/utilities/stubResponse.ts b/express-api/src/utilities/stubResponse.ts similarity index 100% rename from express-api/utilities/stubResponse.ts rename to express-api/src/utilities/stubResponse.ts diff --git a/express-api/utilities/winstonLogger.ts b/express-api/src/utilities/winstonLogger.ts similarity index 94% rename from express-api/utilities/winstonLogger.ts rename to express-api/src/utilities/winstonLogger.ts index 9aae06ff80..27f4f8dffe 100644 --- a/express-api/utilities/winstonLogger.ts +++ b/express-api/src/utilities/winstonLogger.ts @@ -1,5 +1,5 @@ import { format, createLogger, transports } from 'winston'; -import constants from '../constants'; +import constants from '@constants'; const { timestamp, combine, json } = format; const { TESTING } = constants; diff --git a/express-api/tests/integration/express/express.test.ts b/express-api/tests/integration/express/express.test.ts index f7cf28a041..7f512c0b4c 100644 --- a/express-api/tests/integration/express/express.test.ts +++ b/express-api/tests/integration/express/express.test.ts @@ -1,4 +1,4 @@ -import app, { limiter } from '../../../express'; +import app, { limiter } from '@express'; import supertest from 'supertest'; const request = supertest(app); diff --git a/express-api/tests/integration/health/getHealth.test.ts b/express-api/tests/integration/health/getHealth.test.ts index 4c9ec53748..9236e1ee48 100644 --- a/express-api/tests/integration/health/getHealth.test.ts +++ b/express-api/tests/integration/health/getHealth.test.ts @@ -1,4 +1,4 @@ -import app from 'express'; +import app from '@express'; import supertest from 'supertest'; const request = supertest(app); diff --git a/express-api/tests/integration/ltsa/getLtsa.test.ts b/express-api/tests/integration/ltsa/getLtsa.test.ts index 66fe17af88..bc13cba32e 100644 --- a/express-api/tests/integration/ltsa/getLtsa.test.ts +++ b/express-api/tests/integration/ltsa/getLtsa.test.ts @@ -1,5 +1,5 @@ -import { ILtsaOrder } from '../../../controllers/ltsa/ILtsaOrder'; -import app from '../../../express'; +import { ILtsaOrder } from '@controllers/ltsa/ILtsaOrder'; +import app from '@express'; import supertest from 'supertest'; const request = supertest(app); diff --git a/express-api/tests/integration/middleware/headerHandler.test.ts b/express-api/tests/integration/middleware/headerHandler.test.ts index eeaca198ce..8a1a690fce 100644 --- a/express-api/tests/integration/middleware/headerHandler.test.ts +++ b/express-api/tests/integration/middleware/headerHandler.test.ts @@ -1,4 +1,4 @@ -import app from '../../../express'; +import app from '@express'; import supertest from 'supertest'; const request = supertest(app); diff --git a/express-api/tests/unit/controllers/healthController.test.ts b/express-api/tests/unit/controllers/healthController.test.ts index 037e47c28f..6d234da3a4 100644 --- a/express-api/tests/unit/controllers/healthController.test.ts +++ b/express-api/tests/unit/controllers/healthController.test.ts @@ -1,4 +1,4 @@ -import controllers from '@controllers/index'; +import controllers from '@controllers'; import { Request, Response } from 'express'; describe('UNIT - Testing controller for /health routes', () => { diff --git a/express-api/tests/unit/controllers/ltsa/ltsaController.test.ts b/express-api/tests/unit/controllers/ltsa/ltsaController.test.ts index 42909571d4..859e85c329 100644 --- a/express-api/tests/unit/controllers/ltsa/ltsaController.test.ts +++ b/express-api/tests/unit/controllers/ltsa/ltsaController.test.ts @@ -1,5 +1,5 @@ import { Request, Response } from 'express'; -import controllers from '../../../../controllers'; +import controllers from '@controllers'; describe('UNIT - Testing controllers for /ltsa routes', () => { const mockRequest = { diff --git a/express-api/tests/unit/middleware/keycloak/keycloakOptions.test.ts b/express-api/tests/unit/middleware/keycloak/keycloakOptions.test.ts index 5228371160..bef205c316 100644 --- a/express-api/tests/unit/middleware/keycloak/keycloakOptions.test.ts +++ b/express-api/tests/unit/middleware/keycloak/keycloakOptions.test.ts @@ -1,6 +1,6 @@ import { IdirIdentityProvider } from '@bcgov/citz-imb-kc-express'; -import { KEYCLOAK_OPTIONS } from '../../../../middleware/keycloak/keycloakOptions'; -import logger from '../../../../utilities/winstonLogger'; +import { KEYCLOAK_OPTIONS } from '@middleware/keycloak/keycloakOptions'; +import logger from '@utilities/winstonLogger'; describe('UNIT - Keycloak Options', () => { const user = { diff --git a/express-api/tests/unit/utilities/stubResponse.test.ts b/express-api/tests/unit/utilities/stubResponse.test.ts index d9cab35061..6098189bf8 100644 --- a/express-api/tests/unit/utilities/stubResponse.test.ts +++ b/express-api/tests/unit/utilities/stubResponse.test.ts @@ -1,4 +1,4 @@ -import { stubResponse } from '../../../utilities/stubResponse'; +import { stubResponse } from '@utilities/stubResponse'; import { Response } from 'express'; // TODO: Remove this test, along with the stub controller when all routes are fully implemented. diff --git a/express-api/tests/unit/utilities/winstonLogger.test.ts b/express-api/tests/unit/utilities/winstonLogger.test.ts index 31a97d57b9..b44624efbc 100644 --- a/express-api/tests/unit/utilities/winstonLogger.test.ts +++ b/express-api/tests/unit/utilities/winstonLogger.test.ts @@ -1,4 +1,4 @@ -import logger from '../../../utilities/winstonLogger'; +import logger from '@utilities/winstonLogger'; describe('UNIT - winston logger', () => { it('should be created with the expected settings', () => { diff --git a/express-api/tsconfig.json b/express-api/tsconfig.json index b48fb14020..f75ff98b24 100644 --- a/express-api/tsconfig.json +++ b/express-api/tsconfig.json @@ -2,10 +2,14 @@ "compilerOptions": { "baseUrl": ".", "paths": { - "@middleware/*": ["./middleware/*"], - "@controllers/*": ["./controllers/*"], - "@constants/*": ["./constants/*"], - "*": ["./src/*"] // Include a wildcard path for general source files + "@constants/*": ["src/constants/*"], + "@controllers/*": ["src/controllers/*"], + "@middleware/*": ["src/middleware/*"], + "@routes/*": ["src/routes/*"], + "@swagger/*": ["src/swagger/*"], + "@typeorm/*": ["src/typeorm/*"], + "@utilities/*": ["src/utilities/*"], + "@*": ["src/*"] // Include a wildcard path for general source files }, "module": "commonjs", "esModuleInterop": true, From 02abbd8b46451bde253a7ef81f843da3a1ec0964 Mon Sep 17 00:00:00 2001 From: dbarkowsky Date: Thu, 21 Dec 2023 09:49:51 -0800 Subject: [PATCH 3/9] Changes to make docker build work --- express-api/jest.config.ts | 20 +++++--------------- express-api/package.json | 3 ++- express-api/tsconfig.json | 4 ++-- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/express-api/jest.config.ts b/express-api/jest.config.ts index cc89a89bca..4aa4dbd098 100644 --- a/express-api/jest.config.ts +++ b/express-api/jest.config.ts @@ -1,4 +1,6 @@ import type { JestConfigWithTsJest } from 'ts-jest'; +import { pathsToModuleNameMapper } from 'ts-jest'; +import { compilerOptions } from './tsconfig.json'; const jestConfig: JestConfigWithTsJest = { testEnvironment: 'node', @@ -8,21 +10,6 @@ const jestConfig: JestConfigWithTsJest = { 'ts-jest', { // ts-jest configuration goes here - tsconfig: { - baseUrl: "src", - paths: { - "@constants/*": ["src/constants/*"], - "@controllers/*": ["src/controllers/*"], - "@middleware/*": ["src/middleware/*"], - "@routes/*": ["src/routes/*"], - "@swagger/*": ["src/swagger/*"], - "@typeorm/*": ["src/typeorm/*"], - "@utilities/*": ["src/utilities/*"], - "@*": ["src/*"] // Include a wildcard path for general source files - }, - - - } }, ], }, @@ -48,6 +35,9 @@ const jestConfig: JestConfigWithTsJest = { }, }, randomize: true, // Randomizes order of tests + roots: ['.'], + modulePaths: [compilerOptions.baseUrl], // <-- This will be set to 'baseUrl' value + moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths), }; export default jestConfig; diff --git a/express-api/package.json b/express-api/package.json index 21af40abc6..2f9f24a243 100644 --- a/express-api/package.json +++ b/express-api/package.json @@ -5,7 +5,7 @@ "main": "server.ts", "scripts": { "dev": "nodemon --exec ts-node -r tsconfig-paths/register -r dotenv/config ./src/server.ts dotenv_config_path=../.env", - "build": "tsc", + "build": "tsc && tsc-alias", "lint": "eslint './' --ext .ts,.js", "lint:fix": "npm run lint -- --fix", "format": "prettier --write \"./**/*.{js,ts,json}\"", @@ -57,6 +57,7 @@ "swagger-autogen": "2.23.7", "ts-jest": "29.1.1", "ts-node": "10.9.1", + "tsc-alias": "1.8.8", "tsconfig-paths": "4.2.0", "typescript": "5.2.2" } diff --git a/express-api/tsconfig.json b/express-api/tsconfig.json index f75ff98b24..fca9cb9cb1 100644 --- a/express-api/tsconfig.json +++ b/express-api/tsconfig.json @@ -9,7 +9,7 @@ "@swagger/*": ["src/swagger/*"], "@typeorm/*": ["src/typeorm/*"], "@utilities/*": ["src/utilities/*"], - "@*": ["src/*"] // Include a wildcard path for general source files + "@*": ["src/*"] }, "module": "commonjs", "esModuleInterop": true, @@ -20,7 +20,7 @@ "outDir": "dist", "emitDecoratorMetadata": true, "experimentalDecorators": true, - "resolveJsonModule": true // Used for swagger-output.json + "resolveJsonModule": true }, "include": ["./**/*"] } From 063bb3c7c194a35d078bc894b788ce8fa79f0b7e Mon Sep 17 00:00:00 2001 From: Graham Stewart Date: Thu, 21 Dec 2023 13:43:20 -0800 Subject: [PATCH 4/9] Updated the tsconfig and relevant imports elsewhere to refer to src/ as @approot instead of just @, jest will correctly resolve paths this way. --- express-api/src/express.ts | 6 +++--- express-api/src/routes/healthRouter.ts | 2 +- express-api/src/routes/ltsaRouter.ts | 2 +- express-api/src/utilities/winstonLogger.ts | 2 +- express-api/tests/integration/express/express.test.ts | 2 +- express-api/tests/integration/health/getHealth.test.ts | 2 +- express-api/tests/integration/ltsa/getLtsa.test.ts | 2 +- .../tests/integration/middleware/headerHandler.test.ts | 2 +- express-api/tests/unit/controllers/healthController.test.ts | 2 +- .../tests/unit/controllers/ltsa/ltsaController.test.ts | 2 +- express-api/tsconfig.json | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/express-api/src/express.ts b/express-api/src/express.ts index 67f5906941..58558118d5 100644 --- a/express-api/src/express.ts +++ b/express-api/src/express.ts @@ -5,9 +5,9 @@ import compression from 'compression'; import cors from 'cors'; import rateLimit from 'express-rate-limit'; import { keycloak, protectedRoute } from '@bcgov/citz-imb-kc-express'; -import router from '@routes'; -import middleware from '@middleware'; -import constants from '@constants'; +import router from '@approot/routes'; +import middleware from '@approot/middleware'; +import constants from '@approot/constants'; import { KEYCLOAK_OPTIONS } from '@middleware/keycloak/keycloakOptions'; import swaggerUi from 'swagger-ui-express'; import swaggerJSON from '@swagger/swagger-output.json'; diff --git a/express-api/src/routes/healthRouter.ts b/express-api/src/routes/healthRouter.ts index 3c8757c0fa..77e05d9236 100644 --- a/express-api/src/routes/healthRouter.ts +++ b/express-api/src/routes/healthRouter.ts @@ -1,4 +1,4 @@ -import controllers from '@controllers'; +import controllers from '@approot/controllers'; import express from 'express'; const router = express.Router(); diff --git a/express-api/src/routes/ltsaRouter.ts b/express-api/src/routes/ltsaRouter.ts index 486d56da92..4aa1fb2a52 100644 --- a/express-api/src/routes/ltsaRouter.ts +++ b/express-api/src/routes/ltsaRouter.ts @@ -1,4 +1,4 @@ -import controllers from '@controllers'; +import controllers from '@approot/controllers'; import express from 'express'; const router = express.Router(); diff --git a/express-api/src/utilities/winstonLogger.ts b/express-api/src/utilities/winstonLogger.ts index 27f4f8dffe..ca30e181bc 100644 --- a/express-api/src/utilities/winstonLogger.ts +++ b/express-api/src/utilities/winstonLogger.ts @@ -1,5 +1,5 @@ import { format, createLogger, transports } from 'winston'; -import constants from '@constants'; +import constants from '@approot/constants'; const { timestamp, combine, json } = format; const { TESTING } = constants; diff --git a/express-api/tests/integration/express/express.test.ts b/express-api/tests/integration/express/express.test.ts index 7f512c0b4c..5e71d13689 100644 --- a/express-api/tests/integration/express/express.test.ts +++ b/express-api/tests/integration/express/express.test.ts @@ -1,4 +1,4 @@ -import app, { limiter } from '@express'; +import app, { limiter } from '@approot/express'; import supertest from 'supertest'; const request = supertest(app); diff --git a/express-api/tests/integration/health/getHealth.test.ts b/express-api/tests/integration/health/getHealth.test.ts index 9236e1ee48..a7f9706c5f 100644 --- a/express-api/tests/integration/health/getHealth.test.ts +++ b/express-api/tests/integration/health/getHealth.test.ts @@ -1,4 +1,4 @@ -import app from '@express'; +import app from '@approot/express'; import supertest from 'supertest'; const request = supertest(app); diff --git a/express-api/tests/integration/ltsa/getLtsa.test.ts b/express-api/tests/integration/ltsa/getLtsa.test.ts index bc13cba32e..70f373ace1 100644 --- a/express-api/tests/integration/ltsa/getLtsa.test.ts +++ b/express-api/tests/integration/ltsa/getLtsa.test.ts @@ -1,5 +1,5 @@ import { ILtsaOrder } from '@controllers/ltsa/ILtsaOrder'; -import app from '@express'; +import app from '@approot/express'; import supertest from 'supertest'; const request = supertest(app); diff --git a/express-api/tests/integration/middleware/headerHandler.test.ts b/express-api/tests/integration/middleware/headerHandler.test.ts index 8a1a690fce..4f2e9192e5 100644 --- a/express-api/tests/integration/middleware/headerHandler.test.ts +++ b/express-api/tests/integration/middleware/headerHandler.test.ts @@ -1,4 +1,4 @@ -import app from '@express'; +import app from '@approot/express'; import supertest from 'supertest'; const request = supertest(app); diff --git a/express-api/tests/unit/controllers/healthController.test.ts b/express-api/tests/unit/controllers/healthController.test.ts index 6d234da3a4..5d3278a891 100644 --- a/express-api/tests/unit/controllers/healthController.test.ts +++ b/express-api/tests/unit/controllers/healthController.test.ts @@ -1,4 +1,4 @@ -import controllers from '@controllers'; +import controllers from '@approot/controllers'; import { Request, Response } from 'express'; describe('UNIT - Testing controller for /health routes', () => { diff --git a/express-api/tests/unit/controllers/ltsa/ltsaController.test.ts b/express-api/tests/unit/controllers/ltsa/ltsaController.test.ts index 859e85c329..bee0bdf7c6 100644 --- a/express-api/tests/unit/controllers/ltsa/ltsaController.test.ts +++ b/express-api/tests/unit/controllers/ltsa/ltsaController.test.ts @@ -1,5 +1,5 @@ import { Request, Response } from 'express'; -import controllers from '@controllers'; +import controllers from '@approot/controllers'; describe('UNIT - Testing controllers for /ltsa routes', () => { const mockRequest = { diff --git a/express-api/tsconfig.json b/express-api/tsconfig.json index fca9cb9cb1..6c95485ac2 100644 --- a/express-api/tsconfig.json +++ b/express-api/tsconfig.json @@ -9,7 +9,7 @@ "@swagger/*": ["src/swagger/*"], "@typeorm/*": ["src/typeorm/*"], "@utilities/*": ["src/utilities/*"], - "@*": ["src/*"] + "@approot/*": ["src/*"] }, "module": "commonjs", "esModuleInterop": true, From a31c0d04810822765faf2a08f359390789a9e400 Mon Sep 17 00:00:00 2001 From: dbarkowsky Date: Thu, 21 Dec 2023 14:59:09 -0800 Subject: [PATCH 5/9] exclude express from branch coverage --- express-api/jest.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/express-api/jest.config.ts b/express-api/jest.config.ts index 4aa4dbd098..fd20ef2f04 100644 --- a/express-api/jest.config.ts +++ b/express-api/jest.config.ts @@ -30,7 +30,7 @@ const jestConfig: JestConfigWithTsJest = { lines: 80, statements: 80, }, - 'express.ts': { + 'src/express.ts': { branches: 0, // Because rate limiter is omitted when testing }, }, From 8cc1e091df45a2cd1ecf2ac8dc4bab56a3e33620 Mon Sep 17 00:00:00 2001 From: Graham Stewart Date: Thu, 21 Dec 2023 15:06:29 -0800 Subject: [PATCH 6/9] Fixed absolute imports in server.ts --- express-api/src/server.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/express-api/src/server.ts b/express-api/src/server.ts index 95dac3d456..0bcfd50521 100644 --- a/express-api/src/server.ts +++ b/express-api/src/server.ts @@ -1,7 +1,7 @@ import logger from '@utilities/winstonLogger'; -import constants from '@constants'; -import app from '@express'; -import { AppDataSource } from '@appDataSource'; +import constants from '@approot/constants'; +import app from '@approot/express'; +import { AppDataSource } from '@approot/appDataSource'; const { API_PORT } = constants; From f84eea6118ce826a2d8c2815bd9bdfdb9ce73610 Mon Sep 17 00:00:00 2001 From: dbarkowsky Date: Thu, 28 Dec 2023 13:26:00 -0800 Subject: [PATCH 7/9] simplify path rerouting --- express-api/src/appDataSource.ts | 2 +- express-api/src/constants/index.ts | 4 ++-- express-api/src/controllers/index.ts | 4 ++-- express-api/src/controllers/ltsa/ltsaController.ts | 2 +- express-api/src/express.ts | 10 +++++----- express-api/src/middleware/index.ts | 4 ++-- express-api/src/middleware/keycloak/keycloakOptions.ts | 2 +- express-api/src/middleware/morganHttpLogging.ts | 2 +- express-api/src/routes/healthRouter.ts | 2 +- express-api/src/routes/index.ts | 4 ++-- express-api/src/routes/ltsaRouter.ts | 2 +- express-api/src/server.ts | 8 ++++---- .../src/typeorm/utilities/CustomWinstonLogger.ts | 2 +- express-api/src/utilities/winstonLogger.ts | 2 +- express-api/tests/integration/express/express.test.ts | 2 +- express-api/tests/integration/health/getHealth.test.ts | 2 +- express-api/tests/integration/ltsa/getLtsa.test.ts | 4 ++-- .../tests/integration/middleware/headerHandler.test.ts | 2 +- .../tests/unit/controllers/healthController.test.ts | 2 +- .../tests/unit/controllers/ltsa/ltsaController.test.ts | 2 +- .../unit/middleware/keycloak/keycloakOptions.test.ts | 4 ++-- express-api/tests/unit/utilities/stubResponse.test.ts | 2 +- express-api/tests/unit/utilities/winstonLogger.test.ts | 2 +- express-api/tsconfig.json | 9 +-------- 24 files changed, 37 insertions(+), 44 deletions(-) diff --git a/express-api/src/appDataSource.ts b/express-api/src/appDataSource.ts index 44c2ad41eb..3a2c64ee2f 100644 --- a/express-api/src/appDataSource.ts +++ b/express-api/src/appDataSource.ts @@ -1,5 +1,5 @@ import { DataSource } from 'typeorm'; -import { CustomWinstonLogger } from '@typeorm/utilities/CustomWinstonLogger'; +import { CustomWinstonLogger } from '@/typeorm/utilities/CustomWinstonLogger'; const { POSTGRES_USER, diff --git a/express-api/src/constants/index.ts b/express-api/src/constants/index.ts index bc39ae5e55..eb2b3d6815 100644 --- a/express-api/src/constants/index.ts +++ b/express-api/src/constants/index.ts @@ -1,5 +1,5 @@ -import networking from '@constants/networking'; -import switches from '@constants/switches'; +import networking from '@/constants/networking'; +import switches from '@/constants/switches'; const constants = { ...networking, diff --git a/express-api/src/controllers/index.ts b/express-api/src/controllers/index.ts index 33870484ba..faf829221f 100644 --- a/express-api/src/controllers/index.ts +++ b/express-api/src/controllers/index.ts @@ -1,5 +1,5 @@ -import { healthCheck } from '@controllers/healthController'; -import * as ltsa from '@controllers/ltsa/ltsaController'; +import { healthCheck } from '@/controllers/healthController'; +import * as ltsa from '@/controllers/ltsa/ltsaController'; export default { healthCheck, diff --git a/express-api/src/controllers/ltsa/ltsaController.ts b/express-api/src/controllers/ltsa/ltsaController.ts index 3c5de40a7d..cff9007237 100644 --- a/express-api/src/controllers/ltsa/ltsaController.ts +++ b/express-api/src/controllers/ltsa/ltsaController.ts @@ -1,5 +1,5 @@ import { Request, Response } from 'express'; -import { stubResponse } from '@utilities/stubResponse'; +import { stubResponse } from '@/utilities/stubResponse'; /** * @description Used to retrieve property information from LTSA. diff --git a/express-api/src/express.ts b/express-api/src/express.ts index 58558118d5..e1713486bd 100644 --- a/express-api/src/express.ts +++ b/express-api/src/express.ts @@ -5,12 +5,12 @@ import compression from 'compression'; import cors from 'cors'; import rateLimit from 'express-rate-limit'; import { keycloak, protectedRoute } from '@bcgov/citz-imb-kc-express'; -import router from '@approot/routes'; -import middleware from '@approot/middleware'; -import constants from '@approot/constants'; -import { KEYCLOAK_OPTIONS } from '@middleware/keycloak/keycloakOptions'; +import router from '@/routes'; +import middleware from '@/middleware'; +import constants from '@/constants'; +import { KEYCLOAK_OPTIONS } from '@/middleware/keycloak/keycloakOptions'; import swaggerUi from 'swagger-ui-express'; -import swaggerJSON from '@swagger/swagger-output.json'; +import swaggerJSON from '@/swagger/swagger-output.json'; const app: Application = express(); diff --git a/express-api/src/middleware/index.ts b/express-api/src/middleware/index.ts index 7d75ee7aa1..6309f6bd15 100644 --- a/express-api/src/middleware/index.ts +++ b/express-api/src/middleware/index.ts @@ -1,5 +1,5 @@ -import headerHandler from '@middleware/headerHandler'; -import morganMiddleware from '@middleware/morganHttpLogging'; +import headerHandler from '@/middleware/headerHandler'; +import morganMiddleware from '@/middleware/morganHttpLogging'; export default { headerHandler, diff --git a/express-api/src/middleware/keycloak/keycloakOptions.ts b/express-api/src/middleware/keycloak/keycloakOptions.ts index 833c0e9c5e..24e54decde 100644 --- a/express-api/src/middleware/keycloak/keycloakOptions.ts +++ b/express-api/src/middleware/keycloak/keycloakOptions.ts @@ -1,5 +1,5 @@ import { KCOptions, KeycloakUser } from '@bcgov/citz-imb-kc-express'; -import logger from '@utilities/winstonLogger'; +import logger from '@/utilities/winstonLogger'; export const KEYCLOAK_OPTIONS: KCOptions = { afterUserLogin: (user: KeycloakUser) => { diff --git a/express-api/src/middleware/morganHttpLogging.ts b/express-api/src/middleware/morganHttpLogging.ts index 3f23e84497..68aa86e459 100644 --- a/express-api/src/middleware/morganHttpLogging.ts +++ b/express-api/src/middleware/morganHttpLogging.ts @@ -1,5 +1,5 @@ import morgan from 'morgan'; -import logger from '@utilities/winstonLogger'; +import logger from '@/utilities/winstonLogger'; /** * Middleware function that configures Morgan to use a custom logger with the http severity. diff --git a/express-api/src/routes/healthRouter.ts b/express-api/src/routes/healthRouter.ts index 77e05d9236..703192e522 100644 --- a/express-api/src/routes/healthRouter.ts +++ b/express-api/src/routes/healthRouter.ts @@ -1,4 +1,4 @@ -import controllers from '@approot/controllers'; +import controllers from '@/controllers'; import express from 'express'; const router = express.Router(); diff --git a/express-api/src/routes/index.ts b/express-api/src/routes/index.ts index 101e3661ff..92969c7e22 100644 --- a/express-api/src/routes/index.ts +++ b/express-api/src/routes/index.ts @@ -1,5 +1,5 @@ -import ltsaRouter from '@routes/ltsaRouter'; -import healthRouter from '@routes/healthRouter'; +import ltsaRouter from '@/routes/ltsaRouter'; +import healthRouter from '@/routes/healthRouter'; const router = { healthRouter, diff --git a/express-api/src/routes/ltsaRouter.ts b/express-api/src/routes/ltsaRouter.ts index 4aa1fb2a52..47e04c138b 100644 --- a/express-api/src/routes/ltsaRouter.ts +++ b/express-api/src/routes/ltsaRouter.ts @@ -1,4 +1,4 @@ -import controllers from '@approot/controllers'; +import controllers from '@/controllers'; import express from 'express'; const router = express.Router(); diff --git a/express-api/src/server.ts b/express-api/src/server.ts index 0bcfd50521..476df87b1d 100644 --- a/express-api/src/server.ts +++ b/express-api/src/server.ts @@ -1,7 +1,7 @@ -import logger from '@utilities/winstonLogger'; -import constants from '@approot/constants'; -import app from '@approot/express'; -import { AppDataSource } from '@approot/appDataSource'; +import logger from '@/utilities/winstonLogger'; +import constants from '@/constants'; +import app from '@/express'; +import { AppDataSource } from '@/appDataSource'; const { API_PORT } = constants; diff --git a/express-api/src/typeorm/utilities/CustomWinstonLogger.ts b/express-api/src/typeorm/utilities/CustomWinstonLogger.ts index e5d08d6d6f..d30d9489e7 100644 --- a/express-api/src/typeorm/utilities/CustomWinstonLogger.ts +++ b/express-api/src/typeorm/utilities/CustomWinstonLogger.ts @@ -1,5 +1,5 @@ import { AbstractLogger, LogLevel, LogMessage } from 'typeorm'; -import logger from '@utilities/winstonLogger'; +import logger from '@/utilities/winstonLogger'; export class CustomWinstonLogger extends AbstractLogger { /** diff --git a/express-api/src/utilities/winstonLogger.ts b/express-api/src/utilities/winstonLogger.ts index ca30e181bc..b4b22940e3 100644 --- a/express-api/src/utilities/winstonLogger.ts +++ b/express-api/src/utilities/winstonLogger.ts @@ -1,5 +1,5 @@ import { format, createLogger, transports } from 'winston'; -import constants from '@approot/constants'; +import constants from '@/constants'; const { timestamp, combine, json } = format; const { TESTING } = constants; diff --git a/express-api/tests/integration/express/express.test.ts b/express-api/tests/integration/express/express.test.ts index 5e71d13689..f311e00136 100644 --- a/express-api/tests/integration/express/express.test.ts +++ b/express-api/tests/integration/express/express.test.ts @@ -1,4 +1,4 @@ -import app, { limiter } from '@approot/express'; +import app, { limiter } from '@/express'; import supertest from 'supertest'; const request = supertest(app); diff --git a/express-api/tests/integration/health/getHealth.test.ts b/express-api/tests/integration/health/getHealth.test.ts index a7f9706c5f..666b617626 100644 --- a/express-api/tests/integration/health/getHealth.test.ts +++ b/express-api/tests/integration/health/getHealth.test.ts @@ -1,4 +1,4 @@ -import app from '@approot/express'; +import app from '@/express'; import supertest from 'supertest'; const request = supertest(app); diff --git a/express-api/tests/integration/ltsa/getLtsa.test.ts b/express-api/tests/integration/ltsa/getLtsa.test.ts index 70f373ace1..9b183f41e8 100644 --- a/express-api/tests/integration/ltsa/getLtsa.test.ts +++ b/express-api/tests/integration/ltsa/getLtsa.test.ts @@ -1,5 +1,5 @@ -import { ILtsaOrder } from '@controllers/ltsa/ILtsaOrder'; -import app from '@approot/express'; +import { ILtsaOrder } from '@/controllers/ltsa/ILtsaOrder'; +import app from '@/express'; import supertest from 'supertest'; const request = supertest(app); diff --git a/express-api/tests/integration/middleware/headerHandler.test.ts b/express-api/tests/integration/middleware/headerHandler.test.ts index 4f2e9192e5..ed9cee4e53 100644 --- a/express-api/tests/integration/middleware/headerHandler.test.ts +++ b/express-api/tests/integration/middleware/headerHandler.test.ts @@ -1,4 +1,4 @@ -import app from '@approot/express'; +import app from '@/express'; import supertest from 'supertest'; const request = supertest(app); diff --git a/express-api/tests/unit/controllers/healthController.test.ts b/express-api/tests/unit/controllers/healthController.test.ts index 5d3278a891..65b605bbe9 100644 --- a/express-api/tests/unit/controllers/healthController.test.ts +++ b/express-api/tests/unit/controllers/healthController.test.ts @@ -1,4 +1,4 @@ -import controllers from '@approot/controllers'; +import controllers from '@/controllers'; import { Request, Response } from 'express'; describe('UNIT - Testing controller for /health routes', () => { diff --git a/express-api/tests/unit/controllers/ltsa/ltsaController.test.ts b/express-api/tests/unit/controllers/ltsa/ltsaController.test.ts index bee0bdf7c6..06337cb458 100644 --- a/express-api/tests/unit/controllers/ltsa/ltsaController.test.ts +++ b/express-api/tests/unit/controllers/ltsa/ltsaController.test.ts @@ -1,5 +1,5 @@ import { Request, Response } from 'express'; -import controllers from '@approot/controllers'; +import controllers from '@/controllers'; describe('UNIT - Testing controllers for /ltsa routes', () => { const mockRequest = { diff --git a/express-api/tests/unit/middleware/keycloak/keycloakOptions.test.ts b/express-api/tests/unit/middleware/keycloak/keycloakOptions.test.ts index bef205c316..8c4466e2f8 100644 --- a/express-api/tests/unit/middleware/keycloak/keycloakOptions.test.ts +++ b/express-api/tests/unit/middleware/keycloak/keycloakOptions.test.ts @@ -1,6 +1,6 @@ import { IdirIdentityProvider } from '@bcgov/citz-imb-kc-express'; -import { KEYCLOAK_OPTIONS } from '@middleware/keycloak/keycloakOptions'; -import logger from '@utilities/winstonLogger'; +import { KEYCLOAK_OPTIONS } from '@/middleware/keycloak/keycloakOptions'; +import logger from '@/utilities/winstonLogger'; describe('UNIT - Keycloak Options', () => { const user = { diff --git a/express-api/tests/unit/utilities/stubResponse.test.ts b/express-api/tests/unit/utilities/stubResponse.test.ts index 6098189bf8..27c18e8d40 100644 --- a/express-api/tests/unit/utilities/stubResponse.test.ts +++ b/express-api/tests/unit/utilities/stubResponse.test.ts @@ -1,4 +1,4 @@ -import { stubResponse } from '@utilities/stubResponse'; +import { stubResponse } from '@/utilities/stubResponse'; import { Response } from 'express'; // TODO: Remove this test, along with the stub controller when all routes are fully implemented. diff --git a/express-api/tests/unit/utilities/winstonLogger.test.ts b/express-api/tests/unit/utilities/winstonLogger.test.ts index b44624efbc..9364000b20 100644 --- a/express-api/tests/unit/utilities/winstonLogger.test.ts +++ b/express-api/tests/unit/utilities/winstonLogger.test.ts @@ -1,4 +1,4 @@ -import logger from '@utilities/winstonLogger'; +import logger from '@/utilities/winstonLogger'; describe('UNIT - winston logger', () => { it('should be created with the expected settings', () => { diff --git a/express-api/tsconfig.json b/express-api/tsconfig.json index 6c95485ac2..9c5daa16c7 100644 --- a/express-api/tsconfig.json +++ b/express-api/tsconfig.json @@ -2,14 +2,7 @@ "compilerOptions": { "baseUrl": ".", "paths": { - "@constants/*": ["src/constants/*"], - "@controllers/*": ["src/controllers/*"], - "@middleware/*": ["src/middleware/*"], - "@routes/*": ["src/routes/*"], - "@swagger/*": ["src/swagger/*"], - "@typeorm/*": ["src/typeorm/*"], - "@utilities/*": ["src/utilities/*"], - "@approot/*": ["src/*"] + "@/*": ["src/*"] }, "module": "commonjs", "esModuleInterop": true, From 81af5981a6249892cc887ce9c578d3d278e62a46 Mon Sep 17 00:00:00 2001 From: dbarkowsky Date: Thu, 28 Dec 2023 13:51:26 -0800 Subject: [PATCH 8/9] Update paths from merged code --- express-api/controllers/index.ts | 9 --------- express-api/routes/index.ts | 11 ----------- express-api/src/controllers/index.ts | 2 ++ express-api/{ => src}/controllers/parcels/IParcel.ts | 0 .../controllers/parcels/parcelsController.ts | 2 +- express-api/src/routes/index.ts | 2 ++ express-api/src/routes/parcelsRouter.ts | 2 +- express-api/tests/integration/parcels/parcels.test.ts | 4 ++-- .../controllers/parcels/parcelsController.test.ts | 4 ++-- 9 files changed, 10 insertions(+), 26 deletions(-) delete mode 100644 express-api/controllers/index.ts delete mode 100644 express-api/routes/index.ts rename express-api/{ => src}/controllers/parcels/IParcel.ts (100%) rename express-api/{ => src}/controllers/parcels/parcelsController.ts (98%) diff --git a/express-api/controllers/index.ts b/express-api/controllers/index.ts deleted file mode 100644 index 3aae4c7b19..0000000000 --- a/express-api/controllers/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { healthCheck } from './healthController'; -import * as ltsa from './ltsa/ltsaController'; -import * as parcels from './parcels/parcelsController'; - -export default { - healthCheck, - ...ltsa, - ...parcels, -}; diff --git a/express-api/routes/index.ts b/express-api/routes/index.ts deleted file mode 100644 index 8845627fc2..0000000000 --- a/express-api/routes/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ltsaRouter from './ltsaRouter'; -import healthRouter from './healthRouter'; -import parcelsRouter from './parcelsRouter'; - -const router = { - healthRouter, - ltsaRouter, - parcelsRouter, -}; - -export default router; diff --git a/express-api/src/controllers/index.ts b/express-api/src/controllers/index.ts index faf829221f..6f8ecd0857 100644 --- a/express-api/src/controllers/index.ts +++ b/express-api/src/controllers/index.ts @@ -1,7 +1,9 @@ import { healthCheck } from '@/controllers/healthController'; import * as ltsa from '@/controllers/ltsa/ltsaController'; +import * as parcels from '@/controllers/parcels/parcelsController'; export default { healthCheck, ...ltsa, + ...parcels, }; diff --git a/express-api/controllers/parcels/IParcel.ts b/express-api/src/controllers/parcels/IParcel.ts similarity index 100% rename from express-api/controllers/parcels/IParcel.ts rename to express-api/src/controllers/parcels/IParcel.ts diff --git a/express-api/controllers/parcels/parcelsController.ts b/express-api/src/controllers/parcels/parcelsController.ts similarity index 98% rename from express-api/controllers/parcels/parcelsController.ts rename to express-api/src/controllers/parcels/parcelsController.ts index b4e0fd4b7e..49db3e7989 100644 --- a/express-api/controllers/parcels/parcelsController.ts +++ b/express-api/src/controllers/parcels/parcelsController.ts @@ -1,5 +1,5 @@ import { Request, Response } from 'express'; -import { stubResponse } from '../../utilities/stubResponse'; +import { stubResponse } from '@/utilities/stubResponse'; /** * @description Gets information about a particular parcel by the Id provided in the URL parameter. diff --git a/express-api/src/routes/index.ts b/express-api/src/routes/index.ts index 92969c7e22..eaa7ff56b1 100644 --- a/express-api/src/routes/index.ts +++ b/express-api/src/routes/index.ts @@ -1,9 +1,11 @@ import ltsaRouter from '@/routes/ltsaRouter'; import healthRouter from '@/routes/healthRouter'; +import parcelsRouter from '@/routes/parcelsRouter'; const router = { healthRouter, ltsaRouter, + parcelsRouter, }; export default router; diff --git a/express-api/src/routes/parcelsRouter.ts b/express-api/src/routes/parcelsRouter.ts index 6b91d00fce..616732fab3 100644 --- a/express-api/src/routes/parcelsRouter.ts +++ b/express-api/src/routes/parcelsRouter.ts @@ -1,4 +1,4 @@ -import controllers from '../controllers'; +import controllers from '@/controllers'; import express from 'express'; export const PARCELS_ROUTE = '/properties/parcels'; diff --git a/express-api/tests/integration/parcels/parcels.test.ts b/express-api/tests/integration/parcels/parcels.test.ts index b85a6081e4..528d6db3f9 100644 --- a/express-api/tests/integration/parcels/parcels.test.ts +++ b/express-api/tests/integration/parcels/parcels.test.ts @@ -1,7 +1,7 @@ import supertest from 'supertest'; -import app from '../../../express'; +import app from '@/express'; import { faker } from '@faker-js/faker'; -import { IParcel } from '../../../controllers/parcels/IParcel'; +import { IParcel } from '@/controllers/parcels/IParcel'; const request = supertest(app); const API_PATH = '/api/v2/properties/parcels'; diff --git a/express-api/tests/unit/controllers/parcels/parcelsController.test.ts b/express-api/tests/unit/controllers/parcels/parcelsController.test.ts index 84b582735a..e1b6a8f5f6 100644 --- a/express-api/tests/unit/controllers/parcels/parcelsController.test.ts +++ b/express-api/tests/unit/controllers/parcels/parcelsController.test.ts @@ -1,6 +1,6 @@ -import { IParcel } from '../../../../controllers/parcels/IParcel'; +import { IParcel } from '@/controllers/parcels/IParcel'; import { faker } from '@faker-js/faker'; -import controllers from '../../../../controllers'; +import controllers from '@/controllers'; import { Request, Response } from 'express'; import { MockReq, MockRes, getRequestHandlerMocks } from '../../../testUtils/factories'; From 2135b7d94758e7db9ef7093a49472390e8fc3fae Mon Sep 17 00:00:00 2001 From: dbarkowsky Date: Fri, 29 Dec 2023 08:24:42 -0800 Subject: [PATCH 9/9] update swaggerdocs --- express-api/src/swagger/swagger-output.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/express-api/src/swagger/swagger-output.json b/express-api/src/swagger/swagger-output.json index bafbbc411d..ca8e115264 100644 --- a/express-api/src/swagger/swagger-output.json +++ b/express-api/src/swagger/swagger-output.json @@ -22,10 +22,13 @@ "paths": { "/health": { "get": { - "description": "", + "tags": [ + "Health" + ], + "description": "Returns a 200 (OK) status if API is reached.", "responses": { - "default": { - "description": "" + "200": { + "description": "OK" } } }