Skip to content

Commit

Permalink
Merge pull request #2256 from metriport/develop
Browse files Browse the repository at this point in the history
RELEASE 1634 Adjustment to E2E tests + Sentry sample rate
  • Loading branch information
leite08 committed Jun 12, 2024
2 parents db31e87 + a78fd27 commit ab54b02
Show file tree
Hide file tree
Showing 30 changed files with 175 additions and 152 deletions.
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/api-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metriport/api-sdk",
"version": "8.1.1",
"version": "8.2.1",
"description": "Metriport helps you access and manage health and medical data, through a single open source API.",
"author": "Metriport Inc. <[email protected]>",
"homepage": "https://metriport.com/",
Expand Down Expand Up @@ -57,8 +57,8 @@
},
"dependencies": {
"@medplum/fhirtypes": "^2.0.32",
"@metriport/commonwell-sdk": "^4.15.11",
"@metriport/shared": "^0.9.4",
"@metriport/commonwell-sdk": "^4.15.13",
"@metriport/shared": "^0.9.6",
"axios": "^1.3.4",
"dayjs": "^1.11.7",
"dotenv": "^16.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export { User } from "./devices/models/user";

// Medical API
export {
WebhookRequestParsingError,
WebhookRequestParsingFailure,
WebhookRequest,
WebhookRequestStatus,
WebhookType,
Expand Down
8 changes: 4 additions & 4 deletions packages/api-sdk/src/medical/client/metriport.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Bundle, DocumentReference as FHIRDocumentReference, Resource } from "@medplum/fhirtypes";
import {
WebhookRequest,
WebhookRequestParsingError,
WebhookRequestParsingFailure,
webhookRequestSchema,
WebhookStatusResponse,
} from "@metriport/shared/medical";
Expand Down Expand Up @@ -709,13 +709,13 @@ export class MetriportMedicalApi {
static parseWebhookResponse(
requestBody: unknown,
throwOnError: false
): WebhookRequest | WebhookRequestParsingError;
): WebhookRequest | WebhookRequestParsingFailure;
static parseWebhookResponse(reqBody: unknown, throwOnError: true): WebhookRequest;
static parseWebhookResponse(reqBody: unknown): WebhookRequest;
static parseWebhookResponse(
reqBody: unknown,
throwOnError = true
): WebhookRequest | WebhookRequestParsingError {
): WebhookRequest | WebhookRequestParsingFailure {
if (throwOnError) {
try {
return webhookRequestSchema.parse(reqBody);
Expand All @@ -725,6 +725,6 @@ export class MetriportMedicalApi {
}
const parse = webhookRequestSchema.safeParse(reqBody);
if (parse.success) return parse.data;
return new WebhookRequestParsingError(parse.error, parse.error.format());
return new WebhookRequestParsingFailure(parse.error, parse.error.format());
}
}
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api",
"version": "1.18.1",
"version": "1.18.3",
"description": "",
"main": "app.js",
"private": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import isBetween from "dayjs/plugin/isBetween";
import fs from "fs";
import { validate as validateUuid } from "uuid";
import { e2eResultsFolderName } from "../../shared";
import { E2eContext, medicalApi } from "../shared";
import { getConsolidatedWebhookRequest, resetConsolidatedData } from "../webhook/consolidated";
import { checkWebhookRequestMeta } from "../webhook/shared";
import {
checkConsolidatedHtml,
checkConsolidatedJson,
Expand Down Expand Up @@ -130,10 +130,11 @@ export function runConsolidatedTests(e2e: E2eContext) {
let conversionProgresses = await medicalApi.getConsolidatedQueryStatus(e2e.patient.id);
let initConversionProgress = conversionProgresses?.queries?.[0];
let retryLimit = 0;
while (
initConversionProgress?.status !== "completed" &&
retryLimit++ < conversionCheckStatusMaxRetries
) {
while (initConversionProgress?.status !== "completed") {
if (retryLimit++ > conversionCheckStatusMaxRetries) {
console.log(`Gave up waiting for Conversion`);
break;
}
console.log(
`Conversion still processing, retrying in ${conversionCheckStatusWaitTime.asSeconds()} seconds...`
);
Expand Down Expand Up @@ -165,25 +166,7 @@ export function runConsolidatedTests(e2e: E2eContext) {

it(`receives consolidated ${format} WH with correct meta`, async () => {
const whRequest = getConsolidatedWebhookRequest();
expect(whRequest).toBeTruthy();
if (!whRequest) throw new Error("Missing WH request");
expect(whRequest.meta).toBeTruthy();
expect(whRequest.meta).toEqual(
expect.objectContaining({
type: "medical.consolidated-data",
messageId: expect.anything(),
when: expect.anything(),
})
);
expect(validateUuid(whRequest.meta.messageId)).toBeTrue();
const minDate = dayjs().subtract(1, "minute").toDate();
const maxDate = dayjs().add(1, "minute").toDate();
expect(dayjs(whRequest.meta.when).isBetween(minDate, maxDate)).toBeTrue();
expect(whRequest.meta).not.toEqual(
expect.objectContaining({
data: expect.toBeFalsy,
})
);
checkWebhookRequestMeta(whRequest, "medical.consolidated-data");
});

it(`receives consolidated ${format} WH with MR in ${format} format`, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export function runDocumentQueryTests(e2e: E2eContext) {
);
let status = await medicalApi.getDocumentQueryStatus(e2e.patient.id);
let retryLimit = 0;
while (areDocumentsProcessing(status) && retryLimit++ < dqCheckStatusMaxRetries) {
while (areDocumentsProcessing(status)) {
if (retryLimit++ > dqCheckStatusMaxRetries) {
console.log(`Gave up waiting for Document Query`);
break;
}
console.log(
`Document query still processing, retrying in ${dqCheckStatusWaitTime.asSeconds} seconds...`
);
Expand Down
21 changes: 2 additions & 19 deletions packages/api/src/__tests__/e2e/mapi/parts/settings.test.part.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { sleep } from "@metriport/shared";
import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import isBetween from "dayjs/plugin/isBetween";
import { validate as validateUuid } from "uuid";
import { medicalApi } from "../shared";
import { getPingWebhookRequest } from "../webhook/settings";
import { checkWebhookRequestMeta } from "../webhook/shared";
import whServer from "../webhook/webhook-server";

dayjs.extend(isBetween);
Expand Down Expand Up @@ -62,25 +62,8 @@ export function runSettingsTests() {

it("receives ping WH with correct data", async () => {
const whRequest = getPingWebhookRequest();
expect(whRequest).toBeTruthy();
checkWebhookRequestMeta(whRequest, "ping");
if (!whRequest) throw new Error("Missing WH request");
expect(whRequest.meta).toBeTruthy();
expect(whRequest.meta).toEqual(
expect.objectContaining({
type: "ping",
messageId: expect.anything(),
when: expect.anything(),
})
);
expect(validateUuid(whRequest.meta.messageId)).toBeTrue();
const minDate = dayjs().subtract(1, "minute").toDate();
const maxDate = dayjs().add(1, "minute").toDate();
expect(dayjs(whRequest.meta.when).isBetween(minDate, maxDate)).toBeTrue();
expect(whRequest.meta).not.toEqual(
expect.objectContaining({
data: expect.toBeFalsy,
})
);
expect(whRequest.ping).toBeTruthy();
expect(whRequest.ping.length).toEqual(NANO_ID_LENGTH);
});
Expand Down
6 changes: 5 additions & 1 deletion packages/api/src/__tests__/e2e/mapi/webhook/consolidated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export function resetConsolidatedData(
}

export function handleConsolidated(whRequest: ConsolidatedWebhookRequest, res: Response) {
console.log(`[WH] ================> Handle Consolidated WH running...`);
console.log(
`[WH] ================> Handle Consolidated WH running... whRequest: ${
whRequest ? whRequest.patients?.length + " patients" : whRequest
}`
);
webhookRequest = whRequest;
return res.sendStatus(200);
}
2 changes: 1 addition & 1 deletion packages/api/src/__tests__/e2e/mapi/webhook/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function resetPingData(value: PingWebhookRequest | undefined = undefined)
}

export function handlePing(whRequest: PingWebhookRequest, res: Response) {
console.log(`[WH] ================> Handle Ping WH running...`);
console.log(`[WH] ================> Handle Ping WH running... ping: ${whRequest.ping}`);
webhookRequest = whRequest;
return res.status(200).send({ pong: whRequest.ping });
}
31 changes: 31 additions & 0 deletions packages/api/src/__tests__/e2e/mapi/webhook/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { WebhookRequest } from "@metriport/shared/medical";
import dayjs from "dayjs";
import { validate as validateUuid } from "uuid";

export function checkWebhookRequestMeta(
whRequest: WebhookRequest | undefined,
type: WebhookRequest["meta"]["type"]
): void {
expect(whRequest).toBeTruthy();
if (!whRequest) throw new Error("Missing WH request");
expect(whRequest.meta).toBeTruthy();
expect(whRequest.meta).toEqual(
expect.objectContaining({
type,
messageId: expect.anything(),
when: expect.anything(),
})
);
expect(validateUuid(whRequest.meta.messageId)).toBeTrue();
const expectedRefDate = dayjs();
const expectedMminDate = expectedRefDate.subtract(1, "minute").toDate();
const expectedMaxDate = dayjs().add(1, "minute").toDate();
const receivedDate = dayjs(whRequest.meta.when).toDate();
expect(receivedDate).toBeAfterOrEqualTo(expectedMminDate);
expect(receivedDate).toBeBeforeOrEqualTo(expectedMaxDate);
expect(whRequest.meta).not.toEqual(
expect.objectContaining({
data: expect.toBeFalsy,
})
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function handleRequest(req: Request, res: Response) {
return res.status(400).send({ message: `Invalid WH` });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
console.log(`[WH] ====> Error parsing WH request - cause: ${error.cause} - error: ${error}`);
console.log(`[WH] ######> ERROR parsing WH request - cause: ${error.cause} - error: ${error}`);
return res.status(400).send({ message: error.message });
}
}
Expand Down
10 changes: 7 additions & 3 deletions packages/api/src/__tests__/e2e/mapi/webhook/webhook-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import { getEnvVar, getEnvVarOrFail, sleep } from "@metriport/shared";
import ngrok, { Session } from "@ngrok/ngrok";
import express, { Request, Response } from "express";
import { Server } from "http";
import { asyncHandler } from "../../../../routes/util";
import whHandler from "./webhook-handler";

const port = 8478;

const app = express();
app.use(express.json({ limit: "20mb" }));

app.post("/", async (req: Request, res: Response) => {
await whHandler.handleRequest(req, res);
});
app.post(
"/",
asyncHandler(async (req: Request, res: Response) => {
await whHandler.handleRequest(req, res);
}, true)
);

let server: Server;
let session: Session;
Expand Down
Loading

0 comments on commit ab54b02

Please sign in to comment.