Skip to content

Commit

Permalink
Merge pull request #54799 from FitseTLT/fix-auto-enabling-delayed-sub…
Browse files Browse the repository at this point in the history
…mission-on-upgrade

Fix - Workflows -"Delay submissions" is auto-enabled after upgrading workspace and then auto-disabled
  • Loading branch information
robertjchen authored Jan 8, 2025
2 parents 1b244b3 + 7b7713c commit 557432d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3466,10 +3466,6 @@ function upgradeToCorporate(policyID: string, featureName?: string) {
maxExpenseAmount: CONST.POLICY.DEFAULT_MAX_EXPENSE_AMOUNT,
maxExpenseAmountNoReceipt: CONST.POLICY.DEFAULT_MAX_AMOUNT_NO_RECEIPT,
glCodes: true,
...(PolicyUtils.isInstantSubmitEnabled(policy) && {
autoReporting: true,
autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.IMMEDIATE,
}),
harvesting: {
enabled: false,
},
Expand Down Expand Up @@ -3498,8 +3494,6 @@ function upgradeToCorporate(policyID: string, featureName?: string) {
maxExpenseAmount: policy?.maxExpenseAmount ?? null,
maxExpenseAmountNoReceipt: policy?.maxExpenseAmountNoReceipt ?? null,
glCodes: policy?.glCodes ?? null,
autoReporting: policy?.autoReporting ?? null,
autoReportingFrequency: policy?.autoReportingFrequency ?? null,
harvesting: policy?.harvesting ?? null,
},
},
Expand Down
32 changes: 32 additions & 0 deletions tests/actions/PolicyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,36 @@ describe('actions/Policy', () => {
});
});
});

describe('upgradeToCorporate', () => {
it('upgradeToCorporate should not alter initial values of autoReporting and autoReportingFrequency', async () => {
const autoReporting = true;
const autoReportingFrequency = CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT;
// Given that a policy has autoReporting initially set to true and autoReportingFrequency set to instant.
const fakePolicy: PolicyType = {
...createRandomPolicy(0, CONST.POLICY.TYPE.TEAM),
autoReporting,
autoReportingFrequency,
};
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);

// When a policy is upgradeToCorporate
Policy.upgradeToCorporate(fakePolicy.id);
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 autoReporting and autoReportingFrequency should equal the initial value.
expect(policy?.autoReporting).toBe(autoReporting);
expect(policy?.autoReportingFrequency).toBe(autoReportingFrequency);
});
});
});

0 comments on commit 557432d

Please sign in to comment.