From 96454326f36300ab6490ecee7d83579f44fc2026 Mon Sep 17 00:00:00 2001 From: kristian carr Date: Thu, 18 Apr 2024 12:20:02 +0100 Subject: [PATCH 1/2] chore(cb2-11778): updated mysql2 to the latest version --- package-lock.json | 64 ++++++++++--------- package.json | 2 +- src/app/databaseService.ts | 15 ++--- src/app/evlFeedQueryFunctionFactory.ts | 3 +- src/app/queries/testResults/index.ts | 5 +- src/infrastructure/api/index.ts | 6 +- src/interfaces/DatabaseService.ts | 2 +- src/utils/logger.ts | 4 +- src/utils/validationService.ts | 5 +- .../infrastructure/databaseService.test.ts | 21 ++++-- tests/unit/utils/validationService.test.ts | 9 +-- 11 files changed, 77 insertions(+), 59 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8aef6d4..e9bddd3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "aws-sdk": "2.857.0", "express": "4.18.2", "moment": "2.29.4", - "mysql2": "^2.2.5", + "mysql2": "3.9.6", "serverless-http": "2.6.0", "source-map-support": "0.5.19", "winston": "^3.7.2", @@ -5604,8 +5604,9 @@ } }, "node_modules/denque": { - "version": "1.5.0", - "license": "Apache-2.0", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", "engines": { "node": ">=0.10" } @@ -10021,8 +10022,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", @@ -10042,6 +10044,7 @@ }, "node_modules/lru-cache": { "version": "6.0.0", + "dev": true, "license": "ISC", "dependencies": { "yallist": "^4.0.0" @@ -10442,15 +10445,16 @@ "license": "ISC" }, "node_modules/mysql2": { - "version": "2.2.5", - "license": "MIT", + "version": "3.9.6", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.9.6.tgz", + "integrity": "sha512-9NYUMLQv6yXnu+5hUh8PZ5CdKoG6VWDzXbojIdTyob8upNZXU3rBNQK9viaEqfgw+LMifhd+53VEZPxZk3bTWA==", "dependencies": { - "denque": "^1.4.1", + "denque": "^2.1.0", "generate-function": "^2.3.1", - "iconv-lite": "^0.6.2", - "long": "^4.0.0", - "lru-cache": "^6.0.0", - "named-placeholders": "^1.1.2", + "iconv-lite": "^0.6.3", + "long": "^5.2.1", + "lru-cache": "^8.0.0", + "named-placeholders": "^1.1.3", "seq-queue": "^0.0.5", "sqlstring": "^2.3.2" }, @@ -10468,28 +10472,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, @@ -11862,10 +11871,6 @@ "dev": true, "license": "MIT" }, - "node_modules/pseudomap": { - "version": "1.0.2", - "license": "ISC" - }, "node_modules/psl": { "version": "1.8.0", "dev": true, @@ -15692,6 +15697,7 @@ }, "node_modules/yallist": { "version": "4.0.0", + "dev": true, "license": "ISC" }, "node_modules/yaml": { diff --git a/package.json b/package.json index 416a6a4..c222be3 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "aws-sdk": "2.857.0", "express": "4.18.2", "moment": "2.29.4", - "mysql2": "^2.2.5", + "mysql2": "3.9.6", "serverless-http": "2.6.0", "source-map-support": "0.5.19", "winston": "^3.7.2", diff --git a/src/app/databaseService.ts b/src/app/databaseService.ts index 8d986c5..763a639 100644 --- a/src/app/databaseService.ts +++ b/src/app/databaseService.ts @@ -56,9 +56,9 @@ async function getVehicleDetails(vehicleDetailsQueryResult: QueryOutput, databas const vehicleDetailsResult = vehicleDetailsQueryResult[0][0] as VehicleQueryResult; if ( - vehicleDetailsResult === undefined || - vehicleDetailsResult.id === undefined || - vehicleDetailsResult.result === undefined + vehicleDetailsResult === undefined + || vehicleDetailsResult.id === undefined + || vehicleDetailsResult.result === undefined ) { throw new NotFoundError('Vehicle was not found'); } @@ -137,9 +137,9 @@ async function getTestResultDetails( const testResultQueryResult = queryResult[0][0] as TestResultQueryResult; if ( - testResultQueryResult === undefined || - testResultQueryResult.id === undefined || - testResultQueryResult.result === undefined + testResultQueryResult === undefined + || testResultQueryResult.id === undefined + || testResultQueryResult.result === undefined ) { throw new NotFoundError('Test not found'); } @@ -221,8 +221,7 @@ function getEvlFeedByVrmDetails(queryResult: QueryOutput): EvlFeedData { } function getFeedDetails(queryResult: QueryOutput, feedName: FeedName): EvlFeedData[] | TflFeedData[] { - const feedQueryResults: EvlFeedData[] | TflFeedData[] = - feedName === FeedName.EVL ? (queryResult[0][1] as EvlFeedData[]) : (queryResult[0] as TflFeedData[]); + const feedQueryResults: EvlFeedData[] | TflFeedData[] = feedName === FeedName.EVL ? (queryResult[0][1] as EvlFeedData[]) : (queryResult[0] as TflFeedData[]); if (feedQueryResults === undefined || feedQueryResults.length === 0) { throw new NotFoundError('No tests found'); } diff --git a/src/app/evlFeedQueryFunctionFactory.ts b/src/app/evlFeedQueryFunctionFactory.ts index 015c4ec..d492d91 100644 --- a/src/app/evlFeedQueryFunctionFactory.ts +++ b/src/app/evlFeedQueryFunctionFactory.ts @@ -9,7 +9,8 @@ export default ( event: EvlEvent, ): | ((databaseService: DatabaseService, event: EvlEvent) => Promise) - | ((databaseService: DatabaseService, feedName: FeedName, event: EvlEvent) => Promise) => { + | ((databaseService: DatabaseService, feedName: FeedName, event: EvlEvent) => Promise + ) => { if (event.vrm_trm) { logger.debug('redirecting to getEVLFeedByVrm using evl factory'); return getEvlFeedByVrm; 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/infrastructure/api/index.ts b/src/infrastructure/api/index.ts index 7c215c0..fde358e 100644 --- a/src/infrastructure/api/index.ts +++ b/src/infrastructure/api/index.ts @@ -135,8 +135,7 @@ router.get( logger.info('Generating EVL File Data'); const evlFeedProcessedData: string = result .map( - (entry) => - `${entry.vrm_trm},${entry.certificateNumber},${moment(entry.testExpiryDate).format('DD-MMM-YYYY')}`, + (entry) => `${entry.vrm_trm},${entry.certificateNumber},${moment(entry.testExpiryDate).format('DD-MMM-YYYY')}`, ) .join('\n'); logger.debug(`\nData captured for file generation: ${evlFeedProcessedData} \n\n`); @@ -180,8 +179,7 @@ router.get('/tfl', (_req, res) => { const processedResult = result.map((entry) => processTFLFeedData(entry)); const tflFeedProcessedData: string = processedResult .map( - (entry) => - `${entry.VRM},${entry.VIN},${entry.SerialNumberOfCertificate},${entry.CertificationModificationType},${entry.TestStatus},${entry.PMEuropeanEmissionClassificationCode},${entry.ValidFromDate},${entry.ExpiryDate},${entry.IssuedBy},${entry.IssueDate}`, + (entry) => `${entry.VRM},${entry.VIN},${entry.SerialNumberOfCertificate},${entry.CertificationModificationType},${entry.TestStatus},${entry.PMEuropeanEmissionClassificationCode},${entry.ValidFromDate},${entry.ExpiryDate},${entry.IssuedBy},${entry.IssueDate}`, ) .join('\n'); logger.debug(`\nData captured for file generation: ${tflFeedProcessedData} \n\n`); 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); }); From 583389e5b843116fc0c351946846166ff1367a70 Mon Sep 17 00:00:00 2001 From: kristian carr Date: Fri, 26 Apr 2024 10:07:30 +0100 Subject: [PATCH 2/2] chore(cb2-11778): updated mysql2 to the latest minor version --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index e9bddd3..0179e40 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "aws-sdk": "2.857.0", "express": "4.18.2", "moment": "2.29.4", - "mysql2": "3.9.6", + "mysql2": "3.9.7", "serverless-http": "2.6.0", "source-map-support": "0.5.19", "winston": "^3.7.2", @@ -10445,9 +10445,9 @@ "license": "ISC" }, "node_modules/mysql2": { - "version": "3.9.6", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.9.6.tgz", - "integrity": "sha512-9NYUMLQv6yXnu+5hUh8PZ5CdKoG6VWDzXbojIdTyob8upNZXU3rBNQK9viaEqfgw+LMifhd+53VEZPxZk3bTWA==", + "version": "3.9.7", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.9.7.tgz", + "integrity": "sha512-KnJT8vYRcNAZv73uf9zpXqNbvBG7DJrs+1nACsjZP1HMJ1TgXEy8wnNilXAn/5i57JizXKtrUtwDB7HxT9DDpw==", "dependencies": { "denque": "^2.1.0", "generate-function": "^2.3.1", diff --git a/package.json b/package.json index c222be3..5d9d946 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "aws-sdk": "2.857.0", "express": "4.18.2", "moment": "2.29.4", - "mysql2": "3.9.6", + "mysql2": "3.9.7", "serverless-http": "2.6.0", "source-map-support": "0.5.19", "winston": "^3.7.2",