Skip to content

Commit f1e2cdc

Browse files
committed
updated tests to infer and create abs path dynamically
1 parent 9ecc0d1 commit f1e2cdc

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed
Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1+
const path = require('path');
12
const { BaseCSVExtractor } = require('../../src/extractors');
23

4+
// Some global variables
5+
const fixturesPath = path.join(__dirname, 'fixtures');
6+
const csvFileName = 'example.csv';
7+
38
// Tests
49
describe('BaseCSVExtractor', () => {
5-
describe('constructor', () => {
6-
test('Should create a CSVURLModule when provided a filePath', () => {
7-
const filePathExtractor = new BaseCSVExtractor({ filePath: '/Users/dphelan/Development/mcode-extraction-framework/test/extractors/fixtures/example.csv' });
8-
expect(filePathExtractor.csvModule).not.toBeUndefined();
9-
expect(filePathExtractor.csvModule.constructor.name).toEqual('CSVFileModule');
10-
});
11-
test('Should create a CSVFileModule when provided a URL', () => {
12-
const urlExtractor = new BaseCSVExtractor({ url: 'http://example.com' });
13-
expect(urlExtractor.csvModule).not.toBeUndefined();
14-
expect(urlExtractor.csvModule.constructor.name).toEqual('CSVURLModule');
15-
});
16-
test('Should create a CSVFileModule when provided a fileName and a dataDirectory', () => {
17-
const fileNameDataDirectoryExtractor = new BaseCSVExtractor({ fileName: 'example.csv', dataDirectory: '/Users/dphelan/Development/mcode-extraction-framework/test/extractors/fixtures/' });
18-
expect(fileNameDataDirectoryExtractor.csvModule).not.toBeUndefined();
19-
expect(fileNameDataDirectoryExtractor.csvModule.constructor.name).toEqual('CSVFileModule');
20-
});
21-
test('Should fail when the provided dataDirectory is not an absolute path', () => {
22-
expect(() => new BaseCSVExtractor({ fileName: 'example.csv', dataDirectory: './extractors/fixtures/' }))
23-
.toThrowError('dataDirectory is not an absolutePath, it needs to be.');
24-
});
25-
test('Should fail when provided only provided a fileName and no dataDirectory', () => {
26-
expect(() => new BaseCSVExtractor({ fileName: 'example.csv' }))
27-
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination');
28-
});
29-
test('Should fail when provided only provided a dataDirectory and no fileName', () => {
30-
expect(() => new BaseCSVExtractor({ dataDirectory: '/Users/dphelan/Development/mcode-extraction-framework/test/extractors/fixtures/' }))
31-
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination');
32-
});
33-
test('Should fail when provided none of the three options above', () => {
34-
expect(() => new BaseCSVExtractor({}))
35-
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination');
36-
});
10+
test('Should create a CSVURLModule when provided a filePath that is an absolute path', () => {
11+
const absolutePath = path.join(fixturesPath, csvFileName);
12+
const filePathExtractor = new BaseCSVExtractor({ filePath: absolutePath });
13+
expect(filePathExtractor.csvModule).not.toBeUndefined();
14+
expect(filePathExtractor.csvModule.constructor.name).toEqual('CSVFileModule');
15+
});
16+
test('Should create a CSVFileModule when provided a URL', () => {
17+
const urlExtractor = new BaseCSVExtractor({ url: 'http://example.com' });
18+
expect(urlExtractor.csvModule).not.toBeUndefined();
19+
expect(urlExtractor.csvModule.constructor.name).toEqual('CSVURLModule');
20+
});
21+
test('Should create a CSVFileModule when provided a fileName and a dataDirectory', () => {
22+
const fileNameDataDirectoryExtractor = new BaseCSVExtractor({ fileName: csvFileName, dataDirectory: fixturesPath });
23+
expect(fileNameDataDirectoryExtractor.csvModule).not.toBeUndefined();
24+
expect(fileNameDataDirectoryExtractor.csvModule.constructor.name).toEqual('CSVFileModule');
25+
});
26+
test('Should fail when the provided dataDirectory is not an absolute path', () => {
27+
expect(() => new BaseCSVExtractor({ fileName: csvFileName, dataDirectory: './fixtures/' }))
28+
.toThrowError('dataDirectory is not an absolutePath, it needs to be.');
29+
});
30+
test('Should fail when provided only provided a fileName and no dataDirectory', () => {
31+
expect(() => new BaseCSVExtractor({ fileName: csvFileName }))
32+
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination');
33+
});
34+
test('Should fail when provided only provided a dataDirectory and no fileName', () => {
35+
expect(() => new BaseCSVExtractor({ dataDirectory: fixturesPath }))
36+
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination');
37+
});
38+
test('Should fail when provided none of the three options above', () => {
39+
expect(() => new BaseCSVExtractor({}))
40+
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination');
3741
});
3842
});

0 commit comments

Comments
 (0)