Skip to content

Commit

Permalink
PAGOPA-2348 add junit test to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoRuzzier committed Nov 7, 2024
1 parent c305a19 commit 36273e5
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/test/java/it/gov/pagopa/afm/calculator/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,51 @@ public static List<ValidBundle> getMockMultipleValidBundle() {
return bundles;
}

public static List<ValidBundle> getMockMultipleValidBundleSamePsp() {
List<ValidBundle> bundles = new ArrayList<>();
bundles.add(
ValidBundle.builder()
.id("1")
.idChannel("13212880150_01")
.name("bundle1")
.idPsp("ABC")
.pspBusinessName("psp business name")
.abi("14160")
.paymentAmount(50L)
.minPaymentAmount(0L)
.maxPaymentAmount(1000L)
.type(BundleType.GLOBAL)
.touchpoint("1")
.paymentType("CP")
.transferCategoryList(List.of("TAX1"))
.ciBundleList(new ArrayList<>())
.digitalStamp(false)
.digitalStampRestriction(false)
.onUs(true)
.build());
bundles.add(
ValidBundle.builder()
.id("2")
.idChannel("13212880150_02_ONUS")
.name("bundle2")
.idPsp("ABC")
.pspBusinessName("psp business name")
.abi("14156")
.paymentAmount(55L)
.minPaymentAmount(0L)
.maxPaymentAmount(1000L)
.type(BundleType.PUBLIC)
.touchpoint("1")
.paymentType("CP")
.transferCategoryList(List.of("TAX2"))
.ciBundleList(Collections.singletonList(getMockCiBundle()))
.digitalStamp(false)
.digitalStampRestriction(false)
.onUs(true)
.build());
return bundles;
}

public static Touchpoint getMockTouchpoints() {
return Touchpoint.builder().id("1").name("CHECKOUT").creationDate(LocalDateTime.now()).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,4 +769,21 @@ void calculateMultiFullCommission() throws IOException, JSONException {
String expected = TestUtil.readStringFromFile("responses/getFeesMultiWrongEC.json");
JSONAssert.assertEquals(expected, actual, JSONCompareMode.STRICT);
}

@Test
@Order(28)
void calculateMultiMultipleBundlesOneOutput() throws IOException, JSONException {
CosmosRepository cosmosRepository = Mockito.mock(CosmosRepository.class);
calculatorService.setCosmosRepository(cosmosRepository);

List<ValidBundle> validBundles = TestUtil.getMockMultipleValidBundleSamePsp();
Mockito.doReturn(validBundles).when(cosmosRepository).findByPaymentOption(any(PaymentOptionMulti.class), any(Boolean.class));

var paymentOption = TestUtil.readObjectFromFile("requests/getFeesMultiSamePsp.json", PaymentOptionMulti.class);
var result = calculatorService.calculateMulti(paymentOption, 10, true);
String actual = TestUtil.toJson(result);

String expected = TestUtil.readStringFromFile("responses/getFeesMultiSamePsp.json");
JSONAssert.assertEquals(expected, actual, JSONCompareMode.STRICT);
}
}
18 changes: 18 additions & 0 deletions src/test/resources/requests/getFeesMultiSamePsp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"bin": "1005066",
"paymentMethod": "CP",
"touchpoint": "CHECKOUT",
"idPspList": [],
"paymentNotice": [
{
"primaryCreditorInstitution": "77777777777",
"paymentAmount": 70,
"transferList": [
{
"creditorInstitution": "77777777777",
"transferCategory": "TAX1"
}
]
}
]
}
28 changes: 28 additions & 0 deletions src/test/resources/responses/getFeesMultiSamePsp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"belowThreshold": false,
"bundleOptions": [
{
"taxPayerFee": 55,
"actualPayerFee": 45,
"paymentMethod": "CP",
"touchpoint": "1",
"idBundle": "2",
"bundleName": "bundle2",
"bundleDescription": null,
"idsCiBundle": ["1"],
"idPsp": "ABC",
"idChannel": "13212880150_02_ONUS",
"idBrokerPsp": null,
"onUs": true,
"abi": "14156",
"pspBusinessName": "psp business name",
"fees": [
{
"creditorInstitution" : "77777777777",
"primaryCiIncurredFee": 10,
"actualCiIncurredFee": 10
}
]
}
]
}

0 comments on commit 36273e5

Please sign in to comment.