Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New report param hasReceivedFreeTrialEndMessage check #45723

Merged
merged 11 commits into from
Jul 19, 2024
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
Loading