Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 4 additions & 6 deletions src/libs/ReportSecondaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {getIOUActionForReportID, getIOUActionForTransactionID, getOneTransaction
import {getReportPrimaryAction, isPrimaryPayAction} from './ReportPrimaryActionUtils';
import {
canAddTransaction,
canDeleteCardTransactionByLiabilityType,
canEditReportPolicy,
canHoldUnholdReportAction,
canRejectReportAction,
Expand Down Expand Up @@ -54,7 +55,6 @@ import {
allHavePendingRTERViolation,
getOriginalTransactionWithSplitInfo,
hasReceipt as hasReceiptTransactionUtils,
isCardTransaction as isCardTransactionUtils,
isDemoTransaction,
isDuplicate,
isOnHold as isOnHoldTransactionUtils,
Expand Down Expand Up @@ -458,8 +458,9 @@ function isDeleteAction(report: Report, reportTransactions: Transaction[], repor
return true;
}

const canCardTransactionBeDeleted = canDeleteCardTransactionByLiabilityType(transaction);
if (isUnreported) {
return isOwner;
return isOwner && canCardTransactionBeDeleted;
}

if (isInvoiceReport) {
Expand All @@ -473,10 +474,7 @@ function isDeleteAction(report: Report, reportTransactions: Transaction[], repor
}

if (isExpenseReport) {
const isCardTransactionWithCorporateLiability =
isSingleTransaction && isCardTransactionUtils(transaction) && transaction?.comment?.liabilityType === CONST.TRANSACTION.LIABILITY_TYPE.RESTRICT;

if (isCardTransactionWithCorporateLiability) {
if (!canCardTransactionBeDeleted) {
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2616,6 +2616,9 @@ function canDeleteReportAction(reportAction: OnyxInputOrEntry<ReportAction>, rep
if (!isEmptyObject(report) && (isMoneyRequestReport(report) || isInvoiceReport(report))) {
return canDeleteTransaction(report) && isCardTransactionCanBeDeleted;
}
if (isTrackExpenseAction(reportAction)) {
return isCardTransactionCanBeDeleted;
}
return true;
}
}
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/ReportSecondaryActionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,48 @@ describe('getSecondaryAction', () => {
expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.DELETE)).toBe(false);
});

it('does not include DELETE option for unreported card expense imported with deleting disabled', async () => {
// Given the unreported card expense imported with deleting disabled
const report = {
reportID: REPORT_ID,
type: CONST.REPORT.TYPE.CHAT,
chatType: CONST.REPORT.CHAT_TYPE.SELF_DM,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
ownerAccountID: EMPLOYEE_ACCOUNT_ID,
} as unknown as Report;

const TRANSACTION_ID = 'TRANSACTION_ID';

const transaction = {
transactionID: TRANSACTION_ID,
reportID: CONST.REPORT.UNREPORTED_REPORT_ID,
managedCard: true,
comment: {
liabilityType: CONST.TRANSACTION.LIABILITY_TYPE.RESTRICT,
},
} as unknown as Transaction;

const reportActions = [
{
reportActionID: '1',
actorAccountID: EMPLOYEE_ACCOUNT_ID,
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
originalMessage: {
IOUTransactionID: TRANSACTION_ID,
IOUReportID: CONST.REPORT.UNREPORTED_REPORT_ID,
},
},
] as unknown as ReportAction[];

const policy = {} as unknown as Policy;
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);

// Then it should return false since the unreported card expense is imported with deleting disabled
const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction], violations: {}, policy, reportActions});
expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.DELETE)).toBe(false);
});

it('does not include DELETE option for report that has been forwarded', async () => {
const report = {
reportID: REPORT_ID,
Expand Down
46 changes: 46 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3225,6 +3225,52 @@ describe('ReportUtils', () => {
expect(canDeleteReportAction(moneyRequestAction, '1', transaction)).toBe(true);
});

it('should return false for unreported card expense imported with deleting disabled', async () => {
// Given the unreported card expense import with deleting disabled
const selfDMReport = {
...LHNTestUtils.getFakeReport(),
type: CONST.REPORT.TYPE.CHAT,
chatType: CONST.REPORT.CHAT_TYPE.SELF_DM,
};

const transaction: Transaction = {
...createRandomTransaction(1),
reportID: CONST.REPORT.UNREPORTED_REPORT_ID,
managedCard: true,
comment: {
liabilityType: CONST.TRANSACTION.LIABILITY_TYPE.RESTRICT,
},
};

const trackExpenseAction: ReportAction = {
...LHNTestUtils.getFakeReportAction(),
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
actorAccountID: currentUserAccountID,
originalMessage: {
IOUTransactionID: transaction.transactionID,
IOUReportID: CONST.REPORT.UNREPORTED_REPORT_ID,
amount: 100,
currency: CONST.CURRENCY.USD,
type: CONST.IOU.REPORT_ACTION_TYPE.TRACK,
},
message: [
{
type: 'COMMENT',
html: '$1.00 expense',
text: '$1.00 expense',
isEdited: false,
whisperedTo: [],
isDeletedParentAction: false,
},
],
};

await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`, selfDMReport);

// Then it should return false since the unreported card expense is imported with deleting disabled
expect(canDeleteReportAction(trackExpenseAction, selfDMReport.reportID, transaction)).toBe(false);
});

it("should return false for ADD_COMMENT report action the current user (admin of the personal policy) didn't comment", async () => {
const adminPolicy = {...LHNTestUtils.getFakePolicy(), type: CONST.POLICY.TYPE.PERSONAL};

Expand Down