Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions tests/unit/SidebarUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,99 @@ describe('SidebarUtils', () => {

expect(result).toBeNull();
});

it('returns correct reason when copilot with full access approves report but deposit and withdrawal accounts are the same', async () => {
await Onyx.clear();

// Given: Copilot is set up with full access
const copilotEmail = 'copilot@example.com';
const delegatedAccess = {
delegate: copilotEmail,
delegates: [{email: copilotEmail, role: CONST.DELEGATE_ROLE.ALL}],
};

await act(async () => {
await Onyx.merge(ONYXKEYS.ACCOUNT, {delegatedAccess});
});

await waitForBatchedUpdatesWithAct();

// Given: An expense report (chat report) exists
const expenseReportID = '12345';
const chatReport: Report = {
reportID: expenseReportID,
ownerAccountID: 12345,
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
policyID: '6',
};

// Given: An APPROVED report action with the deposit/withdrawal account error
const approvedReportActionID = '999';
const errorTimestamp = DateUtils.getMicroseconds();
const approvedReportAction: ReportAction = {
reportActionID: approvedReportActionID,
actionName: CONST.REPORT.ACTIONS.TYPE.APPROVED,
actorAccountID: 12345,
created: DateUtils.getDBTime(),
message: [
{
type: '',
text: '',
},
],
errors: {
depositWithdrawalAccountError: {
[errorTimestamp]: 'The deposit and withdrawal accounts are the same.',
},
},
};

const MOCK_REPORTS: ReportCollectionDataSet = {
[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}` as const]: chatReport,
};

const MOCK_REPORT_ACTIONS: OnyxEntry<ReportActions> = {
[approvedReportActionID]: approvedReportAction,
};

const MOCK_TRANSACTIONS = {};
const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection<TransactionViolation[]> = {};

await act(async () => {
await Onyx.multiSet({
Comment thread
KioCoan marked this conversation as resolved.
Resolved
...MOCK_REPORTS,
[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}` as const]: chatReport,
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}` as const]: MOCK_REPORT_ACTIONS,
});
});

await waitForBatchedUpdatesWithAct();

// When: Checking for RBR on the chat report
const {result: isReportArchived} = renderHook(() => useReportIsArchived(chatReport?.reportID));
const reportErrors = getAllReportErrors(chatReport, MOCK_REPORT_ACTIONS);

const result = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(
chatReport,
chatReport,
MOCK_REPORT_ACTIONS,
false,
reportErrors,
MOCK_TRANSACTIONS,
MOCK_TRANSACTION_VIOLATIONS,
isReportArchived.current,
);

// Then: RBR should appear on the chat for the expense report
expect(result).not.toBeNull();
expect(result?.reason).toBe(CONST.RBR_REASONS.HAS_ERRORS);
expect(result?.reportAction).toMatchObject<ReportAction>(approvedReportAction);
expect(Object.values(reportErrors)).toContain('The deposit and withdrawal accounts are the same.');

await Onyx.clear();
});
});

describe('shouldShowRedBrickRoad', () => {
Expand Down