Skip to content

Commit

Permalink
Add temporary isSubsetOf function
Browse files Browse the repository at this point in the history
Ref: #7
  • Loading branch information
projkov committed Sep 12, 2024
1 parent d4d790d commit 0418d23
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/client-testing-demo-tests-standard/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { Patient } from 'fhir/r4';
import { Request } from '@beda.software/app/src/modules/requests/request.entity';
import { isResourceValid } from '@beda.software/fhir-validator';

/**
* Temporary function to check if a set is a subset of another set
*/
function isSubsetOf<T>(setA: Set<T>, setB: Set<T>): boolean {
if (setA.size > setB.size) {
return false;
}

for (const elem of setA) {
if (!setB.has(elem)) {
return false;
}
}
return true;
}

export function patientDemoTest() {
describe('Patients test (2nd version)', () => {
let requests: Request[] = [];
Expand Down Expand Up @@ -35,7 +50,7 @@ export function patientDemoTest() {
.map((request) => request.filtersCodes[0]),
);

expect(filteredRequests.isSubsetOf(availableSearchParams)).toBe(true);
expect(isSubsetOf(filteredRequests, availableSearchParams)).toBe(true);
});

test('Should only have available combo search params', async () => {
Expand All @@ -51,7 +66,7 @@ export function patientDemoTest() {
.map((request) => request.filtersCodes.join('+')),
);

expect(filteredRequests.isSubsetOf(availableComboSearchParams)).toBe(true);
expect(isSubsetOf(filteredRequests, availableComboSearchParams)).toBe(true);
});

test('Should only have valid resources in CREATE action', async () => {
Expand Down

0 comments on commit 0418d23

Please sign in to comment.