diff --git a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts index ce246616b18dc..bf7814acc76fe 100644 --- a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts +++ b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts @@ -1,18 +1,19 @@ -import {isThread} from '@libs/ReportUtils'; +import {isArchivedReportWithID, isThread} from '@libs/ReportUtils'; import createOnyxDerivedValueConfig from '@userActions/OnyxDerived/createOnyxDerivedValueConfig'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; export default createOnyxDerivedValueConfig({ key: ONYXKEYS.DERIVED.CONCIERGE_CHAT_REPORT_ID, - dependencies: [ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.CONCIERGE_REPORT_ID], - compute: ([reports, conciergeChatReportID]) => { - if (!reports) { + dependencies: [ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.CONCIERGE_REPORT_ID, ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS], + compute: ([reports, conciergeChatReportID, allReportNameValuePair]) => { + if (!reports || !allReportNameValuePair) { return undefined; } const conciergeReport = Object.values(reports).find((report) => { - if (!report?.participants || isThread(report)) { + // Merged accounts can have multiple conceirge chats, exclude archived chats. + if (!report?.participants || isThread(report) || isArchivedReportWithID(report?.reportID)) { return false; } diff --git a/src/libs/actions/OnyxDerived/index.ts b/src/libs/actions/OnyxDerived/index.ts index 99b34b095eafc..c0321d46b29f8 100644 --- a/src/libs/actions/OnyxDerived/index.ts +++ b/src/libs/actions/OnyxDerived/index.ts @@ -54,7 +54,7 @@ function init() { waitForCollectionCallback: true, callback: (value) => { Log.info(`[OnyxDerived] dependency ${dependencyOnyxKey} for derived key ${key} changed, recomputing`); - setDependencyValue(i, value); + setDependencyValue(i, value as Parameters[0][typeof i]); recomputeDerivedValue(); }, }); @@ -63,7 +63,7 @@ function init() { key: dependencyOnyxKey, callback: (value) => { Log.info(`[OnyxDerived] dependency ${dependencyOnyxKey} for derived key ${key} changed, recomputing`); - setDependencyValue(i, value); + setDependencyValue(i, value as Parameters[0][typeof i]); recomputeDerivedValue(); }, }); diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index a0c982f3fbfb7..6af7a1f019b36 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -5,8 +5,10 @@ import {toZonedTime} from 'date-fns-tz'; import type {Mock} from 'jest-mock'; import Onyx from 'react-native-onyx'; import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; +import OnyxUtils from 'react-native-onyx/dist/OnyxUtils'; import {WRITE_COMMANDS} from '@libs/API/types'; import HttpUtils from '@libs/HttpUtils'; +import initOnyxDerivedValues from '@userActions/OnyxDerived'; import CONST from '@src/CONST'; import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager'; import * as PersistedRequests from '@src/libs/actions/PersistedRequests'; @@ -21,6 +23,7 @@ import type * as OnyxTypes from '@src/types/onyx'; import createRandomReportAction from '../utils/collections/reportActions'; import createRandomReport from '../utils/collections/reports'; import getIsUsingFakeTimers from '../utils/getIsUsingFakeTimers'; +import * as LHNTestUtils from '../utils/LHNTestUtils'; import PusherHelper from '../utils/PusherHelper'; import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -1518,4 +1521,32 @@ describe('actions/Report', () => { }); }); }); + describe('isConciergeChatReport', () => { + const accountID = 2; + const conciergeChatReport1 = LHNTestUtils.getFakeReport([accountID, CONST.ACCOUNT_ID.CONCIERGE]); + const conciergeChatReport2 = LHNTestUtils.getFakeReport([accountID, CONST.ACCOUNT_ID.CONCIERGE]); + + beforeAll(async () => { + Onyx.init({keys: ONYXKEYS}); + await waitForBatchedUpdates(); + }); + + beforeEach(async () => { + await Onyx.clear(); + await waitForBatchedUpdates(); + }); + + it('should not return archived Concierge chat report', async () => { + initOnyxDerivedValues(); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${conciergeChatReport1.reportID}`, conciergeChatReport1); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${conciergeChatReport2.reportID}`, conciergeChatReport2); + + // Set First conciergeChatReport1 to archived state + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${conciergeChatReport1.reportID}`, { + private_isArchived: new Date().toString(), + }); + const derivedConciergeChatReportID = await OnyxUtils.get(ONYXKEYS.DERIVED.CONCIERGE_CHAT_REPORT_ID); + expect(derivedConciergeChatReportID).toBe(conciergeChatReport2.reportID); + }); + }); }); diff --git a/tests/unit/navigateAfterOnboardingTest.ts b/tests/unit/navigateAfterOnboardingTest.ts index 47d5c7d4febc0..85cafb6fc535c 100644 --- a/tests/unit/navigateAfterOnboardingTest.ts +++ b/tests/unit/navigateAfterOnboardingTest.ts @@ -32,6 +32,7 @@ jest.mock('@libs/ReportUtils', () => ({ findLastAccessedReport: () => mockFindLastAccessedReport() as OnyxEntry, parseReportRouteParams: jest.fn(() => ({})), isConciergeChatReport: jest.requireActual('@libs/ReportUtils').isConciergeChatReport, + isArchivedReportWithID: jest.requireActual('@libs/ReportUtils').isArchivedReportWithID, isThread: jest.requireActual('@libs/ReportUtils').isThread, }));