Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

[SELC-4976] feat: add EA DelegationType #504

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2815,7 +2815,7 @@
},
"type" : {
"type" : "string",
"enum" : [ "AOO", "PT" ]
"enum" : [ "AOO", "EA", "PT" ]
}
}
},
Expand Down Expand Up @@ -2846,7 +2846,7 @@
},
"type" : {
"type" : "string",
"enum" : [ "AOO", "PT" ]
"enum" : [ "AOO", "EA", "PT" ]
}
}
},
Expand Down Expand Up @@ -2898,7 +2898,7 @@
},
"type" : {
"type" : "string",
"enum" : [ "AOO", "PT" ]
"enum" : [ "AOO", "EA", "PT" ]
},
"updatedAt" : {
"type" : "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public enum DelegationType {
PT,
AOO,
EA
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import it.pagopa.selfcare.mscore.web.model.mapper.DelegationMapperImpl;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
Expand Down Expand Up @@ -55,8 +57,9 @@ class DelegationControllerTest {
/**
* Method under test: {@link DelegationController#createDelegation(DelegationRequest)}
*/
@Test
void testCreateDelegation() throws Exception {
@ParameterizedTest
@EnumSource(value = DelegationType.class)
void testCreateDelegation(DelegationType delegationType) throws Exception {

Delegation delegation = new Delegation();
delegation.setId("id");
Expand All @@ -69,7 +72,7 @@ void testCreateDelegation() throws Exception {
delegationRequest.setInstitutionFromName("Test name");
delegationRequest.setInstitutionToName("Test to name");
delegationRequest.setProductId("productId");
delegationRequest.setType(DelegationType.PT);
delegationRequest.setType(delegationType);
String content = (new ObjectMapper()).writeValueAsString(delegationRequest);
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders
.post("/delegations")
Expand Down Expand Up @@ -211,47 +214,6 @@ void getDelegations_shouldGetDataCustom() throws Exception {
verifyNoMoreInteractions(delegationService);
}

/**
* Method under test: {@link DelegationController#getDelegations(String, String, String, String, String, Optional, Optional, Optional)}
*/
@Test
void getDelegations_shouldGetData_nullMode() throws Exception {
// Given
Delegation expectedDelegation = dummyDelegation();

when(delegationService.getDelegations(expectedDelegation.getFrom(), expectedDelegation.getTo(),
expectedDelegation.getProductId(), null, null, Optional.empty(), Optional.empty(), Optional.empty()))
.thenReturn(List.of(expectedDelegation));
// When
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders
.get("/delegations?institutionId={institutionId}&brokerId={brokerId}&productId={productId}", expectedDelegation.getFrom(),
expectedDelegation.getTo(), expectedDelegation.getProductId());
MvcResult result = MockMvcBuilders.standaloneSetup(delegationController)
.build()
.perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentType("application/json"))
.andReturn();

List<DelegationResponse> response = objectMapper.readValue(
result.getResponse().getContentAsString(), new TypeReference<>() {});
// Then
assertThat(response).isNotNull();
assertThat(response.size()).isEqualTo(1);
DelegationResponse actual = response.get(0);
assertThat(actual.getId()).isEqualTo(expectedDelegation.getId());
assertThat(actual.getInstitutionName()).isEqualTo(expectedDelegation.getInstitutionFromName());
assertThat(actual.getBrokerId()).isEqualTo(expectedDelegation.getTo());
assertThat(actual.getProductId()).isEqualTo(expectedDelegation.getProductId());
assertThat(actual.getInstitutionId()).isEqualTo(expectedDelegation.getFrom());
assertThat(actual.getInstitutionRootName()).isEqualTo(expectedDelegation.getInstitutionFromRootName());

verify(delegationService, times(1))
.getDelegations(expectedDelegation.getFrom(), expectedDelegation.getTo(),
expectedDelegation.getProductId(), null, null, Optional.empty(), Optional.empty(), Optional.empty());
verifyNoMoreInteractions(delegationService);
}

private Delegation dummyDelegation() {
Delegation delegation = new Delegation();
delegation.setFrom("from");
Expand Down
Loading