Skip to content

Commit ebbb344

Browse files
authored
Merge pull request #107 from mcode/byte-order-mark-parsing
CSV Module now ignores BOMs
2 parents 21689a2 + 0e3d63a commit ebbb344

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/modules/CSVModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const logger = require('../helpers/logger');
55

66
class CSVModule {
77
constructor(csvFilePath) {
8-
this.data = parse(fs.readFileSync(csvFilePath), { columns: true });
8+
this.data = parse(fs.readFileSync(csvFilePath), { columns: true, bom: true });
99
}
1010

1111
async get(key, value, fromDate, toDate) {

test/modules/CSVModule.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ const exampleResponse = require('./fixtures/csv-response.json');
44

55
const INVALID_MRN = 'INVALID MRN';
66
const csvModule = new CSVModule(path.join(__dirname, './fixtures/example-csv.csv'));
7+
const csvModuleWithBOMs = new CSVModule(path.join(__dirname, './fixtures/example-csv-bom.csv'));
78

89
test('Reads data from CSV', async () => {
910
const data = await csvModule.get('mrn', 'example-mrn-1');
1011
expect(data).toEqual(exampleResponse);
1112
});
1213

14+
test('Reads data from CSV with a Byte Order Mark', async () => {
15+
const data = await csvModuleWithBOMs.get('mrn', 'example-mrn-1');
16+
expect(data).toEqual(exampleResponse);
17+
});
18+
1319
test('Returns multiple rows', async () => {
1420
const data = await csvModule.get('mrn', 'example-mrn-2');
1521
expect(data).toHaveLength(2);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mrn,trialSubjectID,enrollmentStatus,trialResearchID,trialStatus,dateRecorded
2+
example-mrn-1,subjectId-1,status-1,researchId-1,trialStatus-1,2020-01-10
3+
example-mrn-2,subjectId-2,status-2,researchId-2,trialStatus-2,2020-01-10
4+
example-mrn-2,subjectId-3,status-3,researchId-3,trialStatus-3,2020-06-10

0 commit comments

Comments
 (0)