Skip to content

Commit

Permalink
Merge pull request #45723 from Expensify/chirag-new-report-param-check
Browse files Browse the repository at this point in the history
New report param hasReceivedFreeTrialEndMessage check
  • Loading branch information
puneetlath authored Jul 19, 2024
2 parents b4f5d80 + 6c9d20a commit f52b7fe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 50 deletions.
5 changes: 0 additions & 5 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ import type {LastVisibleMessage} from './ReportActionsUtils';
import * as ReportActionsUtils from './ReportActionsUtils';
import * as ReportConnection from './ReportConnection';
import StringUtils from './StringUtils';
import * as SubscriptionUtils from './SubscriptionUtils';
import * as TransactionUtils from './TransactionUtils';
import * as Url from './Url';
import type {AvatarSource} from './UserUtils';
Expand Down Expand Up @@ -2381,10 +2380,6 @@ function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry<Report> | Op
return true;
}

if (isChatUsedForOnboarding(optionOrReport) && SubscriptionUtils.hasUserFreeTrialEnded() && !SubscriptionUtils.doesUserHavePaymentCardAdded()) {
return true;
}

return false;
}

Expand Down
48 changes: 3 additions & 45 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {addDays, format as formatDate, subDays} from 'date-fns';
import {addDays, format as formatDate} from 'date-fns';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import DateUtils from '@libs/DateUtils';
Expand Down Expand Up @@ -321,7 +321,7 @@ describe('ReportUtils', () => {
expect(ReportUtils.requiresAttentionFromCurrentUser(report)).toBe(false);
});

it('returns false when the report has no oustanding IOU but is waiting for a bank account and the logged user is not the report owner', () => {
it('returns false when the report has no outstanding IOU but is waiting for a bank account and the logged user is not the report owner', () => {
const report = {
...LHNTestUtils.getFakeReport(),
ownerAccountID: 97,
Expand Down Expand Up @@ -350,7 +350,7 @@ describe('ReportUtils', () => {
expect(ReportUtils.requiresAttentionFromCurrentUser(report)).toBe(true);
});

it('returns true when the report has oustanding child expense', () => {
it('returns true when the report has outstanding child expense', () => {
const report = {
...LHNTestUtils.getFakeReport(),
ownerAccountID: 99,
Expand Down Expand Up @@ -387,48 +387,6 @@ describe('ReportUtils', () => {

expect(ReportUtils.requiresAttentionFromCurrentUser(report)).toBe(false);
});

it('returns false if the user free trial has ended and it added a payment card', async () => {
await Onyx.multiSet({
[ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL]: formatDate(addDays(new Date(), 1), CONST.DATE.FNS_DATE_TIME_FORMAT_STRING), // trial not ended
[ONYXKEYS.NVP_BILLING_FUND_ID]: 8010, // payment card added
});

const report: Report = {
...LHNTestUtils.getFakeReport(),
chatType: CONST.REPORT.CHAT_TYPE.SYSTEM,
};

expect(ReportUtils.requiresAttentionFromCurrentUser(report)).toBe(false);
});

it("returns true if the report is the system chat, the user free trial has ended and it didn't add a payment card yet", async () => {
await Onyx.multiSet({
[ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL]: formatDate(subDays(new Date(), 1), CONST.DATE.FNS_DATE_TIME_FORMAT_STRING), // trial ended
[ONYXKEYS.NVP_BILLING_FUND_ID]: null, // no payment card added
});

const report: Report = {
...LHNTestUtils.getFakeReport(),
chatType: CONST.REPORT.CHAT_TYPE.SYSTEM,
};

expect(ReportUtils.requiresAttentionFromCurrentUser(report)).toBe(true);
});

it("returns true if the report is the concierge chat, the user free trial has ended and it didn't add a payment card yet", async () => {
await Onyx.multiSet({
[ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL]: formatDate(subDays(new Date(), 1), CONST.DATE.FNS_DATE_TIME_FORMAT_STRING), // trial ended
[ONYXKEYS.NVP_BILLING_FUND_ID]: null, // no payment card added
[ONYXKEYS.SESSION]: {email: currentUserEmail, accountID: 8}, // even account id
});

const report: Report = {
...LHNTestUtils.getFakeReport([CONST.ACCOUNT_ID.CONCIERGE]),
};

expect(ReportUtils.requiresAttentionFromCurrentUser(report)).toBe(true);
});
});

describe('getMoneyRequestOptions', () => {
Expand Down

0 comments on commit f52b7fe

Please sign in to comment.