|
1 | 1 | const { when } = require('jest-when');
|
2 |
| -const rewire = require('rewire'); |
3 | 2 | const { BaseFHIRExtractor } = require('../../src/extractors');
|
4 | 3 | const examplePatientBundle = require('./fixtures/patient-bundle.json');
|
5 | 4 | const exampleConditionBundle = require('./fixtures/condition-bundle.json');
|
6 | 5 |
|
7 |
| -const BaseFHIRExtractorRewired = rewire('../../src/extractors/BaseFHIRExtractor.js'); |
8 |
| - |
9 | 6 | // Constants for mock tests
|
10 | 7 | const MOCK_URL = 'http://localhost';
|
11 | 8 | const MOCK_REQUEST_HEADERS = {
|
@@ -44,33 +41,22 @@ describe('BaseFhirExtractor', () => {
|
44 | 41 | expect(moduleRequestHeadersSpy).toHaveBeenCalledWith(MOCK_REQUEST_HEADERS);
|
45 | 42 | });
|
46 | 43 |
|
47 |
| - const parseContextForPatientId = BaseFHIRExtractorRewired.__get__('parseContextForPatientId'); |
48 |
| - test('parseContextForPatientId returns undefined when no context is provided', () => { |
49 |
| - const emptyValue = parseContextForPatientId({}); |
50 |
| - expect(emptyValue).toBeUndefined(); |
51 |
| - }); |
52 |
| - |
53 |
| - test('parseContextForPatientId returns the patient ID when one exists on the contextBundle', () => { |
54 |
| - const idValue = parseContextForPatientId(MOCK_CONTEXT); |
55 |
| - expect(idValue).toEqual(MOCK_CONTEXT.entry[0].resource.id); |
56 |
| - }); |
57 |
| - |
58 | 44 | test('parametrizeArgsForFHIRModule parses data off of context if available', async () => {
|
59 | 45 | baseFHIRModuleSearchSpy.mockClear();
|
60 |
| - const paramsBasedOnContext = await baseFHIRExtractor.parametrizeArgsForFHIRModule({ context: MOCK_CONTEXT }); |
| 46 | + const paramsBasedOnContext = await baseFHIRExtractor.parametrizeArgsForFHIRModule({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT }); |
61 | 47 | expect(baseFHIRModuleSearchSpy).not.toHaveBeenCalled();
|
62 | 48 | expect(paramsBasedOnContext).toHaveProperty('patient');
|
63 | 49 | expect(paramsBasedOnContext.patient).toEqual(MOCK_CONTEXT.entry[0].resource.id);
|
64 | 50 | });
|
65 | 51 |
|
66 | 52 | test('parametrizeArgsForFHIRModule throws an error if context has no relevant ID', async () => {
|
67 | 53 | baseFHIRModuleSearchSpy.mockClear();
|
68 |
| - await expect(baseFHIRExtractor.parametrizeArgsForFHIRModule({})).rejects.toThrowError('BaseFHIRExtractor could not find Patient resource in context.'); |
| 54 | + await expect(baseFHIRExtractor.parametrizeArgsForFHIRModule({ mrn: MOCK_PATIENT_MRN, context: {} })).rejects.toThrow(); |
69 | 55 | expect(baseFHIRModuleSearchSpy).not.toHaveBeenCalled();
|
70 | 56 | });
|
71 | 57 |
|
72 | 58 | test('get should return a condition resource', async () => {
|
73 |
| - const data = await baseFHIRExtractor.get({ context: MOCK_CONTEXT }); |
| 59 | + const data = await baseFHIRExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT }); |
74 | 60 | expect(data.resourceType).toEqual('Bundle');
|
75 | 61 | expect(data.entry).toBeDefined();
|
76 | 62 | expect(data.entry.length).toBeGreaterThan(0);
|
|
0 commit comments