Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ function getForReportAction({

const hasModifiedAttendees = isReportActionOriginalMessageAnObject && 'oldAttendees' in reportActionOriginalMessage && 'newAttendees' in reportActionOriginalMessage;
if (hasModifiedAttendees) {
const [oldAttendees, attendees] = getFormattedAttendees(reportActionOriginalMessage.newAttendees, reportActionOriginalMessage.oldAttendees);
buildMessageFragmentForValue(translate, oldAttendees, attendees, translate('iou.attendees'), false, setFragments, removalFragments, changeFragments);
const [oldAttendees, newAttendees] = getFormattedAttendees(reportActionOriginalMessage.oldAttendees, reportActionOriginalMessage.newAttendees);
buildMessageFragmentForValue(translate, newAttendees, oldAttendees, translate('iou.attendees'), false, setFragments, removalFragments, changeFragments);
Comment on lines +454 to +455
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Make attendee message logic actually change behavior

This edit is behaviorally neutral: getFormattedAttendees() returns values in the same order as its arguments, and this patch swaps both the arguments and the tuple positions passed into buildMessageFragmentForValue(), so the final call still evaluates to newAttendees as new value and oldAttendees as old value just like before. In attendee-modification flows, the rendered system message will therefore be unchanged, so the intended copy fix is not actually applied.

Useful? React with 👍 / 👎.

}

const hasPersonalRulesModifiedFields = isReportActionOriginalMessageAnObject && 'personalRulesModifiedFields' in reportActionOriginalMessage;
Expand Down
65 changes: 65 additions & 0 deletions tests/unit/ModifiedExpenseMessageTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1395,5 +1395,70 @@ describe('ModifiedExpenseMessage', () => {
expect(result).toEqual(expectedResult);
});
});

describe('when attendees are changed', () => {
it('returns the correct message with old and new attendees in the right order', () => {
const reportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE,
originalMessage: {
oldAttendees: [{email: 'alice@example.com', displayName: 'Alice', avatarUrl: ''}],
newAttendees: [
{email: 'alice@example.com', displayName: 'Alice', avatarUrl: ''},
{email: 'bob@example.com', displayName: 'Bob', avatarUrl: ''},
],
},
};

const result = getForReportAction({
translate: translateLocal,
reportAction,
policyTags: undefined,
currentUserLogin: 'test@example.com',
});

expect(result).toEqual('changed the attendees to Alice, Bob (previously Alice)');
});

it('returns "set" message when attendees are added from empty', () => {
const reportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE,
originalMessage: {
oldAttendees: [],
newAttendees: [{email: 'alice@example.com', displayName: 'Alice', avatarUrl: ''}],
},
};

const result = getForReportAction({
translate: translateLocal,
reportAction,
policyTags: undefined,
currentUserLogin: 'test@example.com',
});

expect(result).toEqual('set the attendees to Alice');
});

it('returns "removed" message when attendees are cleared', () => {
const reportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE,
originalMessage: {
oldAttendees: [{email: 'alice@example.com', displayName: 'Alice', avatarUrl: ''}],
newAttendees: [],
},
};

const result = getForReportAction({
translate: translateLocal,
reportAction,
policyTags: undefined,
currentUserLogin: 'test@example.com',
});

expect(result).toEqual('removed the attendees (previously Alice)');
});
});
});
});
Loading