|
1 | 1 | import { SetupFactoryOptions } from "../driver"; |
2 | | -import { customCheckItems } from "../mocks/custom-checks-template"; |
| 2 | +import { passedCustomCheckItems, customCheckItems } from "../mocks/custom-checks-template"; |
3 | 3 |
|
4 | | -const content = JSON.stringify([]); |
5 | | -const failedCustomCheckItems = customCheckItems.filter((check) => check.status === "Fail"); |
6 | | -const passedCustomCheckItems = customCheckItems.filter((check) => check.status === "Pass"); |
| 4 | +const emptyContent = JSON.stringify([]); |
7 | 5 |
|
8 | 6 | export const hasCustomChecksEmpty = ({ driver }: SetupFactoryOptions) => { |
9 | 7 | const serviceControlInstanceUrl = window.defaultConfig.service_control_url; |
10 | 8 | driver.mockEndpoint(`${serviceControlInstanceUrl}customchecks`, { |
11 | | - body: content, |
| 9 | + body: emptyContent, |
12 | 10 | headers: { |
13 | 11 | "Total-Count": "0", //count of failing custom checks |
14 | 12 | }, |
15 | 13 | }); |
16 | 14 | }; |
17 | 15 |
|
18 | | -export const hasCustomChecksFailing = ({ driver }: SetupFactoryOptions) => { |
| 16 | +export const hasCustomChecksPassing = ({ driver }: SetupFactoryOptions) => { |
19 | 17 | const serviceControlInstanceUrl = window.defaultConfig.service_control_url; |
20 | 18 | driver.mockEndpointDynamic(`${serviceControlInstanceUrl}customchecks`, (url) => { |
21 | 19 | const status = url.searchParams.get("status"); |
| 20 | + let dataForCustomCheckItems = passedCustomCheckItems; |
| 21 | + |
22 | 22 | if (status === "fail") { |
23 | | - return { |
24 | | - body: failedCustomCheckItems, |
25 | | - headers: { "Total-Count": failedCustomCheckItems.length.toString() }, |
26 | | - }; |
| 23 | + dataForCustomCheckItems = dataForCustomCheckItems.filter((check) => check.status === "Fail"); |
27 | 24 | } |
28 | 25 |
|
29 | 26 | return { |
30 | | - body: passedCustomCheckItems, |
31 | | - headers: { "Total-Count": passedCustomCheckItems.length.toString() }, |
| 27 | + body: dataForCustomCheckItems, |
| 28 | + headers: { "Total-Count": dataForCustomCheckItems.length.toString() }, |
32 | 29 | }; |
33 | 30 | }); |
34 | 31 | }; |
35 | | -export const hasCustomChecksPassing = ({ driver }: SetupFactoryOptions) => { |
| 32 | +export const hasCustomChecks = ({ driver }: SetupFactoryOptions) => { |
36 | 33 | const serviceControlInstanceUrl = window.defaultConfig.service_control_url; |
37 | | - driver.mockEndpoint(`${serviceControlInstanceUrl}customchecks`, { |
38 | | - body: passedCustomCheckItems, |
39 | | - headers: { |
40 | | - "Total-Count": passedCustomCheckItems.length.toString(), //count of passing custom checks |
41 | | - }, |
| 34 | + driver.mockEndpointDynamic(`${serviceControlInstanceUrl}customchecks`, (url) => { |
| 35 | + const status = url.searchParams.get("status"); |
| 36 | + let dataForCustomCheckItems = customCheckItems; |
| 37 | + |
| 38 | + if (status === "fail") { |
| 39 | + dataForCustomCheckItems = dataForCustomCheckItems.filter((check) => check.status === "Fail"); |
| 40 | + } |
| 41 | + |
| 42 | + return { |
| 43 | + body: dataForCustomCheckItems, |
| 44 | + headers: { "Total-Count": dataForCustomCheckItems.length.toString() }, |
| 45 | + }; |
42 | 46 | }); |
43 | 47 | }; |
0 commit comments