Skip to content

Commit 557432d

Browse files
authored
Merge pull request #54799 from FitseTLT/fix-auto-enabling-delayed-submission-on-upgrade
Fix - Workflows -"Delay submissions" is auto-enabled after upgrading workspace and then auto-disabled
2 parents 1b244b3 + 7b7713c commit 557432d

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/libs/actions/Policy/Policy.ts

-6
Original file line numberDiff line numberDiff line change
@@ -3466,10 +3466,6 @@ function upgradeToCorporate(policyID: string, featureName?: string) {
34663466
maxExpenseAmount: CONST.POLICY.DEFAULT_MAX_EXPENSE_AMOUNT,
34673467
maxExpenseAmountNoReceipt: CONST.POLICY.DEFAULT_MAX_AMOUNT_NO_RECEIPT,
34683468
glCodes: true,
3469-
...(PolicyUtils.isInstantSubmitEnabled(policy) && {
3470-
autoReporting: true,
3471-
autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.IMMEDIATE,
3472-
}),
34733469
harvesting: {
34743470
enabled: false,
34753471
},
@@ -3498,8 +3494,6 @@ function upgradeToCorporate(policyID: string, featureName?: string) {
34983494
maxExpenseAmount: policy?.maxExpenseAmount ?? null,
34993495
maxExpenseAmountNoReceipt: policy?.maxExpenseAmountNoReceipt ?? null,
35003496
glCodes: policy?.glCodes ?? null,
3501-
autoReporting: policy?.autoReporting ?? null,
3502-
autoReportingFrequency: policy?.autoReportingFrequency ?? null,
35033497
harvesting: policy?.harvesting ?? null,
35043498
},
35053499
},

tests/actions/PolicyTest.ts

+32
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,36 @@ describe('actions/Policy', () => {
190190
});
191191
});
192192
});
193+
194+
describe('upgradeToCorporate', () => {
195+
it('upgradeToCorporate should not alter initial values of autoReporting and autoReportingFrequency', async () => {
196+
const autoReporting = true;
197+
const autoReportingFrequency = CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT;
198+
// Given that a policy has autoReporting initially set to true and autoReportingFrequency set to instant.
199+
const fakePolicy: PolicyType = {
200+
...createRandomPolicy(0, CONST.POLICY.TYPE.TEAM),
201+
autoReporting,
202+
autoReportingFrequency,
203+
};
204+
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
205+
206+
// When a policy is upgradeToCorporate
207+
Policy.upgradeToCorporate(fakePolicy.id);
208+
await waitForBatchedUpdates();
209+
210+
const policy: OnyxEntry<PolicyType> = await new Promise((resolve) => {
211+
const connection = Onyx.connect({
212+
key: `${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`,
213+
callback: (workspace) => {
214+
Onyx.disconnect(connection);
215+
resolve(workspace);
216+
},
217+
});
218+
});
219+
220+
// Then the policy autoReporting and autoReportingFrequency should equal the initial value.
221+
expect(policy?.autoReporting).toBe(autoReporting);
222+
expect(policy?.autoReportingFrequency).toBe(autoReportingFrequency);
223+
});
224+
});
193225
});

0 commit comments

Comments
 (0)