-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cb2-16021): generate ants file (#104)
* feat(cb2-16021): added logic for ants endpoint * feat(cb2-16021): tidied up code * feat(cb2-16021): updated formatting of dates in csv * feat(cb2-16021): added unit tests for ants ep * feat(cb2-16021): further tests for coverage * feat(cb2-16021): further tests for coverage
- Loading branch information
Showing
12 changed files
with
309 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import DatabaseService from "../interfaces/DatabaseService"; | ||
import { FeedName } from "../interfaces/FeedTypes"; | ||
import logger from "../utils/logger"; | ||
import { getFeed } from "./databaseService"; | ||
import AntsFeedData from "../interfaces/queryResults/antsFeedData"; | ||
|
||
export default (): ((databaseService: DatabaseService, feedName: FeedName) => Promise<AntsFeedData[]>) => { | ||
logger.debug('redirecting to getAntsFeed using ants factory'); | ||
return getFeed as (databaseService: DatabaseService, feedName: FeedName) => Promise<AntsFeedData[]>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const ANTS_QUERY = ` | ||
SELECT | ||
vrm_trm, | ||
make, | ||
model, | ||
wheelplan, | ||
test_date, | ||
weight_before_test, | ||
weight_after_test, | ||
DOE_reference, | ||
tech_record_date | ||
FROM vw_dvla_ants | ||
WHERE test_date >= STR_TO_DATE(?, '%d/%m/%Y %T') | ||
ORDER BY test_date ASC;`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export enum FeedName { | ||
EVL = 'EVL', | ||
TFL = 'TFL', | ||
ANTS = 'ANTS', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default interface AntsFeedData { | ||
vrm_trm?: string | undefined; | ||
make?: string | undefined; | ||
model?: string | undefined; | ||
wheelplan?: string | undefined; | ||
test_date?: string | undefined; | ||
weight_before_test?: bigint | undefined; | ||
weight_after_test?: bigint | undefined; | ||
DOE_reference?: string | undefined; | ||
tech_record_date?: string | undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import AntsFeedData from "../interfaces/queryResults/antsFeedData"; | ||
import { escapeString } from "./tflHelpers"; | ||
|
||
export function processAntsFeedData(data: AntsFeedData): AntsFeedData { | ||
return Object.assign( | ||
{}, | ||
...Object.keys(data).map((key) => ({ [key]: escapeString(data[key as keyof AntsFeedData]) })), | ||
) as AntsFeedData; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import queryFunctionFactory from '../../../src/app/antsFeedQueryFunctionFactory'; | ||
import * as dbFunctions from "../../../src/app/databaseService"; | ||
import DatabaseService from "../../../src/infrastructure/databaseService"; | ||
import { FeedName } from "../../../src/interfaces/FeedTypes"; | ||
|
||
jest.mock('../../../src/app/databaseService'); | ||
jest.mock('../../../src/infrastructure/databaseService'); | ||
|
||
const dbFunctionsMock = jest.mocked(dbFunctions); | ||
const dbServiceMock = (jest.mocked(DatabaseService) as unknown) as DatabaseService; | ||
|
||
describe('Query Function Factory', () => { | ||
it('returns the correct function when passed no parameters', () => { | ||
dbFunctionsMock.getFeed = jest.fn().mockReturnValue('Success'); | ||
|
||
const func = queryFunctionFactory(); | ||
|
||
expect(func(dbServiceMock, FeedName.ANTS)).toEqual('Success'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.