Skip to content
11 changes: 6 additions & 5 deletions src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/OnyxDerived/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof compute>[0][typeof i]);
recomputeDerivedValue();
},
});
Expand All @@ -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<typeof compute>[0][typeof i]);
recomputeDerivedValue();
},
});
Expand Down
31 changes: 31 additions & 0 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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);
});
});
});
1 change: 1 addition & 0 deletions tests/unit/navigateAfterOnboardingTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jest.mock('@libs/ReportUtils', () => ({
findLastAccessedReport: () => mockFindLastAccessedReport() as OnyxEntry<Report>,
parseReportRouteParams: jest.fn(() => ({})),
isConciergeChatReport: jest.requireActual<typeof ReportUtils>('@libs/ReportUtils').isConciergeChatReport,
isArchivedReportWithID: jest.requireActual<typeof ReportUtils>('@libs/ReportUtils').isArchivedReportWithID,
isThread: jest.requireActual<typeof ReportUtils>('@libs/ReportUtils').isThread,
}));

Expand Down