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

MAT-7737 validate test case bundles based on model type #743

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading