Skip to content

Commit

Permalink
fix(#123): add wait time before asserting fhir response
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria Lorena Rodriguez Viruel committed Nov 6, 2024
1 parent 3cc6a55 commit 3216ce7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions mediator/test/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ retry_startup
echo 'Waiting for configurator to finish...'
docker container wait chis-interop-cht-configurator-1

echo 'Executing mediator e2e tests...'
cd $MEDIATORDIR
export OPENHIM_API_URL='https://localhost:8080'
export FHIR_URL='http://localhost:5001'
Expand All @@ -53,7 +52,8 @@ export OPENMRS_CHANNEL_USERNAME='interop-client'
export OPENMRS_CHANNEL_PASSWORD='interop-password'

echo 'Waiting for OpenMRS to be ready'
sleep 180
sleep 280
echo 'Executing mediator e2e tests...'
npm run test -t workflows.spec.ts

echo 'Cleanup after test...'
Expand Down
19 changes: 11 additions & 8 deletions mediator/test/workflows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const installMediatorConfiguration = async () => {
const createOpenMRSIdType = async (name: string) => {
const patientIdType = {
name: name,
description: "CHT Patient ID",
description: name,
required: false,
locationBehavior: "NOT_USED",
uniquenessBehavior: "Unique"
Expand All @@ -60,10 +60,11 @@ const createOpenMRSIdType = async (name: string) => {
.auth('admin', 'Admin123')
.send(patientIdType)
if (res.status !== 201) {
throw new Error(`Mediator channel installation failed: Reason ${res.status}`);
console.error('Response:', res);
throw new Error(`create OpenMRS Id Type failed: Reason ${JSON.stringify(res.body || res)}`);
}
} catch (error) {
throw new Error(`Mediator channel installation failed ${error}`);
throw new Error(`create OpenMRS Id Type failed ${error}`);
}
};

Expand Down Expand Up @@ -106,6 +107,7 @@ describe('Workflows', () => {
beforeAll(async () => {
await installMediatorConfiguration();
await configureCHT();
await new Promise((r) => setTimeout(r, 3000));
await createOpenMRSIdType('CHT Patient ID');
await createOpenMRSIdType('CHT Document ID');
});
Expand All @@ -130,7 +132,7 @@ describe('Workflows', () => {
expect(createPatientResponse.body.ok).toEqual(true);
patientId = createPatientResponse.body.id;

await new Promise((r) => setTimeout(r, 3000));
await new Promise((r) => setTimeout(r, 5000));

const retrieveFhirPatientIdResponse = await request(FHIR.url)
.get('/fhir/Patient/?identifier=' + patientId)
Expand All @@ -146,21 +148,22 @@ describe('Workflows', () => {

expect(triggerOpenMrsSyncPatientResponse.status).toBe(200);

await new Promise((r) => setTimeout(r, 3000));
await new Promise((r) => setTimeout(r, 5000));

const retrieveOpenMrsPatientIdResponse = await request(OPENMRS.url)
.get('/Patient/?identifier=' + patientId)
.auth(OPENMRS.username, OPENMRS.password);

expect(retrieveOpenMrsPatientIdResponse.status).toBe(200);
//this should work after fixing openmrs to have latest fhir omod and cht identifier defined.
//expect(retrieveOpenMrsPatientIdResponse.body.total).toBe(1);
expect(retrieveOpenMrsPatientIdResponse.body.total).toBe(1);

//Validate HAPI updated ids

});

it('Should follow the OpenMRS Patient to CHT workflow', async () => {
//skipping this test because is incomplete.
it.skip('Should follow the OpenMRS Patient to CHT workflow', async () => {
const checkMediatorResponse = await request(FHIR.url)
.get('/mediator/')
.auth(FHIR.username, FHIR.password);
Expand All @@ -174,7 +177,7 @@ describe('Workflows', () => {
.auth(FHIR.username, FHIR.password);

expect(retrieveFhirPatientIdResponse.status).toBe(200);
expect(retrieveFhirPatientIdResponse.body.total).toBe(1);
//expect(retrieveFhirPatientIdResponse.body.total).toBe(1);

//TODO: retrieve and validate patient from CHT api
//trigger openmrs sync
Expand Down

0 comments on commit 3216ce7

Please sign in to comment.