Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #743 from MeasureAuthoringTool/MAT-7737
Browse files Browse the repository at this point in the history
MAT-7737 validate test case bundles based on model type
  • Loading branch information
adongare authored Oct 28, 2024
2 parents 64605f9 + c0e805d commit 660445d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
18 changes: 10 additions & 8 deletions src/api/TestCaseServiceApi.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { AxiosError, AxiosResponse } from "axios";
import axios from "./axios-instance";
import { TestCaseServiceApi } from "./useTestCaseServiceApi";
import {
QrdaGroupExportDTO,
TestCaseServiceApi,
} from "./useTestCaseServiceApi";
import { ScanValidationDto } from "./models/ScanValidationDto";
import {
Measure,
MeasureScoring,
Model,
PopulationType,
TestCase,
TestCaseExcelExportDto,
} from "@madie/madie-models";
import { waitFor } from "@testing-library/react";
import { addValues } from "../util/DefaultValueProcessor";
Expand Down Expand Up @@ -236,14 +238,14 @@ describe("TestCaseServiceApi Tests", () => {
const resp = { status: 200, data: zippedQRDAData };
axios.put = jest.fn().mockResolvedValueOnce(resp);

const testCaseDtos: TestCaseExcelExportDto[] = [
const groupDTOs: QrdaGroupExportDTO[] = [
{
groupId: "1",
} as TestCaseExcelExportDto,
} as QrdaGroupExportDTO,
];
const qrdaData = await testCaseService.exportQRDA("testMeasureId", {
measure: mockMeasure,
groupDTOs: testCaseDtos,
groupDTOs: groupDTOs,
});
expect(axios.put).toBeCalledTimes(1);
expect(qrdaData).toEqual(zippedQRDAData);
Expand All @@ -255,15 +257,15 @@ describe("TestCaseServiceApi Tests", () => {
};
axios.put = jest.fn().mockRejectedValueOnce(resp);

const testCaseDtos: TestCaseExcelExportDto[] = [
const groupDTOs: QrdaGroupExportDTO[] = [
{
groupId: "1",
} as TestCaseExcelExportDto,
} as QrdaGroupExportDTO,
];
try {
await testCaseService.exportQRDA("testMeasureId", {
measure: mockMeasure,
groupDTOs: testCaseDtos,
groupDTOs: groupDTOs,
});
expect(axios.put).toBeCalledTimes(1);
} catch (error) {
Expand Down
10 changes: 8 additions & 2 deletions src/api/useTestCaseServiceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ export class TestCaseServiceApi {
}
}

async getTestCase(testCaseId: string, measureId: string): Promise<TestCase> {
async getTestCase(
testCaseId: string,
measureId: string,
validateTest: boolean
): Promise<TestCase> {
try {
const response = await axios.get<TestCase>(
`${this.baseUrl}/measures/${measureId}/test-cases/${testCaseId}`,
{
params: { validate: validateTest },
headers: {
Authorization: `Bearer ${this.getAccessToken()}`,
},
Expand Down Expand Up @@ -207,12 +212,13 @@ export class TestCaseServiceApi {
);
}

async validateTestCaseBundle(bundle: any) {
async validateTestCaseBundle(bundle: any, model: string) {
try {
const response = await axios.post<HapiOperationOutcome>(
`${this.baseUrl}/validations/bundles`,
bundle,
{
params: { model: model },
headers: {
Authorization: `Bearer ${this.getAccessToken()}`,
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/editTestCase/qdm/EditTestCase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const EditTestCase = () => {
useEffect(() => {
if (measure && measureId && id) {
testCaseService.current
.getTestCase(id, measureId)
.getTestCase(id, measureId, false)
.then((tc: TestCase) => {
const nextTc = _.cloneDeep(tc);
if (measure?.groups) {
Expand Down
8 changes: 5 additions & 3 deletions src/components/editTestCase/qiCore/EditTestCase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ const EditTestCase = (props: EditTestCaseProps) => {

const loadTestCase = () => {
testCaseService.current
.getTestCase(id, measureId)
.getTestCase(id, measureId, true)
.then((tc: TestCase) => {
const nextTc = _.cloneDeep(tc);
nextTc.json = standardizeJson(nextTc);
Expand Down Expand Up @@ -542,7 +542,8 @@ const EditTestCase = (props: EditTestCaseProps) => {
// Validate test case JSON prior to execution
const validationResult =
await testCaseService.current.validateTestCaseBundle(
JSON.parse(editorVal)
JSON.parse(editorVal),
measure.model
);
const errors = handleHapiOutcome(validationResult);
if (!_.isNil(errors) && errors.length > 0 && hasErrorSeverity(errors)) {
Expand Down Expand Up @@ -577,7 +578,8 @@ const EditTestCase = (props: EditTestCaseProps) => {
const executionResults = calculationOutput.results;
const validationResult =
await testCaseService.current.validateTestCaseBundle(
JSON.parse(editorVal)
JSON.parse(editorVal),
measure.model
);
handleHapiOutcome(validationResult);
setCalculationErrors(undefined);
Expand Down

0 comments on commit 660445d

Please sign in to comment.