Skip to content

Commit

Permalink
Remove helpers for the clean ts tests
Browse files Browse the repository at this point in the history
Ref: #7
  • Loading branch information
projkov committed Sep 11, 2024
1 parent 84a01ae commit 39016a4
Showing 1 changed file with 28 additions and 46 deletions.
74 changes: 28 additions & 46 deletions packages/client-testing-demo-tests-standard/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,6 @@ import { Patient } from 'fhir/r4';
import { Request } from '@beda.software/app/src/modules/requests/request.entity';
import { isResourceValid } from '@beda.software/fhir-validator';

function patientRequestsOnlyAvailableInteractionsExists(requests: Request[]): boolean {
const availableInteractions = ['READ', 'SEARCH', 'CREATE', 'UPDATE'];
const filteredRequests = requests.filter((request) => !availableInteractions.includes(request.fhirAction));

return filteredRequests.length === 0;
}

function patientRequestsOnlyAvailableSearchParamsExists(requests: Request[]): boolean {
const availableSearchParams = [
'_id',
'birthdate',
'family',
'gender',
'identifier',
'name',
'gender-identity',
'indigenous-status',
];

return checkAvailableParams(availableSearchParams, false, requests);
}

function patientRequestsOnlyAvailableComboSearchParamsExists(requests: Request[]): boolean {
const availableComboSearchParams = ['birthdate+family', 'birthdate+name', 'gender+name', 'family+gender'];

return checkAvailableParams(availableComboSearchParams, true, requests);
}

function checkAvailableParams(availableParams: string[], combo: boolean, requests: Request[]): boolean {
const filterCombo = (param: string) => (combo ? param.includes('+') : !param.includes('+'));
const usedComboSearchParams = requests
Expand All @@ -41,18 +13,6 @@ function checkAvailableParams(availableParams: string[], combo: boolean, request
return uniqueUsedComboSearchParams.every((searchParam) => availableParams.includes(searchParam));
}

async function patientRequestCreateValidPatient(requests: Request[]): Promise<boolean> {
const filteredRequests = requests.filter(
(request) => request.fhirAction === 'CREATE' && request.requestBody?.resourceType === 'Patient',
);
const validationStatuses = await Promise.all(
filteredRequests.map(async (request) => await isResourceValid(request.requestBody as Patient)),
);
const falseValidations = validationStatuses.filter((status) => status === false);

return falseValidations.length === 0;
}

export function patientDemoTest() {
describe('Patients test (2nd version)', () => {
let requests: Request[];
Expand All @@ -65,21 +25,43 @@ export function patientDemoTest() {
});

test('Should only have available interactions', async () => {
expect(patientRequestsOnlyAvailableInteractionsExists(requests)).toBe(true);
const availableInteractions = ['READ', 'SEARCH', 'CREATE', 'UPDATE'];
const filteredRequests = requests.filter((request) => !availableInteractions.includes(request.fhirAction));

expect(filteredRequests.length).toBe(0);
});

test('Should only have available search params', async () => {
expect(patientRequestsOnlyAvailableSearchParamsExists(requests)).toBe(true);
const availableSearchParams = [
'_id',
'birthdate',
'family',
'gender',
'identifier',
'name',
'gender-identity',
'indigenous-status',
];

expect(checkAvailableParams(availableSearchParams, false, requests)).toBe(true);
});

test('Should only have available combo search params', async () => {
expect(patientRequestsOnlyAvailableComboSearchParamsExists(requests)).toBe(true);
const availableComboSearchParams = ['birthdate+family', 'birthdate+name', 'gender+name', 'family+gender'];

expect(checkAvailableParams(availableComboSearchParams, true, requests)).toBe(true);
});

test('Should only have valid resources in CREATE action', async () => {
expect(
await patientRequestCreateValidPatient(requests.filter((request) => request.fhirAction === 'CREATE')),
).toBe(true);
const filteredRequests = requests.filter(
(request) => request.fhirAction === 'CREATE' && request.requestBody?.resourceType === 'Patient',
);
const validationStatuses = await Promise.all(
filteredRequests.map(async (request) => await isResourceValid(request.requestBody as Patient)),
);
const falseValidations = validationStatuses.filter((status) => status === false);

expect(falseValidations.length).toBe(0);
});
});
}

0 comments on commit 39016a4

Please sign in to comment.