Skip to content

Commit

Permalink
feat: [PagoPa-1831] disable cart transactions (#73)
Browse files Browse the repository at this point in the history
* [PAGOPA-1831] disable cart: managed disabling for cart-type transactions

* [PAGOPA-1831] disable cart: add junit test

---------

Co-authored-by: pagopa-github-bot <github-bot@pagopa.it>
Co-authored-by: aacitelli <aacitelli@PDD-NB-0205.dgsgroup.it>
  • Loading branch information
3 people authored Jun 19, 2024
1 parent 70c144e commit cf83be6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,17 @@ public TransactionDetailResponse getTransactionDetails(String taxCode, String ev

@Override
public void disableTransaction(String fiscalCode, String transactionId) {
List<BizEventsViewUser> listOfViewUser = this.bizEventsViewUserRepository

List<BizEventsViewUser> 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<List<BizEventsViewUser>> retrievePaginatedList (String taxCode, Integer size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<List<BizEventsViewUser>> argument = ArgumentCaptor.forClass(List.class);
verify(bizEventsViewUserRepository).saveAll(argument.capture());
assertEquals(Boolean.TRUE, argument.getValue().get(0).getHidden());
}

@Test
void transactionViewUserCartDisabled() {

List<BizEventsViewUser> 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<List<BizEventsViewUser>> argument = ArgumentCaptor.forClass(List.class);
verify(bizEventsViewUserRepository).saveAll(argument.capture());
argument.getValue().forEach(u -> assertEquals(Boolean.TRUE, u.getHidden()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cf83be6

Please sign in to comment.