Skip to content

Commit 1fdc8a7

Browse files
authored
Merge pull request #51643 from truph01/fix/50927
fix: Inbox showing GBR when there’s a report with RBR
2 parents b9e6208 + 16b9d4e commit 1fdc8a7

File tree

3 files changed

+167
-1
lines changed

3 files changed

+167
-1
lines changed

src/libs/WorkspacesSettingsUtils.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,18 @@ const getBrickRoadForPolicy = (report: Report, altReportActions?: OnyxCollection
6464
const oneTransactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(report.reportID, reportActions);
6565
let doesReportContainErrors = Object.keys(reportErrors ?? {}).length !== 0 ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined;
6666

67-
if (oneTransactionThreadReportID) {
67+
if (!doesReportContainErrors) {
68+
const parentReportActions = (altReportActions ?? allReportActions)?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`];
69+
const parentReportAction = parentReportActions?.[report?.parentReportActionID ?? '-1'];
70+
const shouldDisplayViolations = ReportUtils.shouldDisplayTransactionThreadViolations(report, allTransactionViolations, parentReportAction);
71+
const shouldDisplayReportViolations = ReportUtils.isReportOwner(report) && ReportUtils.hasReportViolations(report.reportID);
72+
const hasViolations = shouldDisplayViolations || shouldDisplayReportViolations;
73+
if (hasViolations) {
74+
doesReportContainErrors = CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR;
75+
}
76+
}
77+
78+
if (oneTransactionThreadReportID && !doesReportContainErrors) {
6879
const oneTransactionThreadReport = ReportUtils.getReport(oneTransactionThreadReportID);
6980

7081
if (
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"session": {
3+
"accountID": 18634488
4+
},
5+
"reports": {
6+
"report_4286515777714555": {
7+
"type": "chat",
8+
"isOwnPolicyExpenseChat": false,
9+
"ownerAccountID": 0,
10+
"parentReportActionID": "8722650843049927838",
11+
"parentReportID": "6955627196303088",
12+
"policyID": "57D0F454E0BCE54B",
13+
"reportID": "4286515777714555",
14+
"stateNum": 0,
15+
"statusNum": 0
16+
},
17+
"report_6955627196303088": {
18+
"reportID": "6955627196303088",
19+
"chatReportID": "1699789757771388",
20+
"policyID": "57D0F454E0BCE54B",
21+
"type": "expense",
22+
"ownerAccountID": 18634488,
23+
"stateNum": 1,
24+
"statusNum": 1,
25+
"parentReportID": "1699789757771388",
26+
"parentReportActionID": "7978085421707288417"
27+
}
28+
},
29+
"transactionViolations": {
30+
"transactionViolations_3106135972713435169": [
31+
{
32+
"name": "missingCategory",
33+
"type": "violation"
34+
}
35+
],
36+
"transactionViolations_3690687111940510713": [
37+
{
38+
"name": "missingCategory",
39+
"type": "violation"
40+
}
41+
]
42+
},
43+
"reportActions": {
44+
"reportActions_6955627196303088": {
45+
"8722650843049927838": {
46+
"actionName": "IOU",
47+
"actorAccountID": 18634488,
48+
"automatic": false,
49+
"avatar": "https: //d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_1.png",
50+
"isAttachmentOnly": false,
51+
"originalMessage": {
52+
"amount": 12300,
53+
"comment": "",
54+
"currency": "VND",
55+
"IOUTransactionID": "3106135972713435169",
56+
"IOUReportID": "6955627196303088"
57+
},
58+
"message": [
59+
{
60+
"deleted": "",
61+
"html": "₫123 expense",
62+
"isDeletedParentAction": false,
63+
"isEdited": false,
64+
"text": "₫123 expense",
65+
"type": "COMMENT",
66+
"whisperedTo": []
67+
}
68+
],
69+
"person": [
70+
{
71+
"style": "strong",
72+
"text": "adasdasd",
73+
"type": "TEXT"
74+
}
75+
],
76+
"reportActionID": "8722650843049927838",
77+
"shouldShow": true,
78+
"created": "2024-11-05 11: 19: 18.706",
79+
"childReportID": "4286515777714555",
80+
"lastModified": "2024-11-05 11: 19: 18.706",
81+
"childReportNotificationPreference": "hidden",
82+
"childType": "chat"
83+
}
84+
}
85+
}
86+
}
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import type {OnyxCollection} from 'react-native-onyx';
2+
import Onyx from 'react-native-onyx';
3+
import {getBrickRoadForPolicy} from '@libs/WorkspacesSettingsUtils';
4+
import ONYXKEYS from '@src/ONYXKEYS';
5+
import type {Report, ReportActions, TransactionViolations} from '@src/types/onyx';
6+
import type {ReportCollectionDataSet} from '@src/types/onyx/Report';
7+
import * as TestHelper from '../utils/TestHelper';
8+
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
9+
import mockData from './WorkspaceSettingsUtilsTest.json';
10+
11+
describe('WorkspacesSettingsUtils', () => {
12+
beforeAll(() => {
13+
Onyx.init({
14+
keys: ONYXKEYS,
15+
});
16+
});
17+
18+
beforeEach(() => {
19+
global.fetch = TestHelper.getGlobalFetchMock();
20+
return Onyx.clear().then(waitForBatchedUpdates);
21+
});
22+
describe('getBrickRoadForPolicy', () => {
23+
it('Should return "error"', async () => {
24+
// Given mock data for reports, transaction violations, sessions, and report actions.
25+
const report = Object.values(mockData.reports)?.at(0);
26+
const transactionViolations = mockData.transactionViolations;
27+
const reports = mockData.reports;
28+
const session = mockData.session;
29+
const reportActions = mockData.reportActions;
30+
31+
await Onyx.multiSet({
32+
...(reports as ReportCollectionDataSet),
33+
...(reportActions as OnyxCollection<ReportActions>),
34+
...(transactionViolations as OnyxCollection<TransactionViolations>),
35+
session,
36+
});
37+
38+
await waitForBatchedUpdates();
39+
40+
// When calling getBrickRoadForPolicy with a report and report actions
41+
const result = getBrickRoadForPolicy(report as Report, reportActions as OnyxCollection<ReportActions>);
42+
43+
// The result should be 'error' because there is at least one IOU action associated with a transaction that has a violation.
44+
expect(result).toBe('error');
45+
});
46+
47+
it('Should return "undefined"', async () => {
48+
// Given mock data for reports, sessions, and report actions. Note: Transaction data is intentionally excluded.
49+
const report = Object.values(mockData.reports)?.at(0);
50+
const reports = mockData.reports;
51+
const session = mockData.session;
52+
const reportActions = mockData.reportActions;
53+
54+
await Onyx.multiSet({
55+
...(reports as ReportCollectionDataSet),
56+
...(reportActions as OnyxCollection<ReportActions>),
57+
session,
58+
});
59+
60+
await waitForBatchedUpdates();
61+
62+
// When calling getBrickRoadForPolicy with a report and report actions
63+
const result = getBrickRoadForPolicy(report as Report, reportActions as OnyxCollection<ReportActions>);
64+
65+
// Then the result should be 'undefined' since no IOU action is linked to a transaction with a violation.
66+
expect(result).toBe(undefined);
67+
});
68+
});
69+
});

0 commit comments

Comments
 (0)