-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from mcode/develop
Merge for v1.0.1
- Loading branch information
Showing
8 changed files
with
142 additions
and
52 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,13 +1,14 @@ | ||
{ | ||
"name": "mcode-extraction-framework", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
"contributors": [ | ||
"Julia Afeltra <[email protected]>", | ||
"Julian Carter <[email protected]>", | ||
"Matthew Gramigna <[email protected]>", | ||
"Daniel Lee <[email protected]>", | ||
"Dylan Mahalingam <[email protected]>", | ||
"Dylan Mendelowitz <[email protected]>", | ||
"Dylan Phelan <[email protected]>" | ||
], | ||
"main": "src/", | ||
|
@@ -26,9 +27,9 @@ | |
"csv-parse": "^4.8.8", | ||
"fhir-crud-client": "^1.2.2", | ||
"fhirpath": "2.1.5", | ||
"lodash": "^4.17.19", | ||
"lodash": "^4.17.21", | ||
"moment": "^2.26.0", | ||
"nodemailer": "^6.4.14", | ||
"nodemailer": "^6.4.16", | ||
"sha.js": "^2.4.9", | ||
"winston": "^3.2.1" | ||
}, | ||
|
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
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,48 +1,91 @@ | ||
const path = require('path'); | ||
const rewire = require('rewire'); | ||
const { CSVModule } = require('../../src/modules'); | ||
const exampleResponse = require('./fixtures/csv-response.json'); | ||
|
||
const CSVModuleRewired = rewire('../../src/modules/CSVModule.js'); | ||
const normalizeEmptyValues = CSVModuleRewired.__get__('normalizeEmptyValues'); | ||
|
||
const INVALID_MRN = 'INVALID MRN'; | ||
const csvModule = new CSVModule(path.join(__dirname, './fixtures/example-csv.csv')); | ||
const csvModuleWithBOMs = new CSVModule(path.join(__dirname, './fixtures/example-csv-bom.csv')); | ||
|
||
test('Reads data from CSV', async () => { | ||
const data = await csvModule.get('mrn', 'example-mrn-1'); | ||
expect(data).toEqual(exampleResponse); | ||
}); | ||
|
||
test('Reads data from CSV with a Byte Order Mark', async () => { | ||
const data = await csvModuleWithBOMs.get('mrn', 'example-mrn-1'); | ||
expect(data).toEqual(exampleResponse); | ||
}); | ||
describe('CSVModule', () => { | ||
describe('get', () => { | ||
test('Reads data from CSV', async () => { | ||
const data = await csvModule.get('mrn', 'example-mrn-1'); | ||
expect(data).toEqual(exampleResponse); | ||
}); | ||
|
||
test('Returns multiple rows', async () => { | ||
const data = await csvModule.get('mrn', 'example-mrn-2'); | ||
expect(data).toHaveLength(2); | ||
}); | ||
test('Reads data from CSV with a Byte Order Mark', async () => { | ||
const data = await csvModuleWithBOMs.get('mrn', 'example-mrn-1'); | ||
expect(data).toEqual(exampleResponse); | ||
}); | ||
|
||
test('Returns all rows when both key and value are undefined', async () => { | ||
const data = await csvModule.get(); | ||
expect(data).toHaveLength(csvModule.data.length); | ||
expect(data).toEqual(csvModule.data); | ||
}); | ||
test('Returns multiple rows', async () => { | ||
const data = await csvModule.get('mrn', 'example-mrn-2'); | ||
expect(data).toHaveLength(2); | ||
}); | ||
|
||
test('Returns data with recordedDate after specified from date', async () => { | ||
const data = await csvModule.get('mrn', 'example-mrn-2', '2020-05-01'); | ||
expect(data).toHaveLength(1); | ||
}); | ||
test('Returns all rows when both key and value are undefined', async () => { | ||
const data = await csvModule.get(); | ||
expect(data).toHaveLength(csvModule.data.length); | ||
expect(data).toEqual(csvModule.data); | ||
}); | ||
|
||
test('Returns data with recordedDate before specified to date', async () => { | ||
const data = await csvModule.get('mrn', 'example-mrn-2', null, '2020-05-01'); | ||
expect(data).toHaveLength(1); | ||
}); | ||
test('Returns data with recordedDate after specified from date', async () => { | ||
const data = await csvModule.get('mrn', 'example-mrn-2', '2020-05-01'); | ||
expect(data).toHaveLength(1); | ||
}); | ||
|
||
test('Should return an empty array when key-value pair does not exist', async () => { | ||
const data = await csvModule.get('mrn', INVALID_MRN); | ||
expect(data).toEqual([]); | ||
}); | ||
test('Returns data with recordedDate before specified to date', async () => { | ||
const data = await csvModule.get('mrn', 'example-mrn-2', null, '2020-05-01'); | ||
expect(data).toHaveLength(1); | ||
}); | ||
|
||
test('Should return an empty array when key-value pair does not exist', async () => { | ||
const data = await csvModule.get('mrn', INVALID_MRN); | ||
expect(data).toEqual([]); | ||
}); | ||
|
||
test('Should return proper value regardless of key casing', async () => { | ||
const data = await csvModule.get('mRN', 'example-mrn-1'); | ||
expect(data).toEqual(exampleResponse); | ||
}); | ||
}); | ||
|
||
describe('normalizeEmptyValues', () => { | ||
it('Should turn "null" values into empty strings, regardless of case', () => { | ||
const data = [{ key: 'null' }, { key: 'NULL' }, { key: 'nuLL' }]; | ||
const normalizedData = normalizeEmptyValues(data); | ||
normalizedData.forEach((d) => { | ||
expect(d.key).toBe(''); | ||
}); | ||
}); | ||
|
||
it('Should turn "nil" values into empty strings, regardless of case', () => { | ||
const data = [{ key: 'nil' }, { key: 'NIL' }, { key: 'NIl' }]; | ||
const normalizedData = normalizeEmptyValues(data); | ||
normalizedData.forEach((d) => { | ||
expect(d.key).toBe(''); | ||
}); | ||
}); | ||
|
||
it('Should not modify unalterableColumns, regardless of their value', () => { | ||
const data = [{ key: 'null' }, { key: 'NULL' }, { key: 'nuLL' }, { key: 'nil' }, { key: 'NIL' }, { key: 'NIl' }]; | ||
const normalizedData = normalizeEmptyValues(data, ['key']); | ||
normalizedData.forEach((d) => { | ||
expect(d.key).not.toBe(''); | ||
}); | ||
}); | ||
|
||
test('Should return proper value regardless of key casing', async () => { | ||
const data = await csvModule.get('mRN', 'example-mrn-1'); | ||
expect(data).toEqual(exampleResponse); | ||
it('Should leave all other values uneffected, regardless of case', () => { | ||
const data = [{ key: 'anything' }, { key: 'any' }, { key: 'thing' }]; | ||
const normalizedData = normalizeEmptyValues(data); | ||
normalizedData.forEach((d) => { | ||
expect(d.key).not.toBe(''); | ||
}); | ||
}); | ||
}); | ||
}); |