Skip to content

Commit

Permalink
feat: [P4PU-000] Promote to UAT (#172)
Browse files Browse the repository at this point in the history
<!--- Please always add a PR description as if nobody knows anything
about the context these changes come from. -->
<!--- Even if we are all from our internal team, we may not be on the
same page. -->
<!--- Write this PR as you were contributing to a public OSS project,
where nobody knows you and you have to earn their trust. -->
<!--- This will improve our projects in the long run! Thanks. -->

#### List of Changes
- Added field totalAmount on notice details
<!--- Describe your changes in detail -->

#### Motivation and Context

<!--- Why is this change required? What problem does it solve? -->

#### How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, tests ran to see how
-->
<!--- your change affects other areas of the code, etc. -->

#### Screenshots (if appropriate):

#### Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)

#### Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
  • Loading branch information
Giuseppe-LaManna authored Dec 4, 2024
2 parents 30fe299 + bda9278 commit 1554d95
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 13 deletions.
4 changes: 4 additions & 0 deletions openapi/pagopa-arc-be.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ components:
- noticeDate
- pspName
- amount
- totalAmount
- origin
type: object
properties:
Expand Down Expand Up @@ -593,6 +594,9 @@ components:
fee:
type: integer
format: int64
totalAmount:
type: integer
format: int64
origin:
type: string
enum:
Expand Down
8 changes: 5 additions & 3 deletions postman/pagopa-arc-E2E.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,19 @@
" pm.test(\"[Get notice details - Case 1] - When you get the notice details, ARC return a notice details\", () => {\r",
" let jsonResponse = pm.response.json();\r",
"\r",
"\r",
" pm.expect(jsonResponse.infoNotice.eventId).to.eq(pm.collectionVariables.get('eventId'));\r",
" pm.expect(jsonResponse.carts).to.have.length(1);\r",
" pm.expect(jsonResponse.infoNotice).to.have.property(\"walletInfo\");\r",
" pm.expect(jsonResponse.infoNotice).to.have.property(\"paymentMethod\");\r",
" pm.expect(jsonResponse.infoNotice).to.have.property(\"payer\");\r",
" pm.expect(jsonResponse.infoNotice).to.have.property(\"origin\");\r",
"\r",
" pm.expect(jsonResponse.infoNotice.amount).to.eq(pm.collectionVariables.get('amountCents'));\r",
" pm.expect(jsonResponse.infoNotice.totalAmount).to.eq(pm.collectionVariables.get('totalAmount'));\r",
" pm.expect(jsonResponse.infoNotice.pspName).to.eq(\"Worldline Merchant Services Italia S.p.A.\")\r",
" pm.expect(jsonResponse.infoNotice.payer.name).not.eq(null);\r",
" pm.expect(jsonResponse.infoNotice.payer.taxCode).to.eq(pm.environment.get('CF_MOCK_BE_ARC'));\r",
"\r",
" pm.expect(jsonResponse.carts).to.have.length(1);\r",
" pm.expect(jsonResponse.carts[0]).to.have.property(\"subject\");\r",
" pm.expect(jsonResponse.carts[0]).to.have.property(\"refNumberType\");\r",
" pm.expect(jsonResponse.carts[0]).to.have.property(\"refNumberValue\");\r",
Expand Down Expand Up @@ -602,6 +602,7 @@
" pm.expect(jsonResponse.infoNotice).to.have.property(\"origin\");\r",
"\r",
" pm.expect(jsonResponse.infoNotice.amount).to.eq(pm.collectionVariables.get('amountCents'));\r",
" pm.expect(jsonResponse.infoNotice.totalAmount).to.eq(pm.collectionVariables.get('totalAmount'));\r",
" pm.expect(jsonResponse.infoNotice.pspName).to.eq(\"Worldline Merchant Services Italia S.p.A.\")\r",
" pm.expect(jsonResponse.infoNotice.payer.name).not.eq(null);\r",
" pm.expect(jsonResponse.infoNotice.payer.taxCode).to.eq(pm.environment.get('CF_MOCK_BE_ARC'));\r",
Expand Down Expand Up @@ -1016,6 +1017,7 @@
" pm.expect(jsonResponse.infoNotice).to.have.property(\"origin\");\r",
"\r",
" pm.expect(jsonResponse.infoNotice.amount).to.eq(pm.collectionVariables.get('amountCents'));\r",
" pm.expect(jsonResponse.infoNotice.totalAmount).to.eq(pm.collectionVariables.get('totalAmount'));\r",
" pm.expect(jsonResponse.infoNotice.pspName).to.eq(\"Worldline Merchant Services Italia S.p.A.\")\r",
"\r",
" pm.expect(jsonResponse.carts[0]).to.have.property(\"subject\");\r",
Expand Down Expand Up @@ -4545,4 +4547,4 @@
"value": ""
}
]
}
}
15 changes: 15 additions & 0 deletions src/main/java/it/gov/pagopa/arc/dto/mapper/MapperUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,19 @@ static ZonedDateTime dateStringToZonedDateTime(String dateString){
throw new BizEventsInvalidDateException("Invalid date format");
}
}

/** To calculate totalAmount (amount + fee) */
@Named("calculateTotalAmount")
static Long calculateTotalAmount(Long amount, Long fee){
if(amount == null){
return null;
}

if (fee == null) {
fee = 0L;
}

return Long.sum(amount, fee);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,33 @@
import it.gov.pagopa.arc.dto.mapper.BizEventsWalletInfo2WalletInfoDTOMapper;
import it.gov.pagopa.arc.dto.mapper.MapperUtilities;
import it.gov.pagopa.arc.model.generated.InfoNoticeDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.*;


@Mapper(componentModel = "spring", uses = {MapperUtilities.class, BizEventsWalletInfo2WalletInfoDTOMapper.class, BizEventsUserDetail2UserDetailDTOMapper.class})
public interface BizEventsInfoPaidNoticeDTO2InfoNoticeDTOMapper {

@Mapping(source = "amount", target = "amount", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, qualifiedByName = "euroToCents")
@Mapping(source = "fee", target = "fee", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, qualifiedByName = "euroToCents")
@Mapping(source = "fee", target = "fee", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, qualifiedByName = "euroToCents", defaultValue = "0L")
@Mapping(source = "noticeDate", target = "noticeDate", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, qualifiedByName = "dateStringToZonedDateTime")
@Mapping(source = "walletInfo", target = "walletInfo", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
@Mapping(source = "payer", target = "payer", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
@Mapping(target = "totalAmount", source = "bizEventsInfoPaidNoticeDTO")
InfoNoticeDTO toInfoNoticeDTO(BizEventsInfoPaidNoticeDTO bizEventsInfoPaidNoticeDTO);

default Long calculateTotalAmount(BizEventsInfoPaidNoticeDTO bizEventsInfoPaidNoticeDTO){
String bizEventsAmount = bizEventsInfoPaidNoticeDTO.getAmount();
String bizEventsFee = bizEventsInfoPaidNoticeDTO.getFee();
Long fee = 0L;

if (bizEventsAmount != null){
Long amount = MapperUtilities.euroToCents(bizEventsAmount);
if (bizEventsFee != null){
fee = MapperUtilities.euroToCents(bizEventsFee);
}

return MapperUtilities.calculateTotalAmount(amount, fee);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.*;

import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -81,4 +82,23 @@ void givenWrongDateStringWhenCallDateStringToZonedDateTimeThenReturnException(){
() -> MapperUtilities.dateStringToZonedDateTime(wrongDateString));
Assertions.assertEquals("Invalid date format",exception.getMessage());
}

@ParameterizedTest
@MethodSource("valueSource")
void givenCalculateTotalAmountWhenThen(Long amount, Long fee, Long expectedTotalAmount) {
//when
Long totalAmountResult = MapperUtilities.calculateTotalAmount(amount, fee);
//then
assertEquals(expectedTotalAmount, totalAmountResult);
}

static Stream<Arguments> valueSource() {
return Stream.of(
Arguments.of(500L, 20L, 520L),
Arguments.of(21L, 11L, 32L),
Arguments.of(320L, null, 320L),
Arguments.of(null, 19L, null),
Arguments.of(null, null, null)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ void givenBizEventsInfoPaidNoticeDTOWhenCallMapperThenReturnInfoNoticeDTO() {
Assertions.assertEquals("EVENT_ID", infoNoticeDTO.getEventId());
Assertions.assertEquals("250863", infoNoticeDTO.getAuthCode());
Assertions.assertEquals("51561651", infoNoticeDTO.getRrn());
Assertions.assertEquals("51561651", infoNoticeDTO.getRrn());
Assertions.assertEquals(ZonedDateTime.parse("2024-06-27T13:07:25Z"), infoNoticeDTO.getNoticeDate());
Assertions.assertEquals("Worldline Merchant Services Italia S.p.A.", infoNoticeDTO.getPspName());
assertEquals( 565430L, infoNoticeDTO.getAmount());
assertEquals( 29L, infoNoticeDTO.getFee());
assertEquals(565459L, infoNoticeDTO.getTotalAmount());
assertEquals(InfoNoticeDTO.OriginEnum.PM, infoNoticeDTO.getOrigin());

TestUtils.assertNotNullFields(infoNoticeDTO);
Expand All @@ -79,7 +79,7 @@ void givenBizEventsInfoPaidNoticeDTOWithNullWalletInfoAndPayerWhenCallMapperThen
.rrn("51561651")
.noticeDate("2024-06-27T13:07:25Z")
.pspName("Worldline Merchant Services Italia S.p.A.")
.amount("5,654.3")
.amount(null)
.fee("0.29")
.origin(Origin.PM)
.build();
Expand All @@ -90,14 +90,73 @@ void givenBizEventsInfoPaidNoticeDTOWithNullWalletInfoAndPayerWhenCallMapperThen
Assertions.assertEquals("EVENT_ID", infoNoticeDTO.getEventId());
Assertions.assertEquals("250863", infoNoticeDTO.getAuthCode());
Assertions.assertEquals("51561651", infoNoticeDTO.getRrn());
Assertions.assertEquals("51561651", infoNoticeDTO.getRrn());
Assertions.assertEquals(ZonedDateTime.parse("2024-06-27T13:07:25Z"), infoNoticeDTO.getNoticeDate());
Assertions.assertEquals("Worldline Merchant Services Italia S.p.A.", infoNoticeDTO.getPspName());
assertEquals( 565430L, infoNoticeDTO.getAmount());
assertNull(infoNoticeDTO.getAmount());
assertEquals( 29L, infoNoticeDTO.getFee());
assertNull(infoNoticeDTO.getTotalAmount());
assertEquals(InfoNoticeDTO.OriginEnum.PM, infoNoticeDTO.getOrigin());
assertNull(infoNoticeDTO.getWalletInfo());

TestUtils.assertNotNullFields(infoNoticeDTO, "walletInfo","paymentMethod","payer");
TestUtils.assertNotNullFields(infoNoticeDTO, "walletInfo","paymentMethod","payer", "amount", "totalAmount");
}

@Test
void givenAmountAndFeeWhenCalculateTotalAmountThenReturnTotalAmount() {
//given
BizEventsInfoPaidNoticeDTO bizEventsInfoPaidNoticeDTO = BizEventsInfoPaidNoticeDTO.builder()
.eventId("EVENT_ID")
.authCode("250863")
.rrn("51561651")
.noticeDate("2024-06-27T13:07:25Z")
.pspName("Worldline Merchant Services Italia S.p.A.")
.amount("58")
.fee("0.29")
.origin(Origin.PM)
.build();
//when
Long result = mapper.calculateTotalAmount(bizEventsInfoPaidNoticeDTO);
//then
Assertions.assertNotNull(result);
assertEquals(5829L,result);
}

@Test
void givenAmountAndNullFeeWhenCalculateTotalAmountThenReturnTotalAmount() {
//given
BizEventsInfoPaidNoticeDTO bizEventsInfoPaidNoticeDTO = BizEventsInfoPaidNoticeDTO.builder()
.eventId("EVENT_ID")
.authCode("250863")
.rrn("51561651")
.noticeDate("2024-06-27T13:07:25Z")
.pspName("Worldline Merchant Services Italia S.p.A.")
.amount("58")
.fee(null)
.origin(Origin.PM)
.build();
//when
Long result = mapper.calculateTotalAmount(bizEventsInfoPaidNoticeDTO);
//then
Assertions.assertNotNull(result);
assertEquals(5800L,result);
}

@Test
void givenNullAmountWhenCalculateTotalAmountThenReturnNull() {
//given
BizEventsInfoPaidNoticeDTO bizEventsInfoPaidNoticeDTO = BizEventsInfoPaidNoticeDTO.builder()
.eventId("EVENT_ID")
.authCode("250863")
.rrn("51561651")
.noticeDate("2024-06-27T13:07:25Z")
.pspName("Worldline Merchant Services Italia S.p.A.")
.amount(null)
.fee("0.29")
.origin(Origin.PM)
.build();
//when
Long result = mapper.calculateTotalAmount(bizEventsInfoPaidNoticeDTO);
//then
Assertions.assertNull(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private static InfoNoticeDTO.InfoNoticeDTOBuilder mockInstanceBuilder(WalletInfo
.payer(payer)
.amount(565430L)
.fee(29L)
.totalAmount(565459L)
.origin(InfoNoticeDTO.OriginEnum.UNKNOWN);

TestUtils.assertNotNullFields(infoNoticeDTOBuilder);
Expand Down

0 comments on commit 1554d95

Please sign in to comment.