Skip to content

Commit 34b475a

Browse files
committed
Added tests for getresourcecount
1 parent a8a2cc6 commit 34b475a

File tree

4 files changed

+184
-45
lines changed

4 files changed

+184
-45
lines changed

test/helpers/fhirUtils.test.js

Lines changed: 86 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,111 @@
11
const {
2-
getQuantityUnit, isBundleEmpty, firstEntryInBundle, firstResourceInBundle, allResourcesInBundle, quantityCodeToUnitLookup,
2+
getQuantityUnit,
3+
isBundleEmpty,
4+
firstEntryInBundle,
5+
firstResourceInBundle,
6+
allResourcesInBundle,
7+
quantityCodeToUnitLookup,
8+
getResourceCountInBundle,
39
} = require('../../src/helpers/fhirUtils.js');
410
const emptyBundle = require('./fixtures/emptyBundle.json');
511
const bundleWithOneEntry = require('./fixtures/searchsetBundleWithOneEntry.json');
612
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');
716

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+
});
1323
});
1424

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+
});
1728
});
1829

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+
});
2335

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+
});
2942
});
3043

31-
test('firstEntryInBundle', () => {
32-
// Empty bundle should return undefined
44+
describe('firstEntryInBundle', () => {
45+
test('Empty bundle should return undefined', () => {
46+
});
3347
expect(firstEntryInBundle(emptyBundle)).toBeUndefined();
3448

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+
});
4055
});
4156

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+
});
4662

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+
});
5269
});
5370

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+
5877

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+
});
6484
});
6585

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+
});
6697

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+
});
70111
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"resourceType": "Bundle",
3+
"entry": [
4+
{
5+
"resource": {
6+
"resourceType": "Resource-1"
7+
},
8+
"contained": [
9+
{
10+
"resource": {
11+
"resourceType": "Resource-1"
12+
},
13+
"contained": [
14+
{
15+
"resource": {
16+
"resourceType": "Resource-1"
17+
},
18+
"contained": [
19+
{
20+
"resource": {
21+
"resourceType": "Resource-1"
22+
},
23+
"contained": [
24+
{
25+
"resource": {
26+
"resourceType": "Resource-1"
27+
}
28+
}
29+
]
30+
}
31+
]
32+
}
33+
]
34+
}
35+
]
36+
}
37+
]
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"resourceType": "Bundle",
3+
"entry": [
4+
{
5+
"resource": {
6+
"resourceType": "Resource-1"
7+
}
8+
},
9+
{
10+
"resource": {
11+
"resourceType": "Resource-1"
12+
}
13+
},
14+
{
15+
"resource": {
16+
"resourceType": "Resource-1"
17+
}
18+
},
19+
{
20+
"resource": {
21+
"resourceType": "Resource-1"
22+
}
23+
},
24+
{
25+
"resource": {
26+
"resourceType": "Resource-1"
27+
}
28+
}
29+
]
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"resourceType": "Bundle",
3+
"entry": [
4+
{
5+
"resource": {
6+
"resourceType": "Resource-1"
7+
}
8+
},
9+
{
10+
"resource": {
11+
"resourceType": "Resource-2"
12+
}
13+
},
14+
{
15+
"resource": {
16+
"resourceType": "Resource-3"
17+
}
18+
},
19+
{
20+
"resource": {
21+
"resourceType": "Resource-4"
22+
}
23+
},
24+
{
25+
"resource": {
26+
"resourceType": "Resource-5"
27+
}
28+
}
29+
]
30+
}

0 commit comments

Comments
 (0)