Skip to content

Commit

Permalink
Merge pull request Expensify#11612 from Expensify/tgolen-fix-hasoutst…
Browse files Browse the repository at this point in the history
…andingious

Fix the broken logic for if a report has an outstanding IOU
  • Loading branch information
luacmartins authored Oct 5, 2022
2 parents 62331f3 + 08cda1c commit f79df1a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,12 +865,12 @@ function isUnread(report) {
* @param {Object} report
* @param {String} report.iouReportID
* @param {String} currentUserLogin
* @param {Object[]} iouReports
* @param {String} iouReports[].ownerEmail
* @param {Object} iouReports
* @returns {boolean}
*/

function hasOutstandingIOU(report, currentUserLogin, iouReports) {
if (!report || !report.iouReportID || report.hasOutstandingIOU) {
if (!report || !report.iouReportID || _.isUndefined(report.hasOutstandingIOU)) {
return false;
}

Expand All @@ -879,7 +879,11 @@ function hasOutstandingIOU(report, currentUserLogin, iouReports) {
return false;
}

return iouReport.ownerEmail !== currentUserLogin;
if (iouReport.ownerEmail === currentUserEmail) {
return false;
}

return report.hasOutstandingIOU;
}

/**
Expand Down Expand Up @@ -979,6 +983,7 @@ export {
isConciergeChatReport,
hasExpensifyEmails,
hasExpensifyGuidesEmails,
hasOutstandingIOU,
canShowReportRecipientLocalTime,
formatReportLastMessageText,
chatIncludesConcierge,
Expand Down
79 changes: 79 additions & 0 deletions tests/unit/ReportUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CONST from '../../src/CONST';
import ONYXKEYS from '../../src/ONYXKEYS';
import * as ReportUtils from '../../src/libs/ReportUtils';
import waitForPromisesToResolve from '../utils/waitForPromisesToResolve';
import * as LHNTestUtils from '../utils/LHNTestUtils';

const currentUserEmail = '[email protected]';
const participantsPersonalDetails = {
Expand Down Expand Up @@ -223,4 +224,82 @@ describe('ReportUtils', () => {
});
});
});

describe('hasOutstandingIOU', () => {
it('returns false when there is no report', () => {
expect(ReportUtils.hasOutstandingIOU()).toBe(false);
});
it('returns false when the report has no iouReportID', () => {
const report = LHNTestUtils.getFakeReport();
expect(ReportUtils.hasOutstandingIOU(report)).toBe(false);
});
it('returns false when there is no iouReports collection', () => {
const report = {
...LHNTestUtils.getFakeReport(),
iouReportID: '1',
};
expect(ReportUtils.hasOutstandingIOU(report)).toBe(false);
});
it('returns false when there is no matching IOU report', () => {
const report = {
...LHNTestUtils.getFakeReport(),
iouReportID: '1',
};
const iouReports = {};
expect(ReportUtils.hasOutstandingIOU(report, undefined, iouReports)).toBe(false);
});
it('returns false when the matched IOU report does not have an owner email', () => {
const report = {
...LHNTestUtils.getFakeReport(),
iouReportID: '1',
};
const iouReports = {
reportIOUs_1: {
reportID: '1',
},
};
expect(ReportUtils.hasOutstandingIOU(report, undefined, iouReports)).toBe(false);
});
it('returns false when the matched IOU report does not have an owner email', () => {
const report = {
...LHNTestUtils.getFakeReport(),
iouReportID: '1',
};
const iouReports = {
reportIOUs_1: {
reportID: '1',
ownerEmail: '[email protected]',
},
};
expect(ReportUtils.hasOutstandingIOU(report, '[email protected]', iouReports)).toBe(false);
});
it('returns true when the report has an oustanding IOU', () => {
const report = {
...LHNTestUtils.getFakeReport(),
iouReportID: '1',
hasOutstandingIOU: true,
};
const iouReports = {
reportIOUs_1: {
reportID: '1',
ownerEmail: '[email protected]',
},
};
expect(ReportUtils.hasOutstandingIOU(report, '[email protected]', iouReports)).toBe(true);
});
it('returns false when the report has no oustanding IOU', () => {
const report = {
...LHNTestUtils.getFakeReport(),
iouReportID: '1',
hasOutstandingIOU: false,
};
const iouReports = {
reportIOUs_1: {
reportID: '1',
ownerEmail: '[email protected]',
},
};
expect(ReportUtils.hasOutstandingIOU(report, '[email protected]', iouReports)).toBe(false);
});
});
});

0 comments on commit f79df1a

Please sign in to comment.