diff --git a/src/components/FloatingCameraButton/BaseFloatingCameraButton.tsx b/src/components/FloatingCameraButton/BaseFloatingCameraButton.tsx index 1b5548b1bc2f..181fecaa42e2 100644 --- a/src/components/FloatingCameraButton/BaseFloatingCameraButton.tsx +++ b/src/components/FloatingCameraButton/BaseFloatingCameraButton.tsx @@ -60,10 +60,7 @@ function BaseFloatingCameraButton({icon}: BaseFloatingCameraButtonProps) { const onPress = () => { interceptAnonymousUser(() => { - if ( - policyChatForActivePolicy?.policyID && - shouldRestrictUserBillableActions(policyChatForActivePolicy.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy, accountID) - ) { + if (policyChatForActivePolicy?.policyID && shouldRestrictUserBillableActions(activePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policyChatForActivePolicy.policyID)); return; } diff --git a/src/components/MoneyRequestReportView/SearchMoneyRequestReportEmptyState.tsx b/src/components/MoneyRequestReportView/SearchMoneyRequestReportEmptyState.tsx index 45c2d194d3e8..76068e8092b4 100644 --- a/src/components/MoneyRequestReportView/SearchMoneyRequestReportEmptyState.tsx +++ b/src/components/MoneyRequestReportView/SearchMoneyRequestReportEmptyState.tsx @@ -46,7 +46,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report: if (!reportId) { return; } - if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy, accountID)) { + if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id)); return; } @@ -61,7 +61,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report: if (!reportId) { return; } - if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy, accountID)) { + if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id)); return; } @@ -73,7 +73,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report: text: translate('iou.addUnreportedExpense'), icon: icons.ReceiptPlus, onSelected: () => { - if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy, accountID)) { + if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id)); return; } diff --git a/src/components/Navigation/QuickCreationActionsBar/index.tsx b/src/components/Navigation/QuickCreationActionsBar/index.tsx index 661cc3744eb1..002a41dc5697 100644 --- a/src/components/Navigation/QuickCreationActionsBar/index.tsx +++ b/src/components/Navigation/QuickCreationActionsBar/index.tsx @@ -177,30 +177,14 @@ function QuickCreationActionsBar() { if ( !workspaceIDForReportCreation || - (shouldRestrictUserBillableActions( - workspaceIDForReportCreation, - ownerBillingGracePeriodEnd, - userBillingGracePeriodEnds, - amountOwed, - defaultChatEnabledPolicy, - currentUserPersonalDetails.accountID, - ) && + (shouldRestrictUserBillableActions(defaultChatEnabledPolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserPersonalDetails.accountID) && groupPoliciesWithChatEnabled.length > 1) ) { Navigation.navigate(ROUTES.NEW_REPORT_WORKSPACE_SELECTION.getRoute()); return; } - if ( - !shouldRestrictUserBillableActions( - workspaceIDForReportCreation, - ownerBillingGracePeriodEnd, - userBillingGracePeriodEnds, - amountOwed, - defaultChatEnabledPolicy, - currentUserPersonalDetails.accountID, - ) - ) { + if (!shouldRestrictUserBillableActions(defaultChatEnabledPolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserPersonalDetails.accountID)) { if (shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy) { openCreateReportConfirmation(); } else { diff --git a/src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx b/src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx index e5133511f6d3..40e6e832763c 100644 --- a/src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx +++ b/src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx @@ -187,11 +187,10 @@ function SearchActionsBarCreateButton() { if ( !workspaceIDForReportCreation || (shouldRestrictUserBillableActions( - workspaceIDForReportCreation, + defaultChatEnabledPolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, - undefined, currentUserPersonalDetails.accountID, ) && groupPoliciesWithChatEnabled.length > 1) @@ -203,11 +202,10 @@ function SearchActionsBarCreateButton() { // Default workspace is not restricted → create report directly if ( !shouldRestrictUserBillableActions( - workspaceIDForReportCreation, + defaultChatEnabledPolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, - undefined, currentUserPersonalDetails.accountID, ) ) { @@ -240,6 +238,7 @@ function SearchActionsBarCreateButton() { handleCreateWorkspaceReport, amountOwed, currentUserPersonalDetails.accountID, + defaultChatEnabledPolicy, ], ); diff --git a/src/components/SettlementButton/index.tsx b/src/components/SettlementButton/index.tsx index 221ea34077c1..0392a7265f21 100644 --- a/src/components/SettlementButton/index.tsx +++ b/src/components/SettlementButton/index.tsx @@ -227,7 +227,7 @@ function SettlementButton({ return true; } - if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy, currentUserAccountID)) { + if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserAccountID)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id)); return true; } diff --git a/src/hooks/useExpenseActions.ts b/src/hooks/useExpenseActions.ts index a36f3a4f09c4..0b18960ff1d4 100644 --- a/src/hooks/useExpenseActions.ts +++ b/src/hooks/useExpenseActions.ts @@ -544,7 +544,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic if (!moneyRequestReport?.reportID) { return; } - if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) { + if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id)); return; } diff --git a/src/hooks/useReceiptScanDrop.tsx b/src/hooks/useReceiptScanDrop.tsx index 81410c95ade6..196f42c75d6b 100644 --- a/src/hooks/useReceiptScanDrop.tsx +++ b/src/hooks/useReceiptScanDrop.tsx @@ -82,7 +82,7 @@ function useReceiptScanDrop() { if ( isPaidGroupPolicy(activePolicy) && activePolicy?.isPolicyExpenseChatEnabled && - !shouldRestrictUserBillableActions(activePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy, currentUserPersonalDetails.accountID) + !shouldRestrictUserBillableActions(activePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserPersonalDetails.accountID) ) { const shouldAutoReport = !!activePolicy?.autoReporting || !!personalPolicy?.autoReporting; const report = shouldAutoReport ? getPolicyExpenseChat(currentUserPersonalDetails.accountID, activePolicy?.id) : selfDMReport; diff --git a/src/hooks/useSearchBulkActions.ts b/src/hooks/useSearchBulkActions.ts index 02464ebd93b9..dca07e85c9b1 100644 --- a/src/hooks/useSearchBulkActions.ts +++ b/src/hooks/useSearchBulkActions.ts @@ -105,8 +105,7 @@ function getRestrictedPolicyID( .map((item) => item.policyID) .find( (policyID): policyID is string => - !!policyID && - shouldRestrictUserBillableActions(policyID, ownerBillingGracePeriodEnd, billingGracePeriods, amountOwed, allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]), + !!policyID && shouldRestrictUserBillableActions(allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`], ownerBillingGracePeriodEnd, billingGracePeriods, amountOwed), ); } diff --git a/src/libs/PaymentUtils.ts b/src/libs/PaymentUtils.ts index 655411bd74dc..1e4ca94d9abf 100644 --- a/src/libs/PaymentUtils.ts +++ b/src/libs/PaymentUtils.ts @@ -239,7 +239,7 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => { ownerBillingGracePeriodEnd, delegateEmail, } = params; - if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) { + if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id)); return; } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 5484e8625d3c..c0b21332a17e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3019,11 +3019,7 @@ function getAddExpenseDropdownOptions({ if (!iouReportID) { return; } - if ( - policy && - policy.type !== CONST.POLICY.TYPE.PERSONAL && - shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy) - ) { + if (policy && policy.type !== CONST.POLICY.TYPE.PERSONAL && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id)); return; } @@ -3039,7 +3035,7 @@ function getAddExpenseDropdownOptions({ if (!iouReportID) { return; } - if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) { + if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id)); return; } @@ -3052,7 +3048,7 @@ function getAddExpenseDropdownOptions({ icon: icons.ReceiptPlus, sentryLabel: CONST.SENTRY_LABEL.MORE_MENU.ADD_EXPENSE_UNREPORTED, onSelected: () => { - if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) { + if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id)); return; } @@ -11499,7 +11495,7 @@ function createDraftTransactionAndNavigateToParticipantSelector({ } if (actionName === CONST.IOU.ACTION.CATEGORIZE) { - if (activePolicy && shouldRestrictUserBillableActions(activePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy)) { + if (activePolicy && shouldRestrictUserBillableActions(activePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(activePolicy.id)); return; } diff --git a/src/libs/SubscriptionUtils.ts b/src/libs/SubscriptionUtils.ts index fdf19aa185c4..18d5932145e0 100644 --- a/src/libs/SubscriptionUtils.ts +++ b/src/libs/SubscriptionUtils.ts @@ -455,13 +455,13 @@ function doesUserHavePaymentCardAdded(userBillingFundID: number | undefined): bo * Whether the user's billable actions should be restricted. */ function shouldRestrictUserBillableActions( - policyID: string, + policyIDOrPolicy: string | OnyxEntry, ownerBillingGracePeriodEnd: OnyxEntry, userBillingGracePeriodEnds: OnyxCollection, amountOwed: OnyxEntry, - policy: OnyxEntry = deprecatedAllPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`], currentUserAccountID: number = deprecatedCurrentUserAccountID, ): boolean { + const policy = typeof policyIDOrPolicy === 'string' ? deprecatedAllPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyIDOrPolicy}`] : policyIDOrPolicy; const currentDate = new Date(); // This logic will be executed if the user is a workspace's non-owner (normal user or admin). diff --git a/src/libs/actions/IOU/ReportWorkflow.ts b/src/libs/actions/IOU/ReportWorkflow.ts index 1f433f296c54..f4743339cb15 100644 --- a/src/libs/actions/IOU/ReportWorkflow.ts +++ b/src/libs/actions/IOU/ReportWorkflow.ts @@ -344,7 +344,7 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { return; } - if (expenseReport.policyID && shouldRestrictUserBillableActions(expenseReport.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, expenseReportPolicy)) { + if (expenseReport.policyID && shouldRestrictUserBillableActions(expenseReportPolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(expenseReport.policyID)); return; } diff --git a/src/libs/shouldUseDefaultExpensePolicy.ts b/src/libs/shouldUseDefaultExpensePolicy.ts index 109f3ec97dea..4b775610c4cc 100644 --- a/src/libs/shouldUseDefaultExpensePolicy.ts +++ b/src/libs/shouldUseDefaultExpensePolicy.ts @@ -16,7 +16,7 @@ function shouldUseDefaultExpensePolicy( iouType === CONST.IOU.TYPE.CREATE && isPaidGroupPolicy(defaultExpensePolicy) && defaultExpensePolicy?.isPolicyExpenseChatEnabled && - !shouldRestrictUserBillableActions(defaultExpensePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, defaultExpensePolicy) + !shouldRestrictUserBillableActions(defaultExpensePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed) ); } diff --git a/src/pages/AddUnreportedExpense.tsx b/src/pages/AddUnreportedExpense.tsx index 5c95fefd1d34..34756622fb1a 100644 --- a/src/pages/AddUnreportedExpense.tsx +++ b/src/pages/AddUnreportedExpense.tsx @@ -302,7 +302,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) { { buttonText: translate('iou.createExpense'), buttonAction: () => { - if (report?.policyID && shouldRestrictUserBillableActions(report.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) { + if (report?.policyID && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(report.policyID)); return; } diff --git a/tests/unit/PaymentUtilsTest.ts b/tests/unit/PaymentUtilsTest.ts index 46f8f8e3cbde..3e33efbc744b 100644 --- a/tests/unit/PaymentUtilsTest.ts +++ b/tests/unit/PaymentUtilsTest.ts @@ -231,7 +231,7 @@ describe('PaymentUtils', () => { selectPaymentType(params); - expect(mockShouldRestrict).toHaveBeenCalledWith(testPolicyID, 999, params.userBillingGracePeriodEnds, 42, testPolicy); + expect(mockShouldRestrict).toHaveBeenCalledWith(testPolicy, 999, params.userBillingGracePeriodEnds, 42); }); it('should trigger KYC flow for EXPENSIFY payment type when user is validated', () => { @@ -331,7 +331,7 @@ describe('PaymentUtils', () => { selectPaymentType(params); - expect(mockShouldRestrict).toHaveBeenCalledWith(testPolicyID, undefined, params.userBillingGracePeriodEnds, undefined, testPolicy); + expect(mockShouldRestrict).toHaveBeenCalledWith(testPolicy, undefined, params.userBillingGracePeriodEnds, undefined); }); }); diff --git a/tests/unit/SubscriptionUtilsTest.ts b/tests/unit/SubscriptionUtilsTest.ts index a63d2a15b58b..6eed2a358f9e 100644 --- a/tests/unit/SubscriptionUtilsTest.ts +++ b/tests/unit/SubscriptionUtilsTest.ts @@ -278,7 +278,7 @@ describe('SubscriptionUtils', () => { expect( shouldRestrictUserBillableActions( - policyID, + policy, undefined, { [`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END}${ownerAccountID}`]: { @@ -287,7 +287,6 @@ describe('SubscriptionUtils', () => { }, }, undefined, - policy, ), ).toBeFalsy(); }); @@ -299,7 +298,7 @@ describe('SubscriptionUtils', () => { expect( shouldRestrictUserBillableActions( - policyID, + policy, undefined, { [`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END}${ownerAccountID}` as const]: { @@ -308,7 +307,6 @@ describe('SubscriptionUtils', () => { }, }, undefined, - policy, ), ).toBeFalsy(); }); @@ -320,7 +318,7 @@ describe('SubscriptionUtils', () => { expect( shouldRestrictUserBillableActions( - policyID, + policy, undefined, { [`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END}${ownerAccountID}` as const]: { @@ -329,7 +327,6 @@ describe('SubscriptionUtils', () => { }, }, undefined, - policy, ), ).toBeTruthy(); }); @@ -343,7 +340,7 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.SESSION]: {email: '', accountID}, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(addDays(new Date(), 3)), undefined, undefined, policy)).toBeFalsy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(addDays(new Date(), 3)), undefined, undefined)).toBeFalsy(); }); it("should return false if the user is the workspace's owner that is past due billing but isn't owning any amount", async () => { @@ -356,7 +353,7 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 0, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 0, policy)).toBeFalsy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(subDays(new Date(), 3)), undefined, 0)).toBeFalsy(); }); it("should return true if the user is the workspace's owner that is past due billing and is owning some amount", async () => { @@ -369,7 +366,7 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, policy)).toBeTruthy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(subDays(new Date(), 3)), undefined, 8010)).toBeTruthy(); }); it("should return false if the user is past due billing but is not the workspace's owner", async () => { @@ -382,7 +379,7 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, policy)).toBeFalsy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(subDays(new Date(), 3)), undefined, 8010)).toBeFalsy(); }); it('should restrict when ownerBillingGracePeriodEnd is passed directly as 3rd param and is past due', async () => { @@ -395,7 +392,7 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, policy)).toBeTruthy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(subDays(new Date(), 3)), undefined, 8010)).toBeTruthy(); }); it("should return false if the user is past due billing but is not the workspace's owner (2nd check)", async () => { @@ -408,7 +405,7 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, policy)).toBeFalsy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(subDays(new Date(), 3)), undefined, 8010)).toBeFalsy(); }); it('should restrict when ownerBillingGracePeriodEnd is passed directly as 4th param and is past due', async () => { @@ -421,7 +418,7 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, policy)).toBeTruthy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(subDays(new Date(), 3)), undefined, 8010)).toBeTruthy(); }); it('should not restrict when ownerBillingGracePeriodEnd is passed directly as 4th param but is not past due', async () => { @@ -434,7 +431,7 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(addDays(new Date(), 3)), undefined, 8010, policy)).toBeFalsy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(addDays(new Date(), 3)), undefined, 8010)).toBeFalsy(); }); it('should not restrict when ownerBillingGracePeriodEnd is passed directly as 4th param but amount owed is 0', async () => { @@ -447,7 +444,7 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 0, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 0, policy)).toBeFalsy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(subDays(new Date(), 3)), undefined, 0)).toBeFalsy(); }); it('should restrict when amountOwed is passed directly and is greater than 0', async () => { @@ -459,7 +456,7 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.SESSION]: {email: '', accountID}, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 500, policy)).toBeTruthy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(subDays(new Date(), 3)), undefined, 500)).toBeTruthy(); }); it('should not restrict when amountOwed is passed directly as 0', async () => { @@ -471,7 +468,7 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.SESSION]: {email: '', accountID}, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 0, policy)).toBeFalsy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(subDays(new Date(), 3)), undefined, 0)).toBeFalsy(); }); it('should not restrict when amountOwed is passed directly as undefined', async () => { @@ -483,7 +480,7 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.SESSION]: {email: '', accountID}, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, undefined, policy)).toBeFalsy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(subDays(new Date(), 3)), undefined, undefined)).toBeFalsy(); }); }); @@ -511,7 +508,7 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, policy)).toBeTruthy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(subDays(new Date(), 3)), undefined, 8010)).toBeTruthy(); }); it('should not restrict when policy is passed directly but owner is not past due', async () => { @@ -527,11 +524,11 @@ describe('SubscriptionUtils', () => { [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(addDays(new Date(), 3)), undefined, 8010, policy)).toBeFalsy(); + expect(shouldRestrictUserBillableActions(policy, getUnixTime(addDays(new Date(), 3)), undefined, 8010)).toBeFalsy(); }); it('should not restrict when policy is passed as undefined', () => { - expect(shouldRestrictUserBillableActions('nonexistent', getUnixTime(subDays(new Date(), 3)), undefined, 500, undefined)).toBeFalsy(); + expect(shouldRestrictUserBillableActions(undefined, getUnixTime(subDays(new Date(), 3)), undefined, 500)).toBeFalsy(); }); it('should restrict for non-owner when policy is passed directly and billing grace period is overdue', async () => { @@ -544,7 +541,7 @@ describe('SubscriptionUtils', () => { expect( shouldRestrictUserBillableActions( - policyID, + policy, undefined, { [`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END}${ownerAccountID}` as const]: { @@ -553,7 +550,6 @@ describe('SubscriptionUtils', () => { }, }, undefined, - policy, ), ).toBeTruthy(); }); @@ -568,7 +564,7 @@ describe('SubscriptionUtils', () => { expect( shouldRestrictUserBillableActions( - policyID, + policy, undefined, { [`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END}${ownerAccountID}` as const]: { @@ -577,7 +573,6 @@ describe('SubscriptionUtils', () => { }, }, undefined, - policy, ), ).toBeFalsy(); }); @@ -599,7 +594,7 @@ describe('SubscriptionUtils', () => { }, }); - expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, differentOwnerPolicy)).toBeFalsy(); + expect(shouldRestrictUserBillableActions(differentOwnerPolicy, getUnixTime(subDays(new Date(), 3)), undefined, 8010)).toBeFalsy(); }); });