Skip to content

Commit

Permalink
feat(CB2-11778): Updated mysql2 to the latest version (#82)
Browse files Browse the repository at this point in the history
* chore(cb2-11778): updated mysql2 to the latest version

* chore(cb2-11778): updated mysql2 to the latest minor version

* chore(cb2-11778): tidied up git ignore file

---------

Co-authored-by: kristian carr <kristian.carr@bjss.com>
  • Loading branch information
Daniel-Searle and kcarr-bjss authored May 14, 2024
1 parent 6697d02 commit 4381881
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ reports
.vscode/

# Idea specific hidden files
.idea/**
.idea/**
58 changes: 31 additions & 27 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 @@ -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",
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
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

0 comments on commit 4381881

Please sign in to comment.