Skip to content

Commit a0062cd

Browse files
authored
fix: prevent submitting alerts per check when FF is off (#1068)
1 parent 68bd4bf commit a0062cd

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

‎src/components/CheckForm/checkForm.hooks.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import { ScriptedCheckSchema } from 'schemas/forms/ScriptedCheckSchema';
1010
import { TCPCheckSchema } from 'schemas/forms/TCPCheckSchema';
1111
import { TracerouteCheckSchema } from 'schemas/forms/TracerouteCheckSchema';
1212

13-
import { Check, CheckAlertDraft, CheckAlertFormRecord, CheckFormValues, CheckType } from 'types';
13+
import { Check, CheckAlertDraft, CheckAlertFormRecord, CheckFormValues, CheckType, FeatureName } from 'types';
1414
import { ROUTES } from 'routing/types';
1515
import { AdHocCheckResponse } from 'datasource/responses.types';
1616
import { useUpdateAlertsForCheck } from 'data/useCheckAlerts';
1717
import { useCUDChecks, useTestCheck } from 'data/useChecks';
18+
import { useFeatureFlag } from 'hooks/useFeatureFlag';
1819
import { useNavigation } from 'hooks/useNavigation';
1920
import { toPayload } from 'components/CheckEditor/checkFormTransformations';
2021
import { getAlertsPayload } from 'components/CheckEditor/transformations/toPayload.alerts';
@@ -54,6 +55,7 @@ export function useCheckForm({ check, checkType, onTestSuccess }: UseCheckFormPr
5455
const { mutate: testCheck, isPending, error: testError } = useTestCheck({ eventInfo: { checkType } });
5556

5657
const navigateToChecks = useCallback(() => navigate(ROUTES.Checks), [navigate]);
58+
const alertsEnabled = useFeatureFlag(FeatureName.AlertsPerCheck).isEnabled;
5759

5860
const onError = (err: Error | unknown) => {
5961
setSubmittingToApi(false);
@@ -102,9 +104,9 @@ export function useCheckForm({ check, checkType, onTestSuccess }: UseCheckFormPr
102104
return testCheck(toSubmit, { onSuccess: onTestSuccess });
103105
}
104106

105-
mutateCheck(toSubmit, checkValues?.alerts);
107+
mutateCheck(toSubmit, alertsEnabled ? checkValues?.alerts : undefined);
106108
},
107-
[mutateCheck, onTestSuccess, testCheck]
109+
[mutateCheck, onTestSuccess, testCheck, alertsEnabled]
108110
);
109111

110112
const handleInvalid = useCallback((errs: FieldErrors) => {

‎src/page/NewCheck/__tests__/ApiEndPointChecks/CommonFields.payload.test.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ describe('Api endpoint checks - common fields payload', () => {
9999
[FeatureName.AlertsPerCheck]: true,
100100
});
101101

102-
103102
const { user, read } = await renderNewForm(checkType);
104-
103+
105104
await fillMandatoryFields({ user, checkType });
106105

107106
await goToSection(user, 4);
@@ -122,6 +121,27 @@ describe('Api endpoint checks - common fields payload', () => {
122121

123122
expect(alertsBody).toEqual({ alerts: [{ name: 'ProbeFailedExecutionsTooHigh', threshold: 0.1 }] });
124123
});
124+
125+
it(`does not submit aletrs per check when the feature flag is disabled`, async () => {
126+
jest.replaceProperty(config, 'featureToggles', {
127+
// @ts-expect-error
128+
[FeatureName.AlertsPerCheck]: false,
129+
});
130+
131+
const { user, read } = await renderNewForm(checkType);
132+
133+
await fillMandatoryFields({ user, checkType });
134+
135+
await goToSection(user, 4);
136+
137+
expect(screen.queryByText('Predefined alerts')).not.toBeInTheDocument();
138+
139+
await submitForm(user);
140+
141+
const { body: alertsBody } = await read(1);
142+
143+
expect(alertsBody).toEqual(undefined);
144+
});
125145
});
126146

127147
describe(`Section 5 (Execution)`, () => {

0 commit comments

Comments
 (0)