Skip to content

Commit

Permalink
[PIDM-35] feat: updateTransferIbanMassive unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
svariant committed Jan 28, 2025
1 parent cc2e142 commit 6bfc12f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public ResponseEntity<String> updateTransferIbanMassive(
String.format(
LOG_BASE_HEADER_INFO,
"POST",
"updateIbanMassive",
"updateTransferIbanMassive",
String.format(
"organizationFiscalCode= %s; oldIban= %s; newIban= %s",
organizationFiscalCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
Expand All @@ -14,7 +12,9 @@
import it.gov.pagopa.debtposition.dto.PaymentOptionDTO;
import it.gov.pagopa.debtposition.dto.PaymentPositionDTO;
import it.gov.pagopa.debtposition.dto.TransferDTO;
import it.gov.pagopa.debtposition.model.payments.UpdateTransferIbanMassiveModel;
import it.gov.pagopa.debtposition.model.pd.NotificationFeeUpdateModel;
import it.gov.pagopa.debtposition.service.payments.PaymentsService;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -25,6 +25,7 @@
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
Expand Down Expand Up @@ -62,6 +63,9 @@ class PaymentsControllerTest {
private ModelMapper modelMapperMock;

@MockBean private NodeClient nodeClient;

@SpyBean
private PaymentsService paymentsService;

@Value("${nav.aux.digit}")
private String auxDigit;
Expand Down Expand Up @@ -1479,5 +1483,48 @@ void ValidationError_checkPaymentPositionAccountability_Transfer() throws Except
fail("Not the expected exception: "+e.getMessage());
}
}


/**
* UPDATE IBAN ON TRANSFERS
*/

@Test
void updateTransferIbanMassive_200() throws Exception {
UpdateTransferIbanMassiveModel request = UpdateTransferIbanMassiveModel.builder().oldIban("oldIban").newIban("newIban").build();

doReturn(1).when(paymentsService).updateTransferIbanMassive("77777777777", "oldIban", "newIban");

mvc.perform(post("/organizations/77777777777/transfers/update/iban")
.content(TestUtil.toJson(request)).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.TEXT_PLAIN))
.andExpect(content().string("Updated IBAN on 1 Transfers"));
}

@Test
void updateTransferIbanMassive_404() throws Exception {
UpdateTransferIbanMassiveModel request = UpdateTransferIbanMassiveModel.builder().oldIban("oldIban").newIban("newIban").build();

mvc.perform(post("/organizations/notFoundOrg/transfers/update/iban")
.content(TestUtil.toJson(request)).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound());
}

@Test
void updateTransferIbanMassive_400_noOldIban() throws Exception {
UpdateTransferIbanMassiveModel request = UpdateTransferIbanMassiveModel.builder().oldIban(null).newIban("newIban").build();

mvc.perform(post("/organizations/notFoundOrg/transfers/update/iban")
.content(TestUtil.toJson(request)).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());
}

@Test
void updateTransferIbanMassive_400_noNewIban() throws Exception {
UpdateTransferIbanMassiveModel request = UpdateTransferIbanMassiveModel.builder().oldIban("oldIban").newIban(null).build();

mvc.perform(post("/organizations/notFoundOrg/transfers/update/iban")
.content(TestUtil.toJson(request)).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());
}
}

0 comments on commit 6bfc12f

Please sign in to comment.