Skip to content

Skip reimbursable step in duplicate resolver for managed card transactions - #94789

Closed
abzokhattab wants to merge 2 commits into
Expensify:mainfrom
abzokhattab:claude-duplicateReimbursableManagedCard
Closed

Skip reimbursable step in duplicate resolver for managed card transactions#94789
abzokhattab wants to merge 2 commits into
Expensify:mainfrom
abzokhattab:claude-duplicateReimbursableManagedCard

Conversation

@abzokhattab

Copy link
Copy Markdown
Contributor

Explanation of Change

The duplicate resolver decides which review steps to show and what values to merge from compareDuplicateTransactionFields in src/libs/TransactionUtils/index.ts. reimbursable was treated as a generic comparable field: when a manually-added cash expense (reimbursable: true) was a duplicate of a managed company-card transaction (reimbursable: false), the values differed, so reimbursable was added to the change map — surfacing the "Choose if transaction is reimbursable" step. The user could pick reimbursable, and the merge persisted reimbursable: true onto a managed card transaction, an invalid state with no in-product way to correct it.

This change adds a dedicated reimbursable branch in the field-comparison loop that gates on the selected transaction (the one the user chose to keep), not on any transaction in the duplicate set:

  • If the selected transaction is a managed card (isManagedCardTransaction(selectedTransaction)), reimbursable is forced into keep as false and never added to change. Because every Review* page derives its step list from Object.keys(change), dropping reimbursable from change removes the step, and seeding keep.reimbursable = false flows through setReviewDuplicatesKey so buildMergeDuplicatesParams merges the transaction as non-reimbursable.
  • If the selected transaction is the cash expense (the managed card duplicate is being discarded), the cash expense's reimbursable value is left intact and the field is handled by the normal equal/differ logic. Silently overriding a valid reimbursable cash expense was the concern raised during review of the original approach (transactions.some(isManagedCardTransaction)).
  • When no managed card is involved at all, the existing equal/differ behavior is fully preserved.

isManagedCardTransaction (!!transaction?.managedCard) is used deliberately rather than a broader card-import check, so personal/CSV card imports that can legitimately be reimbursable are unaffected — only centrally managed cards are constrained to non-reimbursable.

Supersedes #94777.

Fixed Issues

$ #94679
PROPOSAL: #94679 (comment)

Tests

  1. Create a workspace and connect a company card feed; import some transactions.
  2. Add a cash expense matching one of the imported managed card transactions so they are flagged as duplicates.
  3. Open one of the duplicates and tap Review duplicates.
  4. Select the managed card transaction to keep and proceed.
  5. Verify the "Choose if transaction is reimbursable" step is not shown.
  6. Complete the merge and verify the resulting transaction is non-reimbursable.
  7. Repeat steps 3–4 but this time select the cash expense to keep.
  8. Verify the "Choose if transaction is reimbursable" step is shown and the cash expense retains its reimbursable value after merging.
  9. Regression: resolve duplicates between two cash expenses with differing reimbursable values and verify the reimbursable step is still shown.
  10. Verify that no errors appear in the JS console.

Automated coverage added in tests/unit/TransactionUtilsTest.ts (compareDuplicateTransactionFieldsreimbursable field comparison):

  • Keeping the managed card duplicate → keep.reimbursable === false, no change.reimbursable.

  • Keeping the cash duplicate → reimbursable step shown with both values, cash value preserved.

  • Existing cash-vs-cash behavior unchanged.

  • Verify that no errors appear in the JS console

Offline tests

Same as tests.

QA Steps

  1. Create a workspace and connect a company card feed; import some transactions.
  2. Add a cash expense matching one of the imported managed card transactions so they are flagged as duplicates.
  3. Open the duplicate warning and tap Review duplicates.
  4. Select the managed card transaction to keep — verify the "Choose if transaction is reimbursable" step is not shown and the merged result is non-reimbursable.
  5. Repeat, this time selecting the cash expense to keep — verify the reimbursable step is shown and the merged result respects the chosen value.
  6. Regression: verify the reimbursable step still appears when resolving duplicates between two non-managed-card (cash) expenses with differing reimbursable values.
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

MelvinBot and others added 2 commits June 27, 2026 18:43
…tions

Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
Only force reimbursable=false when the transaction being kept is itself
a managed card transaction. Previously, the check fired if any duplicate
in the set was a managed card — silently setting a valid cash expense to
non-reimbursable when the user chose to keep the cash duplicate instead.
@abzokhattab
abzokhattab requested review from a team as code owners June 28, 2026 17:03
@melvin-bot
melvin-bot Bot requested review from JmillsExpensify and QichenZhu and removed request for a team and QichenZhu June 28, 2026 17:03
@melvin-bot

melvin-bot Bot commented Jun 28, 2026

Copy link
Copy Markdown

@QichenZhu Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

// Managed card transactions are always non-reimbursable. Only suppress the reimbursable
// review step and force false when the transaction being kept is itself a managed card —
// if the user keeps the cash duplicate, the managed card is discarded and the cash
// transaction's reimbursable value should be left intact.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-3 (docs)

This transactions.find((t) => t?.transactionID === selectedTransactionID) lookup duplicates the identical lookup already performed earlier in the same function (where keep.comment is set for the selected transaction). The same selection logic now lives in two places, so a future change to how the selected transaction is resolved must be made twice.

Hoist the lookup once near the top of the function and reuse the result in both branches:

// Computed once, after `transactions` is built
const selectedTransaction = selectedTransactionID ? transactions.find((t) => t?.transactionID === selectedTransactionID) : undefined;

if (selectedTransactionID) {
    keep.comment = selectedTransaction?.comment ?? {};
}

// ...inside the loop:
} else if (fieldName === 'reimbursable') {
    if (isManagedCardTransaction(selectedTransaction ?? firstTransaction)) {
        keep[fieldName] = false;
    } else if (areAllFieldsEqualForKey) {
        keep[fieldName] = firstTransaction?.[keys[0]] ?? firstTransaction?.[keys[1]];
    } else {
        processChanges(fieldName, transactions, keys);
    }
}

Reviewed at: c8f8adc | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants