From b150017e4cd73404b24b65b4c0a854df2a72acd0 Mon Sep 17 00:00:00 2001 From: "David E. Gelhar" Date: Wed, 19 Feb 2025 21:17:12 -0500 Subject: [PATCH 1/3] When disabling workflows, set autoreporting back to "immediately" --- src/libs/actions/Policy/Policy.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 21ea41bab8a8e..a441f9332ab99 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -3203,6 +3203,11 @@ function enablePolicyWorkflows(policyID: string, enabled: boolean) { const parameters: EnablePolicyWorkflowsParams = {policyID, enabled}; + // When disabling workflows, set autoreporting back to "immediately" + if (!enabled) { + setWorkspaceAutoReportingFrequency(policyID, CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT); + } + API.write(WRITE_COMMANDS.ENABLE_POLICY_WORKFLOWS, parameters, onyxData); if (enabled && getIsNarrowLayout()) { From ed3322f69459609ab34d960a4cc050f553c40d19 Mon Sep 17 00:00:00 2001 From: "David E. Gelhar" Date: Thu, 20 Feb 2025 20:52:56 -0500 Subject: [PATCH 2/3] test for enablePolicyWorkflows updating autoReportingFrequency --- tests/actions/PolicyTest.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/actions/PolicyTest.ts b/tests/actions/PolicyTest.ts index 07820ce1cd30d..d31304238c2c4 100644 --- a/tests/actions/PolicyTest.ts +++ b/tests/actions/PolicyTest.ts @@ -249,6 +249,39 @@ describe('actions/Policy', () => { }); }); + describe('disableWorkflows', () => { + it('disableWorkflow should reset autoReportingFrequency to INSTANT', async () => { + const autoReporting = true; + const autoReportingFrequency = CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MONTHLY; + // Given that a policy has autoReporting initially set to true and autoReportingFrequency set to monthly. + const fakePolicy: PolicyType = { + ...createRandomPolicy(0, CONST.POLICY.TYPE.TEAM), + autoReporting, + autoReportingFrequency, + }; + await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy); + + // When workflows are disabled for the policy + Policy.enablePolicyWorkflows(fakePolicy.id, false); + await waitForBatchedUpdates(); + + const policy: OnyxEntry = await new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, + callback: (workspace) => { + Onyx.disconnect(connection); + resolve(workspace); + }, + }); + }); + + // Then the policy autoReportingFrequency should revert to "INSTANT" + expect(policy?.autoReporting).toBe(false); + expect(policy?.autoReportingFrequency).toBe(CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT); + + }); + }); + describe('enablePolicyRules', () => { it('should disable preventSelfApproval when the rule feature is turned off', async () => { (fetch as MockFetch)?.pause?.(); From 0b184c46993f47076c470d9536e24fee0ca0aa30 Mon Sep 17 00:00:00 2001 From: "David E. Gelhar" Date: Thu, 20 Feb 2025 20:58:24 -0500 Subject: [PATCH 3/3] prettier --- tests/actions/PolicyTest.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/actions/PolicyTest.ts b/tests/actions/PolicyTest.ts index d31304238c2c4..f32f9fe7794fd 100644 --- a/tests/actions/PolicyTest.ts +++ b/tests/actions/PolicyTest.ts @@ -261,7 +261,7 @@ describe('actions/Policy', () => { }; await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy); - // When workflows are disabled for the policy + // When workflows are disabled for the policy Policy.enablePolicyWorkflows(fakePolicy.id, false); await waitForBatchedUpdates(); @@ -274,11 +274,10 @@ describe('actions/Policy', () => { }, }); }); - + // Then the policy autoReportingFrequency should revert to "INSTANT" expect(policy?.autoReporting).toBe(false); expect(policy?.autoReportingFrequency).toBe(CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT); - }); });