-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement yymmdd to yyyymmdd Date Conversion Method and Monorep…
…o Testing Structure (#53)
- Loading branch information
1 parent
486406c
commit 27c0a5f
Showing
14 changed files
with
214 additions
and
24 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,19 @@ | ||
import type { Config } from '@jest/types' | ||
|
||
const config: Config.InitialOptions = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
coveragePathIgnorePatterns: ['/build/', '/node_modules/', '/__tests__/', 'tests'], | ||
coverageDirectory: '<rootDir>/coverage/', | ||
testMatch: ['**/?(*.)+(spec|test).[tj]s?(x)'], | ||
transform: { | ||
'^.+\\.tsx?$': [ | ||
'ts-jest', | ||
{ | ||
isolatedModules: true, | ||
}, | ||
], | ||
}, | ||
} | ||
|
||
export default config |
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 @@ | ||
import type { Config } from '@jest/types' | ||
|
||
import base from './jest.config.base' | ||
|
||
const config: Config.InitialOptions = { | ||
...base, | ||
roots: ['<rootDir>'], | ||
projects: ['<rootDir>/packages/*'], | ||
} | ||
|
||
export default config |
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,12 @@ | ||
import type { Config } from '@jest/types' | ||
|
||
import base from '../../jest.config.base' | ||
|
||
import packageJson from './package.json' | ||
|
||
const config: Config.InitialOptions = { | ||
...base, | ||
displayName: packageJson.name, | ||
} | ||
|
||
export default config |
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,12 @@ | ||
import type { Config } from '@jest/types' | ||
|
||
import base from '../../jest.config.base' | ||
|
||
import packageJson from './package.json' | ||
|
||
const config: Config.InitialOptions = { | ||
...base, | ||
displayName: packageJson.name, | ||
} | ||
|
||
export default config |
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,12 @@ | ||
import type { Config } from '@jest/types' | ||
|
||
import base from '../../jest.config.base' | ||
|
||
import packageJson from './package.json' | ||
|
||
const config: Config.InitialOptions = { | ||
...base, | ||
displayName: packageJson.name, | ||
} | ||
|
||
export default config |
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,3 +1,4 @@ | ||
export * from './messages' | ||
export * from './events' | ||
export * from './types' | ||
export * from './utils' |
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,48 @@ | ||
/** | ||
* Converts a Machine Readable Travel Document (MRTD) date in the format `YYMMDD` to a complete | ||
* `YYYYMMDD` date format, taking into account the current century. | ||
* | ||
* **Note:** This method is limited to interpreting dates based on the current year. | ||
* It may not handle dates correctly for years beyond the range determined by the | ||
* current century (e.g., for dates after 2050 when the current year is in the 21st century). | ||
* | ||
* @param {string} date - The MRTD date string in the format `YYMMDD`. | ||
* @param {boolean} isExpirationDate - A boolean flag indicating whether the date is an expiration date. | ||
* @returns {string} - The converted date in the format `YYYYMMDD`, or the original input | ||
* if the input is not a valid `YYMMDD` date. | ||
* | ||
* @example | ||
* // Current year: 2024 | ||
* convertMRTDDate("240101"); // Returns "20240101" | ||
* convertMRTDDate("991231"); // Returns "19991231" | ||
* convertMRTDDate("abcd12"); // Returns "abcd12" (invalid input) | ||
*/ | ||
export function convertShortDate(date: string | null | undefined, isExpirationDate: boolean) { | ||
if (!date || !/^\d{6}$/.test(date)) return date ?? undefined | ||
|
||
const currentYear = new Date().getFullYear() | ||
const currentCentury = Math.floor(currentYear / 100) | ||
const year = parseInt(date.slice(0, 2), 10) | ||
const month = date.slice(2, 4) | ||
const day = date.slice(4, 6) | ||
|
||
let fullYear: number | ||
|
||
if (isExpirationDate) { | ||
if (year <= currentYear % 100) { | ||
fullYear = currentCentury * 100 + year | ||
if (fullYear < currentYear) { | ||
fullYear += 100 | ||
} | ||
} else { | ||
fullYear = currentCentury * 100 + year | ||
} | ||
} else { | ||
if (year <= currentYear % 100) { | ||
fullYear = currentCentury * 100 + year | ||
} else { | ||
fullYear = (currentCentury - 1) * 100 + year | ||
} | ||
} | ||
return `${fullYear}${month}${day}` | ||
} |
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 @@ | ||
export * from './dateUtils' |
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,60 @@ | ||
import { | ||
DecodedAdditionalPersonalData, | ||
DecodedImage, | ||
DecodedSecurtyObjectOfDocument, | ||
} from '@li0ard/tsemrtd/dist/consts/interfaces' | ||
|
||
import { EMrtdDataSubmitMessage, MrtdSubmitState } from '../src/messages' | ||
|
||
describe('EMrtdDataSubmitMessage', () => { | ||
let securityObjectOfDocument: DecodedSecurtyObjectOfDocument | ||
let additionalPersonalData: DecodedAdditionalPersonalData | ||
let image: DecodedImage | ||
it('should initialize with correct type and state', () => { | ||
const rawMock = { someKey: 'someValue' } | ||
const parsedMock = { | ||
fields: { | ||
com: { | ||
ldsVersion: '1.7', | ||
unicodeVersion: '9.0', | ||
tags: Buffer.from('tagsData'), | ||
}, | ||
mrzData: 'P<COLDOE<<JOHN<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<BC123456<2COL9001011M3005103CC12345678<<<<04', | ||
images: [ | ||
{ | ||
...image, | ||
imageType: 1, | ||
imageData: Buffer.from('faceImage1'), | ||
}, | ||
], | ||
additionalPersonalData: { | ||
...additionalPersonalData, | ||
nameOfHolder: 'John Doe', | ||
fullDateOfBirth: 19900101, | ||
}, | ||
securityObjectOfDocument, | ||
}, | ||
valid: true, | ||
} | ||
|
||
const message = new EMrtdDataSubmitMessage({ | ||
id: '123', | ||
threadId: '456', | ||
timestamp: new Date(), | ||
connectionId: 'conn-1', | ||
state: MrtdSubmitState.Submitted, | ||
dataGroups: { raw: rawMock, parsed: parsedMock }, | ||
}) | ||
|
||
expect(message.dataGroups?.processed.documentType).toBe('TD3') | ||
expect(message.dataGroups?.processed.documentNumber).toBe('BC123456') | ||
expect(message.dataGroups?.processed.lastName).toBe('DOE') | ||
expect(message.dataGroups?.processed.firstName).toBe('JOHN') | ||
expect(message.dataGroups?.processed.dateOfBirth).toBe('19900101') | ||
expect(message.dataGroups?.processed.dateOfExpiry).toBe('20300510') | ||
expect(message.dataGroups?.processed.sex).toBe('M') | ||
expect(message.dataGroups?.processed.nationality).toBe('COL') | ||
expect(message.dataGroups?.processed.nameOfHolder).toBe('John Doe') | ||
expect(message.dataGroups?.processed.faceImages[0]).toContain('data:image/jp2;base64,') | ||
}) | ||
}) |
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,12 @@ | ||
import type { Config } from '@jest/types' | ||
|
||
import base from '../../jest.config.base' | ||
|
||
import packageJson from './package.json' | ||
|
||
const config: Config.InitialOptions = { | ||
...base, | ||
displayName: packageJson.name, | ||
} | ||
|
||
export default config |
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,16 @@ | ||
{ | ||
"extends": "./tsconfig.build.json", | ||
"compilerOptions": { | ||
"lib": ["ES2021.Promise"], | ||
"baseUrl": ".", | ||
"paths": { | ||
"@2060.io/service-agent-client": ["packages/client/src"], | ||
"@2060.io/service-agent-main": ["packages/main/src"], | ||
"@2060.io/service-agent-model": ["packages/model/src"], | ||
"@2060.io/service-agent-nestjs-client": ["packages/nestjs-client/src"], | ||
}, | ||
"types": ["jest", "node"] | ||
}, | ||
"include": ["tests", "samples", "**/tests", "**/samples"], | ||
"exclude": ["node_modules", "build", "**/build/**"] | ||
} |