Skip to content

Commit 6e2eba0

Browse files
authored
Merge pull request Expensify#81085 from Expensify/beaman-addBetaForFollowups
Add beta for followups
2 parents f745547 + 5d1c818 commit 6e2eba0

4 files changed

Lines changed: 38 additions & 3 deletions

File tree

src/CONST/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ const CONST = {
745745
NEW_DOT_DEW: 'newDotDEW',
746746
GPS_MILEAGE: 'gpsMileage',
747747
PERSONAL_CARD_IMPORT: 'personalCardImport',
748+
SUGGESTED_FOLLOWUPS: 'suggestedFollowups',
748749
},
749750
BUTTON_STATES: {
750751
DEFAULT: 'default',

src/libs/ReportUtils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import SCREENS from '@src/SCREENS';
3737
import type {
3838
BankAccountList,
3939
Beta,
40+
BetaConfiguration,
4041
IntroSelected,
4142
OnyxInputOrEntry,
4243
OutstandingReportsByPolicyIDDerivedValue,
@@ -1115,6 +1116,12 @@ Onyx.connectWithoutView({
11151116
callback: (value) => (allBetas = value),
11161117
});
11171118

1119+
let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
1120+
Onyx.connectWithoutView({
1121+
key: ONYXKEYS.BETA_CONFIGURATION,
1122+
callback: (value) => (betaConfiguration = value ?? {}),
1123+
});
1124+
11181125
let allTransactions: OnyxCollection<Transaction> = {};
11191126
let reportsTransactions: Record<string, Transaction[]> = {};
11201127
Onyx.connectWithoutView({
@@ -11580,8 +11587,8 @@ function prepareOnboardingOnyxData({
1158011587

1158111588
// Guides are assigned and tasks are posted in the #admins room for the MANAGE_TEAM and TRACK_WORKSPACE onboarding actions, except for emails that have a '+'.
1158211589
const shouldPostTasksInAdminsRoom = isPostingTasksInAdminsRoom(engagementChoice);
11583-
// When posting to admins room in non-production environments, we skip tasks in favor of backend-generated followups.
11584-
const shouldUseFollowupsInsteadOfTasks = shouldPostTasksInAdminsRoom && environment !== CONST.ENVIRONMENT.PRODUCTION;
11590+
// When posting to admins room and the user is in the suggestedFollowups beta, we skip tasks in favor of backend-generated followups.
11591+
const shouldUseFollowupsInsteadOfTasks = shouldPostTasksInAdminsRoom && Permissions.isBetaEnabled(CONST.BETAS.SUGGESTED_FOLLOWUPS, allBetas, betaConfiguration);
1158511592
const adminsChatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${adminsChatReportID}`];
1158611593
const targetChatReport = shouldPostTasksInAdminsRoom
1158711594
? (adminsChatReport ?? {reportID: adminsChatReportID, policyID: onboardingPolicyID})

tests/actions/PolicyTest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ describe('actions/Policy', () => {
6363
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
6464
await Onyx.set(`${ONYXKEYS.NVP_ACTIVE_POLICY_ID}`, fakePolicy.id);
6565
await Onyx.set(`${ONYXKEYS.NVP_INTRO_SELECTED}`, {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM});
66+
// Enable the suggestedFollowups beta so tasks are skipped in favor of backend-generated followups
67+
await Onyx.set(ONYXKEYS.BETAS, [CONST.BETAS.SUGGESTED_FOLLOWUPS]);
6668
await waitForBatchedUpdates();
6769

6870
let adminReportID;

tests/unit/ReportUtilsTest.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,12 @@ describe('ReportUtils', () => {
524524
);
525525
});
526526

527-
it('should not add anything to guidedSetupData when posting into the admin room', async () => {
527+
it('should not add anything to guidedSetupData when posting into the admin room with suggestedFollowups beta', async () => {
528528
const adminsChatReportID = '1';
529529
// Not having `+` in the email allows for `isPostingTasksInAdminsRoom` flow
530530
await Onyx.merge(ONYXKEYS.SESSION, {email: 'test@example.com'});
531+
// Enable the suggestedFollowups beta so tasks are skipped in favor of backend-generated followups
532+
await Onyx.merge(ONYXKEYS.BETAS, [CONST.BETAS.SUGGESTED_FOLLOWUPS]);
531533
await waitForBatchedUpdates();
532534

533535
const result = prepareOnboardingOnyxData({
@@ -545,6 +547,29 @@ describe('ReportUtils', () => {
545547
expect(result?.optimisticData.filter((i) => i.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminsChatReportID}`)).toHaveLength(0);
546548
});
547549

550+
it('should add guidedSetupData when posting into admin room WITHOUT suggestedFollowups beta', async () => {
551+
const adminsChatReportID = '1';
552+
// Not having `+` in the email allows for `isPostingTasksInAdminsRoom` flow
553+
await Onyx.merge(ONYXKEYS.SESSION, {email: 'test@example.com'});
554+
// Do NOT set the suggestedFollowups beta - user should get the old task list behavior
555+
await Onyx.merge(ONYXKEYS.BETAS, []);
556+
await waitForBatchedUpdates();
557+
558+
const result = prepareOnboardingOnyxData({
559+
introSelected: undefined,
560+
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
561+
onboardingMessage: {
562+
message: 'This is a test',
563+
tasks: [{type: CONST.ONBOARDING_TASK_TYPE.CONNECT_CORPORATE_CARD, title: () => '', description: () => '', autoCompleted: false, mediaAttributes: {}}],
564+
},
565+
adminsChatReportID,
566+
selectedInterestedFeatures: ['areCompanyCardsEnabled'],
567+
companySize: CONST.ONBOARDING_COMPANY_SIZE.MICRO,
568+
});
569+
// Without the beta, tasks SHOULD be generated (old behavior)
570+
expect(result?.guidedSetupData).toHaveLength(3);
571+
});
572+
548573
it('should add guidedSetupData when email has a +', async () => {
549574
const adminsChatReportID = '1';
550575
await waitForBatchedUpdates();

0 commit comments

Comments
 (0)