Skip to content

Commit 2bff573

Browse files
committed
use mockEndpointDynamic to add customchecks url by querystring
1 parent a624624 commit 2bff573

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/Frontend/test/preconditions/customChecks.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { customCheckItems } from "../mocks/custom-checks-template";
33

44
const content = JSON.stringify([]);
55
const failedCustomCheckItems = customCheckItems.filter((check) => check.status === "Fail");
6-
const failedCustomCheckCount = failedCustomCheckItems.length.toString();
76
const passedCustomCheckItems = customCheckItems.filter((check) => check.status === "Pass");
8-
const passedCustomCheckCount = passedCustomCheckItems.length.toString();
97

108
export const hasCustomChecksEmpty = ({ driver }: SetupFactoryOptions) => {
119
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
@@ -16,21 +14,30 @@ export const hasCustomChecksEmpty = ({ driver }: SetupFactoryOptions) => {
1614
},
1715
});
1816
};
17+
1918
export const hasCustomChecksFailing = ({ driver }: SetupFactoryOptions) => {
2019
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
21-
driver.mockEndpoint(`${serviceControlInstanceUrl}customchecks`, {
22-
body: failedCustomCheckItems,
23-
headers: {
24-
"Total-Count": failedCustomCheckCount, //count of failing custom checks
25-
},
20+
driver.mockEndpointDynamic(`${serviceControlInstanceUrl}customchecks`, (url) => {
21+
const status = url.searchParams.get("status");
22+
if (status === "fail") {
23+
return {
24+
body: failedCustomCheckItems,
25+
headers: { "Total-Count": failedCustomCheckItems.length.toString() },
26+
};
27+
}
28+
29+
return {
30+
body: passedCustomCheckItems,
31+
headers: { "Total-Count": passedCustomCheckItems.length.toString() },
32+
};
2633
});
2734
};
2835
export const hasCustomChecksPassing = ({ driver }: SetupFactoryOptions) => {
2936
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
3037
driver.mockEndpoint(`${serviceControlInstanceUrl}customchecks`, {
3138
body: passedCustomCheckItems,
3239
headers: {
33-
"Total-Count": passedCustomCheckCount, //count of passing custom checks
40+
"Total-Count": passedCustomCheckItems.length.toString(), //count of passing custom checks
3441
},
3542
});
3643
};

0 commit comments

Comments
 (0)