From 3d8011d11f3e3f5620f7ff1e2dc949247ec0188c Mon Sep 17 00:00:00 2001 From: Spichonak Pavel Date: Thu, 11 Nov 2021 13:43:04 +0300 Subject: [PATCH] UIU-2469: fix issue when a fee/fine is refunded due to a CLAIMED RETURNED, the refund amount does not appear in User Details --- CHANGELOG.md | 1 + .../UserAccounts/UserAccounts.js | 12 +++++-- .../util/refundTransferClaimReturned.js | 6 ++-- test/jest/__mock__/stripesCore.mock.js | 35 ++++++++++++++++++- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8119d5140..eb77020f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Fix FeeFineAction and FeeFineCharge notice templates not appearing in Manual Charges settings. Refs UIU-2452. * Do not label fees without loans as "Anonymized". Refs UIU-2449. * Fix the issue when fee/fine is partially paid, then refunded, User Details show the full amount of the fee/fine as refunded. Refs UIU-2455. +* Fix the issue when a fee/fine is refunded due to a CLAIMED RETURNED, the refund amount does not appear in User Details. Refs UIU-2469. ## [7.0.2](https://github.com/folio-org/ui-users/tree/v7.0.2) (2021-10-25) [Full Changelog](https://github.com/folio-org/ui-users/compare/v7.0.1...v7.0.2) diff --git a/src/components/UserDetailSections/UserAccounts/UserAccounts.js b/src/components/UserDetailSections/UserAccounts/UserAccounts.js index cc03acde6..dcbbf7886 100644 --- a/src/components/UserDetailSections/UserAccounts/UserAccounts.js +++ b/src/components/UserDetailSections/UserAccounts/UserAccounts.js @@ -15,7 +15,12 @@ import { } from '@folio/stripes/components'; import { useStripes } from '@folio/stripes/core'; -import { accountStatuses, refundStatuses, loanActions } from '../../../constants'; +import { + accountStatuses, + refundStatuses, + refundClaimReturned, + loanActions, +} from '../../../constants'; /** @@ -64,7 +69,10 @@ const UserAccounts = ({ const closed = records.filter(account => account?.status?.name === accountStatuses.CLOSED); // get refunded actions and refunds total amount - const refundStatusesValues = Object.values(refundStatuses); + const refundStatusesValues = [ + ...Object.values(refundStatuses), + refundClaimReturned.REFUNDED_ACTION, + ]; const feeFineActions = resources.feefineactions.records ?? []; const refunded = feeFineActions.filter((feeFineAction) => refundStatusesValues.includes(feeFineAction.typeAction)); const refundedTotal = refunded.reduce((acc, { amountAction }) => (acc + amountAction), 0); diff --git a/src/components/util/refundTransferClaimReturned.js b/src/components/util/refundTransferClaimReturned.js index f367d87df..c3b15a2f1 100644 --- a/src/components/util/refundTransferClaimReturned.js +++ b/src/components/util/refundTransferClaimReturned.js @@ -89,12 +89,14 @@ refundTransfers = async (loan, props) => { const { okapi: { currentUser: { - id: currentUserId, curServicePoint: { id: servicePointId } }, }, + user: { + id: userId, + }, } = props; if (actions[0].typeAction.startsWith(refundClaimReturned.TRANSFERRED_ACTION) || @@ -136,7 +138,7 @@ refundTransfers = async (loan, props) => { source: orderedActions[0].source, paymentMethod: '', accountId: orderedActions[0].accountId, - userId: currentUserId, + userId, createdAt: servicePointId, }; return persistRefundAction(newAction); diff --git a/test/jest/__mock__/stripesCore.mock.js b/test/jest/__mock__/stripesCore.mock.js index 506c0adfa..624c61db2 100644 --- a/test/jest/__mock__/stripesCore.mock.js +++ b/test/jest/__mock__/stripesCore.mock.js @@ -35,6 +35,38 @@ jest.mock('@folio/stripes/core', () => { }, withOkapi: true, }; + + // eslint-disable-next-line react/prop-types + const stripesConnect = Component => ({ mutator, resources, stripes, ...rest }) => { + const fakeMutator = mutator || Object.keys(Component.manifest || {}).reduce((acc, mutatorName) => { + const returnValue = Component.manifest[mutatorName].records ? [] : {}; + + acc[mutatorName] = { + GET: jest.fn().mockReturnValue(Promise.resolve(returnValue)), + PUT: jest.fn().mockReturnValue(Promise.resolve()), + POST: jest.fn().mockReturnValue(Promise.resolve()), + DELETE: jest.fn().mockReturnValue(Promise.resolve()), + reset: jest.fn(), + update: jest.fn(), + replace: jest.fn(), + }; + + return acc; + }, {}); + + const fakeResources = resources || Object.keys(Component.manifest || {}).reduce((acc, resourceName) => { + acc[resourceName] = { + records: [], + }; + + return acc; + }, {}); + + const fakeStripes = stripes || STRIPES; + + return ; + }; + return { AppIcon: jest.fn(({ ariaLabel }) => {ariaLabel}), TitleManager: jest.fn(({ children, ...rest }) => ( @@ -53,7 +85,8 @@ jest.mock('@folio/stripes/core', () => { } }), Pluggable: jest.fn(({ children }) => [children]), - stripesConnect: (Component) => (props) => , + connect: stripesConnect, + stripesConnect, useStripes: () => STRIPES, withStripes: // eslint-disable-next-line react/prop-types