Skip to content
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
5 changes: 5 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
32 changes: 32 additions & 0 deletions tests/actions/PolicyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,38 @@ 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<PolicyType> = 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?.();
Expand Down
Loading