diff --git a/.gitignore b/.gitignore index 2ef801f..113380e 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,4 @@ reports .vscode/ # Idea specific hidden files - .idea/** +.idea/** diff --git a/package-lock.json b/package-lock.json index 5fc0585..dbf02c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "aws-lambda": "1.0.6", "express": "4.18.2", "moment": "2.29.4", - "mysql2": "^2.2.5", + "mysql2": "3.9.7", "serverless-http": "2.6.0", "source-map-support": "0.5.19", "winston": "^3.7.2", @@ -12510,8 +12510,9 @@ "license": "MIT" }, "node_modules/long": { - "version": "4.0.0", - "license": "Apache-2.0" + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", + "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==" }, "node_modules/long-timeout": { "version": "0.1.1", @@ -12531,6 +12532,7 @@ }, "node_modules/lru-cache": { "version": "6.0.0", + "dev": true, "license": "ISC", "dependencies": { "yallist": "^4.0.0" @@ -12931,16 +12933,16 @@ "license": "ISC" }, "node_modules/mysql2": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-2.3.3.tgz", - "integrity": "sha512-wxJUev6LgMSgACDkb/InIFxDprRa6T95+VEoR+xPvtngtccNH2dGjEB/fVZ8yg1gWv1510c9CvXuJHi5zUm0ZA==", + "version": "3.9.7", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.9.7.tgz", + "integrity": "sha512-KnJT8vYRcNAZv73uf9zpXqNbvBG7DJrs+1nACsjZP1HMJ1TgXEy8wnNilXAn/5i57JizXKtrUtwDB7HxT9DDpw==", "dependencies": { - "denque": "^2.0.1", + "denque": "^2.1.0", "generate-function": "^2.3.1", "iconv-lite": "^0.6.3", - "long": "^4.0.0", - "lru-cache": "^6.0.0", - "named-placeholders": "^1.1.2", + "long": "^5.2.1", + "lru-cache": "^8.0.0", + "named-placeholders": "^1.1.3", "seq-queue": "^0.0.5", "sqlstring": "^2.3.2" }, @@ -12958,28 +12960,33 @@ "node": ">=0.10.0" } }, + "node_modules/mysql2/node_modules/lru-cache": { + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-8.0.5.tgz", + "integrity": "sha512-MhWWlVnuab1RG5/zMRRcVGXZLCXrZTgfwMikgzCegsPnG62yDQo5JnqKkrK4jO5iKqDAZGItAqN5CtKBCBWRUA==", + "engines": { + "node": ">=16.14" + } + }, "node_modules/named-placeholders": { - "version": "1.1.2", - "license": "MIT", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz", + "integrity": "sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==", "dependencies": { - "lru-cache": "^4.1.3" + "lru-cache": "^7.14.1" }, "engines": { - "node": ">=6.0.0" + "node": ">=12.0.0" } }, "node_modules/named-placeholders/node_modules/lru-cache": { - "version": "4.1.5", - "license": "ISC", - "dependencies": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "engines": { + "node": ">=12" } }, - "node_modules/named-placeholders/node_modules/yallist": { - "version": "2.1.2", - "license": "ISC" - }, "node_modules/nanomatch": { "version": "1.2.13", "dev": true, @@ -14401,10 +14408,6 @@ "dev": true, "license": "MIT" }, - "node_modules/pseudomap": { - "version": "1.0.2", - "license": "ISC" - }, "node_modules/psl": { "version": "1.8.0", "dev": true, @@ -18176,6 +18179,7 @@ }, "node_modules/yallist": { "version": "4.0.0", + "dev": true, "license": "ISC" }, "node_modules/yaml": { diff --git a/package.json b/package.json index f7c6270..2090e9a 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "aws-lambda": "1.0.6", "express": "4.18.2", "moment": "2.29.4", - "mysql2": "^2.2.5", + "mysql2": "3.9.7", "serverless-http": "2.6.0", "source-map-support": "0.5.19", "winston": "^3.7.2", diff --git a/src/app/queries/testResults/index.ts b/src/app/queries/testResults/index.ts index 834ebea..a9c61e3 100644 --- a/src/app/queries/testResults/index.ts +++ b/src/app/queries/testResults/index.ts @@ -1,5 +1,8 @@ import { - TEST_RESULTS_BY_VIN, TEST_RESULTS_BY_VRM, TEST_RESULTS_BY_TRAILER_ID, TEST_RESULTS_BY_TEST_NUMBER, + TEST_RESULTS_BY_VIN, + TEST_RESULTS_BY_VRM, + TEST_RESULTS_BY_TRAILER_ID, + TEST_RESULTS_BY_TEST_NUMBER, } from './testResultQuery'; import TEST_DEFECT_QUERY from './testDefectQuery'; import CUSTOM_DEFECT_QUERY from './customDefectQuery'; diff --git a/src/interfaces/DatabaseService.ts b/src/interfaces/DatabaseService.ts index 9820a57..4d7832f 100644 --- a/src/interfaces/DatabaseService.ts +++ b/src/interfaces/DatabaseService.ts @@ -3,5 +3,5 @@ import { FieldPacket, RowDataPacket } from 'mysql2/promise'; export type QueryOutput = [RowDataPacket[], FieldPacket[]]; export default interface DatabaseService { - get(query: string, params: string[] | undefined): Promise<[RowDataPacket[], FieldPacket[]]> + get(query: string, params: string[] | undefined): Promise<[RowDataPacket[], FieldPacket[]]>; } diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 773cad8..224357f 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -3,9 +3,7 @@ import { createLogger, format, transports } from 'winston'; const { printf } = format; // Checks if log is an error - has stack info -const logFormat = printf((info) => (info.stack - ? `${info.level}: ${info.stack as string}` - : `${info.level}: ${info.message as string}`)); +const logFormat = printf((info) => (info.stack ? `${info.level}: ${info.stack as string}` : `${info.level}: ${info.message as string}`)); const loggerConfig = { level: process.env.LOG_LEVEL || 'info', diff --git a/src/utils/validationService.ts b/src/utils/validationService.ts index 0177e3e..6a079ac 100644 --- a/src/utils/validationService.ts +++ b/src/utils/validationService.ts @@ -46,7 +46,10 @@ const validateResultsEvent = (event: ResultsEvent): boolean => { || (event.VehicleRegMark !== undefined && event.vinNumber !== undefined && event.testnumber !== undefined) || (event.VehicleRegMark !== undefined && event.trailerId !== undefined && event.testnumber !== undefined) || (event.vinNumber !== undefined && event.trailerId !== undefined && event.testnumber !== undefined) - || (event.VehicleRegMark !== undefined && event.vinNumber !== undefined && event.trailerId !== undefined && event.testnumber !== undefined) + || (event.VehicleRegMark !== undefined + && event.vinNumber !== undefined + && event.trailerId !== undefined + && event.testnumber !== undefined) ) { throw new ParametersError('Too many parameters defined'); } diff --git a/tests/unit/infrastructure/databaseService.test.ts b/tests/unit/infrastructure/databaseService.test.ts index 9d0e4dd..f34f25a 100644 --- a/tests/unit/infrastructure/databaseService.test.ts +++ b/tests/unit/infrastructure/databaseService.test.ts @@ -25,15 +25,21 @@ describe('Database Service', () => { }); it('should throw an error when the query fails', async () => { - const mockQuery = jest.fn().mockRejectedValue(new Error()) as (query:string, params:string[] | undefined)=>Promise; - const dbService = new DatabaseService({ query: mockQuery }); + const mockQuery = jest.fn().mockRejectedValue(new Error()) as ( + query: string, + params: string[] | undefined, + ) => Promise; + const dbService = new DatabaseService(({ query: mockQuery })); await expect(dbService.get('sdfsdf', [''])).rejects.toThrow(Error); }); it('adds the expected prefix to the error', async () => { - const mockQuery = jest.fn().mockRejectedValue(new Error()) as (query:string, params:string[] | undefined)=>Promise; - const dbService = new DatabaseService({ query: mockQuery }); + const mockQuery = jest.fn().mockRejectedValue(new Error()) as ( + query: string, + params: string[] | undefined, + ) => Promise; + const dbService = new DatabaseService(({ query: mockQuery })); await expect(dbService.get('sdfsdf', [''])).rejects.toThrowError('Database error: '); }); @@ -52,8 +58,11 @@ describe('Database Service', () => { }); it('returns the response from executing the DB query', async () => { - const mockQuery = jest.fn().mockReturnValue('Success') as (query:string, params:string[] | undefined)=>Promise; - const dbService = new DatabaseService({ query: mockQuery }); + const mockQuery = jest.fn().mockReturnValue('Success') as ( + query: string, + params: string[] | undefined, + ) => Promise; + const dbService = new DatabaseService(({ query: mockQuery })); const response = await dbService.get('sdfsdf', ['']); expect(response).toEqual('Success'); diff --git a/tests/unit/utils/validationService.test.ts b/tests/unit/utils/validationService.test.ts index 5d93fc5..4559400 100644 --- a/tests/unit/utils/validationService.test.ts +++ b/tests/unit/utils/validationService.test.ts @@ -77,9 +77,7 @@ describe('Validation Service', () => { }); it('throws an error if there are too many identifiers (VRM and trailer id)', () => { - expect(() => validateResultsEvent({ VehicleRegMark: 'GL10RFE', trailerId: '2345678' })).toThrow( - ParametersError, - ); + expect(() => validateResultsEvent({ VehicleRegMark: 'GL10RFE', trailerId: '2345678' })).toThrow(ParametersError); }); it('throws an error if there are too many identifiers (trailerId and VIN)', () => { @@ -100,7 +98,10 @@ describe('Validation Service', () => { it('throws an error if there are too many identifiers (all)', () => { expect(() => validateResultsEvent({ - VehicleRegMark: 'GL10RFE', vinNumber: '123534567', trailerId: '2345678', testnumber: '123456789', + VehicleRegMark: 'GL10RFE', + vinNumber: '123534567', + trailerId: '2345678', + testnumber: '123456789', })).toThrow(ParametersError); });