|
| 1 | +const path = require('path'); |
1 | 2 | const { BaseCSVExtractor } = require('../../src/extractors');
|
2 | 3 |
|
| 4 | +// Some global variables |
| 5 | +const fixturesPath = path.join(__dirname, 'fixtures'); |
| 6 | +const csvFileName = 'example.csv'; |
| 7 | + |
3 | 8 | // Tests
|
4 | 9 | 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'); |
37 | 41 | });
|
38 | 42 | });
|
0 commit comments