diff --git a/src/main/java/it/gov/pagopa/bizeventsservice/service/impl/TransactionService.java b/src/main/java/it/gov/pagopa/bizeventsservice/service/impl/TransactionService.java index addc4a03..71741f48 100644 --- a/src/main/java/it/gov/pagopa/bizeventsservice/service/impl/TransactionService.java +++ b/src/main/java/it/gov/pagopa/bizeventsservice/service/impl/TransactionService.java @@ -161,14 +161,17 @@ public TransactionDetailResponse getTransactionDetails(String taxCode, String ev @Override public void disableTransaction(String fiscalCode, String transactionId) { - List listOfViewUser = this.bizEventsViewUserRepository + + List listOfViewUser = this.bizEventsViewUserRepository .getBizEventsViewUserByTaxCodeAndTransactionId(fiscalCode, transactionId); - if (listOfViewUser.size() != 1) { + + if (CollectionUtils.isEmpty(listOfViewUser)) { throw new AppException(AppError.VIEW_USER_NOT_FOUND_WITH_TRANSACTION_ID, fiscalCode, transactionId); - } - BizEventsViewUser bizEventsViewUser = listOfViewUser.get(0); - bizEventsViewUser.setHidden(true); - bizEventsViewUserRepository.save(bizEventsViewUser); + } + + // PAGOPA-1831: set hidden to true for all transactions with the same transactionId for the given fiscalCode + listOfViewUser.forEach(u -> u.setHidden(true)); + bizEventsViewUserRepository.saveAll(listOfViewUser); } private List> retrievePaginatedList (String taxCode, Integer size) { diff --git a/src/test/java/it/gov/pagopa/bizeventsservice/service/TransactionServiceTest.java b/src/test/java/it/gov/pagopa/bizeventsservice/service/TransactionServiceTest.java index 795ce476..9b663b44 100644 --- a/src/test/java/it/gov/pagopa/bizeventsservice/service/TransactionServiceTest.java +++ b/src/test/java/it/gov/pagopa/bizeventsservice/service/TransactionServiceTest.java @@ -23,6 +23,7 @@ import org.apache.commons.lang3.SerializationUtils; import org.junit.jupiter.api.*; +import org.mockito.ArgumentCaptor; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -281,8 +282,32 @@ void transactionViewUserDisabled() { .thenReturn(viewUserList); Assertions.assertDoesNotThrow(() -> transactionService.disableTransaction( ViewGenerator.USER_TAX_CODE_WITH_TX, ViewGenerator.TRANSACTION_ID)); - viewUserList.get(0).setHidden(true); - verify(bizEventsViewUserRepository).save(viewUserList.get(0)); + + ArgumentCaptor> argument = ArgumentCaptor.forClass(List.class); + verify(bizEventsViewUserRepository).saveAll(argument.capture()); + assertEquals(Boolean.TRUE, argument.getValue().get(0).getHidden()); + } + + @Test + void transactionViewUserCartDisabled() { + + List viewUserList = new ArrayList<>(); + + for (int i=0; i<10; i++) { + BizEventsViewUser u = generateBizEventsViewUser(); + u.setId(u.getId()+"_"+i); + viewUserList.add(u); + } + + when(bizEventsViewUserRepository.getBizEventsViewUserByTaxCodeAndTransactionId(anyString(),anyString())) + .thenReturn(viewUserList); + + Assertions.assertDoesNotThrow(() -> transactionService.disableTransaction( + ViewGenerator.USER_TAX_CODE_WITH_TX, ViewGenerator.TRANSACTION_ID)); + + ArgumentCaptor> argument = ArgumentCaptor.forClass(List.class); + verify(bizEventsViewUserRepository).saveAll(argument.capture()); + argument.getValue().forEach(u -> assertEquals(Boolean.TRUE, u.getHidden())); } @Test diff --git a/src/test/java/it/gov/pagopa/bizeventsservice/util/ViewGenerator.java b/src/test/java/it/gov/pagopa/bizeventsservice/util/ViewGenerator.java index 97081365..b87c94d9 100644 --- a/src/test/java/it/gov/pagopa/bizeventsservice/util/ViewGenerator.java +++ b/src/test/java/it/gov/pagopa/bizeventsservice/util/ViewGenerator.java @@ -33,6 +33,7 @@ public class ViewGenerator { public static BizEventsViewUser generateBizEventsViewUser(){ return BizEventsViewUser.builder() + .id(EVENT_ID) .taxCode(USER_TAX_CODE_WITH_TX) .transactionId(TRANSACTION_ID) .transactionDate(TRANSACTION_DATE)