Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cb2-11778): updated mysql2 to the latest version #79

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 35 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"aws-sdk": "2.857.0",
"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",
Expand Down
15 changes: 7 additions & 8 deletions src/app/databaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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');
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/evlFeedQueryFunctionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export default (
event: EvlEvent,
):
| ((databaseService: DatabaseService, event: EvlEvent) => Promise<EvlFeedData[]>)
| ((databaseService: DatabaseService, feedName: FeedName, event: EvlEvent) => Promise<EvlFeedData[]>) => {
| ((databaseService: DatabaseService, feedName: FeedName, event: EvlEvent) => Promise<EvlFeedData[]>
) => {
if (event.vrm_trm) {
logger.debug('redirecting to getEVLFeedByVrm using evl factory');
return getEvlFeedByVrm;
Expand Down
5 changes: 4 additions & 1 deletion src/app/queries/testResults/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
6 changes: 2 additions & 4 deletions src/infrastructure/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down Expand Up @@ -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`);
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/DatabaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]]>;
}
4 changes: 1 addition & 3 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion src/utils/validationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
21 changes: 15 additions & 6 deletions tests/unit/infrastructure/databaseService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<QueryOutput>;
const dbService = new DatabaseService(<mysqlp.Pool><unknown>{ query: mockQuery });
const mockQuery = jest.fn().mockRejectedValue(new Error()) as (
query: string,
params: string[] | undefined,
) => Promise<QueryOutput>;
const dbService = new DatabaseService(<mysqlp.Pool>(<unknown>{ 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<QueryOutput>;
const dbService = new DatabaseService(<mysqlp.Pool><unknown>{ query: mockQuery });
const mockQuery = jest.fn().mockRejectedValue(new Error()) as (
query: string,
params: string[] | undefined,
) => Promise<QueryOutput>;
const dbService = new DatabaseService(<mysqlp.Pool>(<unknown>{ query: mockQuery }));

await expect(dbService.get('sdfsdf', [''])).rejects.toThrowError('Database error: ');
});
Expand All @@ -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<QueryOutput>;
const dbService = new DatabaseService(<mysqlp.Pool><unknown>{ query: mockQuery });
const mockQuery = jest.fn().mockReturnValue('Success') as (
query: string,
params: string[] | undefined,
) => Promise<QueryOutput>;
const dbService = new DatabaseService(<mysqlp.Pool>(<unknown>{ query: mockQuery }));
const response = await dbService.get('sdfsdf', ['']);

expect(response).toEqual('Success');
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/utils/validationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)', () => {
Expand All @@ -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);
});

Expand Down