Skip to content

Commit

Permalink
UIU-3230 isDcbItem must handle sparse data (#2762)
Browse files Browse the repository at this point in the history
Sometimes, item records are removed even when they are attached to open
loans.  Optional chaining in `isDcbItem()` prevents an NPE in this
circumstance.

Refs UIU-3230
  • Loading branch information
zburke authored Oct 14, 2024
1 parent 18162ec commit f106bde
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
* Open loans: Print Due date receipt for multiple open loans. Refs UIU-3209.
* Update `notes` to `v4.0`. Refs UIU-3229.
* Loan details: Print Due date receipt. Refs UIU-3210.
* Open loans: `isDcbItem()` must tolerate sparse data. Refs UIU-3230.

## [10.1.2](https://github.com/folio-org/ui-users/tree/v10.1.2) (2024-09-05)
[Full Changelog](https://github.com/folio-org/ui-users/compare/v10.1.1...v10.1.2)
Expand Down
2 changes: 1 addition & 1 deletion src/components/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export const isAffiliationsEnabled = (user) => {
return !isPatronUser(user) && !isDcbUser(user);
};

export const isDcbItem = (item) => item.instanceId === DCB_INSTANCE_ID && item.holdingsRecordId === DCB_HOLDINGS_RECORD_ID;
export const isDcbItem = (item) => item?.instanceId === DCB_INSTANCE_ID && item?.holdingsRecordId === DCB_HOLDINGS_RECORD_ID;

export const isAValidUUID = (str) => {
const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
Expand Down
14 changes: 14 additions & 0 deletions src/components/util/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,20 @@ describe('isDcbItem ', () => {
};
expect(isDcbItem(item)).toBeFalsy();
});

describe('should return false if the record is sparsely populated', () => {
it('handles missing instanceId', () => {
const item = {
};
expect(isDcbItem(item)).toBeFalsy();
});
it('handles missing instanceId', () => {
const item = {
instanceId: DCB_INSTANCE_ID,
};
expect(isDcbItem(item)).toBeFalsy();
});
});
});

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

0 comments on commit f106bde

Please sign in to comment.