Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rcrichton committed Mar 4, 2024
1 parent c7b6de3 commit 40b39b2
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 35 deletions.
6 changes: 3 additions & 3 deletions tests/cucumber/step-definitions/fhirAccessProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Then(
'a successful response containing a bundle of related patient resources is sent back',
(): void => {
expect(responseBody.status).to.equal('Success');
expect(responseBody.response.body.resourceType).to.equal('Bundle');
expect(JSON.parse(responseBody.response.body).resourceType).to.equal('Bundle');
server.close();
}
);
Expand All @@ -55,7 +55,7 @@ When(
.set('content-type', 'application/fhir+json')
.expect(200);

const { response } = bundleSubmission.body.response.body.entry.find((entry) =>
const { response } = JSON.parse(bundleSubmission.body.response.body).entry.find((entry) =>
entry.response.location.startsWith('Patient')
);

Expand All @@ -71,7 +71,7 @@ When(

Then('a successful response containing a bundle is sent back', (): void => {
expect(responseBody.status).to.equal('Success');
expect(responseBody.response.body.resourceType).to.equal('Bundle');
expect(JSON.parse(responseBody.response.body).resourceType).to.equal('Bundle');
server.close();
});

Expand Down
9 changes: 5 additions & 4 deletions tests/cucumber/step-definitions/mpiAuthentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ When('a post request without body was sent to get patients', async (): Promise<v
});

Then('we should get an error response', (): void => {
expect(responseBody.response.body.error,
expect(
responseBody.response.body.error,
`Invalid Content! Type should be "${config.contentType}" and Length should be greater than 0"`
);
server.close();
Expand All @@ -51,8 +52,8 @@ When('a post request with body was sent to get patients', async (): Promise<void
resource: {
resourceType: 'Patient',
text: {
div: '<div xmlns=\"http://www.w3.org/1999/xhtml\">Patient</div>',
status: 'generated'
div: '<div xmlns="http://www.w3.org/1999/xhtml">Patient</div>',
status: 'generated',
},
name: [
{
Expand All @@ -79,6 +80,6 @@ When('a post request with body was sent to get patients', async (): Promise<void
});

Then('a response should be sent back', (): void => {
expect(responseBody.response.body.id).not.empty;
expect(JSON.parse(responseBody.response.body).id).not.empty;
server.close();
});
2 changes: 1 addition & 1 deletion tests/cucumber/step-definitions/patientSyncMatching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ When(
Then('a patient should be created on the client registry', async (): Promise<void> => {
const auth = await getMpiAuthToken();

const { response } = responseBody.response.body.entry.find((entry) =>
const { response } = JSON.parse(responseBody.response.body).entry.find((entry) =>
entry.response.location.startsWith('Patient')
);

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/fetchPatientResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('FetchPatientResources handler', (): void => {
.reply(200, {});

const result: MpiMediatorResponseObject = await fetchEverythingByRef(patientRef);
expect(result.body.response.body).to.deep.equal(emptyBundle);
expect(JSON.parse(result.body.response.body)).to.deep.equal(emptyBundle);
});

it('should succesfully return bundle of various resources', async (): Promise<void> => {
Expand All @@ -149,7 +149,7 @@ describe('FetchPatientResources handler', (): void => {

const result: MpiMediatorResponseObject = await fetchEverythingByRef(patientRef);

expect(result.body.response.body).to.deep.equal(bundle);
expect(JSON.parse(result.body.response.body)).to.deep.equal(bundle);
});
});
});
4 changes: 2 additions & 2 deletions tests/unit/fetchPatientSummaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ describe('FetchPatientSummaries handler', (): void => {
nock(fhirDatastoreUrl).get(`/fhir/${emptyPatientRef1}/$summary`).reply(200, {});

const result = await fetchPatientSummaryByRef(emptyPatientRef1);
expect(result.body.response.body).to.deep.equal(emptyBundle);
expect(JSON.parse(result.body.response.body)).to.deep.equal(emptyBundle);
});
it('should return a bundle with 2 entries for 1 given patient', async () => {
nock(fhirDatastoreUrl).get(`/fhir/${patientRef3}/$summary`).reply(200, patientSummary3);

const result = await fetchPatientSummaryByRef(patientRef3);
expect(result.body.response.body).to.deep.equal(combinedBundle2);
expect(JSON.parse(result.body.response.body)).to.deep.equal(combinedBundle2);
});
});
});
6 changes: 3 additions & 3 deletions tests/unit/kafkaAsyncPatientHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('Kafka Async Patient Handler', (): void => {
'x-mediator-urn': '123',
response: {
status: 200,
body: {},
body: '',
timestamp: '12-12-2012',
headers: {
'content-type': 'application/json',
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('Kafka Async Patient Handler', (): void => {
'x-mediator-urn': '123',
response: {
status: 200,
body: {},
body: '',
timestamp: '12-12-2012',
headers: {
'content-type': 'application/json',
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('Kafka Async Patient Handler', (): void => {
'x-mediator-urn': '123',
response: {
status: 200,
body: {},
body: '',
timestamp: '12-12-2012',
headers: {
'content-type': 'application/json',
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/matchPatientSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('Match Patient Synchronously', (): void => {
response: {
status: 200,
headers: { 'content-type': 'application/json' },
body: { mesage: 'Success' },
body: '',
timestamp: '12/02/1991',
},
},
Expand Down Expand Up @@ -179,7 +179,9 @@ describe('Match Patient Synchronously', (): void => {

expect(handlerResponse.status).to.be.equal(500);
expect(handlerResponse.body.status).to.be.equal('Failed');
expect(handlerResponse.body.response.body).to.deep.equal({ errors: [error] });
expect(JSON.parse(handlerResponse.body.response.body)).to.deep.equal({
errors: [error],
});
stub.restore();
});

Expand Down Expand Up @@ -254,7 +256,7 @@ describe('Match Patient Synchronously', (): void => {
response: {
status: 200,
headers: { 'content-type': 'application/json' },
body: { mesage: 'Success' },
body: '',
timestamp: '12/02/1991',
},
},
Expand Down Expand Up @@ -420,7 +422,7 @@ describe('Match Patient Synchronously', (): void => {
response: {
status: 200,
headers: { 'Content-Type': 'application/json' },
body: { mesage: 'Success' },
body: '',
timestamp: '12/02/1991',
},
},
Expand Down
20 changes: 6 additions & 14 deletions tests/unit/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,10 @@ describe('Middlewares', (): void => {
nock(mpiUrl).get('/fhir/Patient/1').reply(200, patientFhirResource1);
nock(mpiUrl).get('/fhir/Patient/2').reply(200, patientFhirResource2);
nock(fhirDatastoreUrl)
.get(
`/fhir/Encounter?subject=${encodeURIComponent(
'Patient/1,Patient/2'
)}`
)
.get(`/fhir/Encounter?subject=${encodeURIComponent('Patient/1,Patient/2')}`)
.reply(200, Encounters);
nock(fhirDatastoreUrl)
.get(
`/fhir/Observation?subject=${encodeURIComponent(
'Patient/1,Patient/2'
)}`
)
.get(`/fhir/Observation?subject=${encodeURIComponent('Patient/1,Patient/2')}`)
.reply(200, Observations);

const request = {
Expand All @@ -362,8 +354,8 @@ describe('Middlewares', (): void => {
await mpiMdmEverythingMiddleware(request, response, () => {});
expect(statusCode).to.equal(200);
expect(result.status).to.equal('Success');
expect(result.response.body.total).to.equal(4);
expect(result.response.body.entry.length).to.equal(4);
expect(JSON.parse(result.response.body).total).to.equal(4);
expect(JSON.parse(result.response.body).entry.length).to.equal(4);
nock.cleanAll();
});
});
Expand Down Expand Up @@ -424,8 +416,8 @@ describe('Middlewares', (): void => {
await mpiMdmSummaryMiddleware(request, response, () => {});
expect(statusCode).to.equal(200);
expect(result.status).to.equal('Success');
expect(result.response.body.total).to.equal(2);
expect(result.response.body.entry.length).to.equal(2);
expect(JSON.parse(result.response.body).total).to.equal(2);
expect(JSON.parse(result.response.body).entry.length).to.equal(2);
nock.cleanAll();
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Utils', (): void => {
expect(returnedObject.response.headers).to.deep.equal({
'Content-Type': contentType,
});
expect(returnedObject.response.body).to.deep.equal(body);
expect(JSON.parse(returnedObject.response.body)).to.deep.equal(body);
});
});

Expand Down Expand Up @@ -468,7 +468,7 @@ describe('Utils', (): void => {
);

expect(handlerResponse.status).to.equal(200);
expect(handlerResponse.body.response.body).to.deep.equal({
expect(JSON.parse(handlerResponse.body.response.body)).to.deep.equal({
message: 'Success',
});
});
Expand Down

0 comments on commit 40b39b2

Please sign in to comment.