|
1 | 1 | const {
|
2 |
| - getQuantityUnit, isBundleEmpty, firstEntryInBundle, firstResourceInBundle, allResourcesInBundle, quantityCodeToUnitLookup, |
| 2 | + getQuantityUnit, |
| 3 | + isBundleEmpty, |
| 4 | + firstEntryInBundle, |
| 5 | + firstResourceInBundle, |
| 6 | + allResourcesInBundle, |
| 7 | + quantityCodeToUnitLookup, |
| 8 | + getResourceCountInBundle, |
3 | 9 | } = require('../../src/helpers/fhirUtils.js');
|
4 | 10 | const emptyBundle = require('./fixtures/emptyBundle.json');
|
5 | 11 | const bundleWithOneEntry = require('./fixtures/searchsetBundleWithOneEntry.json');
|
6 | 12 | const bundleWithMultipleEntries = require('./fixtures/searchsetBundleWithMultipleEntries.json');
|
| 13 | +const countBundle5Unique = require('./fixtures/count-bundle-5-unique.json'); |
| 14 | +const countBundle5Same = require('./fixtures/count-bundle-5-same.json'); |
| 15 | +const countBundle5Nested = require('./fixtures/count-bundle-5-nested.json'); |
7 | 16 |
|
8 |
| -test('getQuantityUnit', () => { |
9 |
| - // Should return unit text if provided in lookup table |
10 |
| - Object.keys(quantityCodeToUnitLookup).forEach((unitCode) => { |
11 |
| - const unitText = quantityCodeToUnitLookup[unitCode]; |
12 |
| - expect(getQuantityUnit(unitCode)).toEqual(unitText); |
| 17 | +describe('getQuantityUnit', () => { |
| 18 | + test('Should return unit text if provided in lookup table', () => { |
| 19 | + Object.keys(quantityCodeToUnitLookup).forEach((unitCode) => { |
| 20 | + const unitText = quantityCodeToUnitLookup[unitCode]; |
| 21 | + expect(getQuantityUnit(unitCode)).toEqual(unitText); |
| 22 | + }); |
13 | 23 | });
|
14 | 24 |
|
15 |
| - // Should return unit code if unit text is not provided |
16 |
| - expect(getQuantityUnit('foo')).toEqual('foo'); |
| 25 | + test('Should return unit code if unit text is not provided', () => { |
| 26 | + expect(getQuantityUnit('foo')).toEqual('foo'); |
| 27 | + }); |
17 | 28 | });
|
18 | 29 |
|
19 |
| -test('isBundleEmpty', () => { |
20 |
| - // Empty bundle return true |
21 |
| - expect(isBundleEmpty(emptyBundle)) |
22 |
| - .toBeTruthy(); |
| 30 | +describe('isBundleEmpty', () => { |
| 31 | + test('Empty bundle return true', () => { |
| 32 | + expect(isBundleEmpty(emptyBundle)) |
| 33 | + .toBeTruthy(); |
| 34 | + }); |
23 | 35 |
|
24 |
| - // Bundles with >=1 entry should return false |
25 |
| - expect(isBundleEmpty(bundleWithOneEntry)) |
26 |
| - .toBeFalsy(); |
27 |
| - expect(isBundleEmpty(bundleWithMultipleEntries)) |
28 |
| - .toBeFalsy(); |
| 36 | + test('Bundles with >=1 entry should return false', () => { |
| 37 | + expect(isBundleEmpty(bundleWithOneEntry)) |
| 38 | + .toBeFalsy(); |
| 39 | + expect(isBundleEmpty(bundleWithMultipleEntries)) |
| 40 | + .toBeFalsy(); |
| 41 | + }); |
29 | 42 | });
|
30 | 43 |
|
31 |
| -test('firstEntryInBundle', () => { |
32 |
| - // Empty bundle should return undefined |
| 44 | +describe('firstEntryInBundle', () => { |
| 45 | + test('Empty bundle should return undefined', () => { |
| 46 | + }); |
33 | 47 | expect(firstEntryInBundle(emptyBundle)).toBeUndefined();
|
34 | 48 |
|
35 |
| - // Bundles with entries should always return the first |
36 |
| - expect(firstEntryInBundle(bundleWithOneEntry)) |
37 |
| - .toEqual(bundleWithOneEntry.entry[0]); |
38 |
| - expect(firstEntryInBundle(bundleWithMultipleEntries)) |
39 |
| - .toEqual(bundleWithMultipleEntries.entry[0]); |
| 49 | + test('Bundles with entries should always return the first', () => { |
| 50 | + expect(firstEntryInBundle(bundleWithOneEntry)) |
| 51 | + .toEqual(bundleWithOneEntry.entry[0]); |
| 52 | + expect(firstEntryInBundle(bundleWithMultipleEntries)) |
| 53 | + .toEqual(bundleWithMultipleEntries.entry[0]); |
| 54 | + }); |
40 | 55 | });
|
41 | 56 |
|
42 |
| -test('firstResourceInBundle', () => { |
43 |
| - // Empty bundle should throw an error |
44 |
| - expect(() => firstResourceInBundle(emptyBundle)) |
45 |
| - .toThrow(TypeError("Cannot read property 'resource' of undefined")); |
| 57 | +describe('firstResourceInBundle', () => { |
| 58 | + test('Empty bundle should throw an error', () => { |
| 59 | + expect(() => firstResourceInBundle(emptyBundle)) |
| 60 | + .toThrow(TypeError("Cannot read property 'resource' of undefined")); |
| 61 | + }); |
46 | 62 |
|
47 |
| - // Bundles with entries should always return the first |
48 |
| - expect(firstResourceInBundle(bundleWithOneEntry)) |
49 |
| - .toEqual(bundleWithOneEntry.entry[0].resource); |
50 |
| - expect(firstResourceInBundle(bundleWithMultipleEntries)) |
51 |
| - .toEqual(bundleWithMultipleEntries.entry[0].resource); |
| 63 | + test('Bundles with entries should always return the first', () => { |
| 64 | + expect(firstResourceInBundle(bundleWithOneEntry)) |
| 65 | + .toEqual(bundleWithOneEntry.entry[0].resource); |
| 66 | + expect(firstResourceInBundle(bundleWithMultipleEntries)) |
| 67 | + .toEqual(bundleWithMultipleEntries.entry[0].resource); |
| 68 | + }); |
52 | 69 | });
|
53 | 70 |
|
54 |
| -test('allResourcesInBundle', () => { |
55 |
| - // Empty bundle should return an empty array |
56 |
| - expect(allResourcesInBundle(emptyBundle)) |
57 |
| - .toEqual([]); |
| 71 | +describe('allResourcesInBundle', () => { |
| 72 | + test('Empty bundle should return an empty array', () => { |
| 73 | + expect(allResourcesInBundle(emptyBundle)) |
| 74 | + .toEqual([]); |
| 75 | + }); |
| 76 | + |
58 | 77 |
|
59 |
| - // Bundles with entries should always return an array of each resource on each entry |
60 |
| - expect(allResourcesInBundle(bundleWithOneEntry)) |
61 |
| - .toEqual([bundleWithOneEntry.entry[0].resource]); |
62 |
| - expect(allResourcesInBundle(bundleWithMultipleEntries)) |
63 |
| - .toEqual(bundleWithMultipleEntries.entry.map((e) => e.resource)); |
| 78 | + test('Bundles with entries should always return an array of each resource on each entry', () => { |
| 79 | + expect(allResourcesInBundle(bundleWithOneEntry)) |
| 80 | + .toEqual([bundleWithOneEntry.entry[0].resource]); |
| 81 | + expect(allResourcesInBundle(bundleWithMultipleEntries)) |
| 82 | + .toEqual(bundleWithMultipleEntries.entry.map((e) => e.resource)); |
| 83 | + }); |
64 | 84 | });
|
65 | 85 |
|
| 86 | +describe('getResourceCountInBundle', () => { |
| 87 | + test('Counts five different resources, all at the same depth', () => { |
| 88 | + const counts = { |
| 89 | + 'Resource-1': [1], |
| 90 | + 'Resource-2': [1], |
| 91 | + 'Resource-3': [1], |
| 92 | + 'Resource-4': [1], |
| 93 | + 'Resource-5': [1], |
| 94 | + }; |
| 95 | + expect(getResourceCountInBundle(countBundle5Unique)).toEqual(counts); |
| 96 | + }); |
66 | 97 |
|
67 |
| -test('getResourceCountInBundle', () => { |
68 |
| - // TODO: MAKE TESTS HERE |
69 |
| - // getResourceCountInBundle; |
| 98 | + test('Counts five of the same resources, all at the same depth', () => { |
| 99 | + const counts = { |
| 100 | + 'Resource-1': [5], |
| 101 | + }; |
| 102 | + expect(getResourceCountInBundle(countBundle5Same)).toEqual(counts); |
| 103 | + }); |
| 104 | + |
| 105 | + test('Counts five of the same resources at various depths', () => { |
| 106 | + const counts = { |
| 107 | + 'Resource-1': [5], |
| 108 | + }; |
| 109 | + expect(getResourceCountInBundle(countBundle5Nested)).toEqual(counts); |
| 110 | + }); |
70 | 111 | });
|
0 commit comments