Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VAS-1167] feat: checks for legacy cart on helpdesk functions #75

Merged
merged 5 commits into from
Jul 10, 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
1 change: 1 addition & 0 deletions helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ microservice-chart:
RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS: "0"
RECOVER_NOT_NOTIFIED_MASSIVE_MAX_RECORDS: "200"
ECOMMERCE_FILTER_ENABLED: "true"
UNWANTED_REMITTANCE_INFO: "pagamento multibeneficiario,pagamento bpay"
envConfigMapExternals:
template-maps:
BRAND_LOGO_MAP: brand-logo-map
Expand Down
13 changes: 7 additions & 6 deletions helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,18 @@ microservice-chart:
MAX_DATE_DIFF_MILLIS: "1800000" # 30min
MAX_DATE_DIFF_NOTIFY_MILLIS: "1800000" # 30nin
MAX_DATE_DIFF_CART_MILLIS: "1800000" # 30nin
TRIGGER_NOTIFY_REC_SCHEDULE: "0 0 */1 * * *"
RECOVER_FAILED_CRON: "0 0 */1 * * *"
RECOVER_FAILED_CART_CRON: "0 0 */1 * * *"
TRIGGER_NOTIFY_REC_SCHEDULE: "0 0 */1 * * *" # https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=python-v2%2Cisolated-process%2Cnodejs-v4&pivots=programming-language-java#function-apps-sharing-storage
RECOVER_FAILED_CRON: "0 0 */1 * * *" # https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=python-v2%2Cisolated-process%2Cnodejs-v4&pivots=programming-language-java#function-apps-sharing-storage
RECOVER_FAILED_CART_CRON: "0 0 */1 * * *" # https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=python-v2%2Cisolated-process%2Cnodejs-v4&pivots=programming-language-java#function-apps-sharing-storage
AZURE_FUNCTIONS_MESH_JAVA_OPTS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/opentelemetry-javaagent.jar -Xmx768m -XX:+UseG1GC"
FAILED_AUTORECOVER_ENABLED: "false"
NOT_NOTIFIED_AUTORECOVER_ENABLED: "false"
FAILED_CART_AUTORECOVER_ENABLED: "false"
FAILED_AUTORECOVER_ENABLED: "true" # https://pagopa.atlassian.net/wiki/spaces/PPR/pages/822870269/Analisi+APIs+Monitoring+Recover+helpdesk-receipt
NOT_NOTIFIED_AUTORECOVER_ENABLED: "true" # https://pagopa.atlassian.net/wiki/spaces/PPR/pages/822870269/Analisi+APIs+Monitoring+Recover+helpdesk-receipt
FAILED_CART_AUTORECOVER_ENABLED: "true" # https://pagopa.atlassian.net/wiki/spaces/PPR/pages/822870269/Analisi+APIs+Monitoring+Recover+helpdesk-receipt
RECOVER_FAILED_MASSIVE_MAX_DAYS: "1"
RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS: "1"
RECOVER_NOT_NOTIFIED_MASSIVE_MAX_RECORDS: "200"
ECOMMERCE_FILTER_ENABLED: "true"
UNWANTED_REMITTANCE_INFO: "pagamento multibeneficiario,pagamento bpay"
envConfigMapExternals:
template-maps:
BRAND_LOGO_MAP: brand-logo-map
Expand Down
1 change: 1 addition & 0 deletions helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ microservice-chart:
RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS: "0"
RECOVER_NOT_NOTIFIED_MASSIVE_MAX_RECORDS: "200"
ECOMMERCE_FILTER_ENABLED: "true"
UNWANTED_REMITTANCE_INFO: "pagamento multibeneficiario,pagamento bpay"
envConfigMapExternals:
template-maps:
BRAND_LOGO_MAP: brand-logo-map
Expand Down
2 changes: 1 addition & 1 deletion integration-test/src/step_definitions/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function createEvent(id, status, transactionId, totalNotice, orgCode, iuv) {
"idTransaction": "123456",
"transactionId": transactionId || "123456",
"grandTotal": 0,
"amount": 0,
"amount": 1000,
"fee": 0
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ public static boolean isBizEventInvalid(BizEvent bizEvent, ExecutionContext cont
return true;
}

if (!isCartMod1(bizEvent)) {
logger.debug("[{}] event with id {} contain either an invalid amount value," +
" or it is a legacy cart element",
context.getFunctionName(), bizEvent.getId());
return true;
}


if (bizEvent.getPaymentInfo() != null) {
String totalNotice = bizEvent.getPaymentInfo().getTotalNotice();

Expand Down Expand Up @@ -513,4 +521,21 @@ public static Integer getTotalNotice(BizEvent bizEvent, ExecutionContext context
}
return 1;
}

/**
* Method to check if the content comes from a legacy cart model (see https://pagopa.atlassian.net/browse/VAS-1167)
* @param bizEvent bizEvent to validate
* @return flag to determine if it is a manageable cart, or otherwise, will return false if
* it is considered a legacy cart content (not having a totalNotice field and having amount values != 0)
*/
public static boolean isCartMod1(BizEvent bizEvent) {
if (bizEvent.getPaymentInfo() != null && bizEvent.getPaymentInfo().getTotalNotice() == null) {
return bizEvent.getTransactionDetails() != null &&
new BigDecimal(bizEvent.getPaymentInfo().getAmount()).subtract(
formatEuroCentAmount(bizEvent.getTransactionDetails().getTransaction().getAmount()))
.floatValue() == 0;
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.mockito.stubbing.Answer;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -386,6 +387,8 @@ void runDiscardedWithEventNotDONE() throws BizEventNotFoundException {
verifyNoInteractions(queueClientMock);
}



@Test
void generateAnonymousDebtorBizEvent() throws BizEventNotFoundException {
BizEvent bizEvent = generateAnonymDebtorBizEvent();
Expand Down Expand Up @@ -431,8 +434,9 @@ void runDiscardedWithEventNull() throws BizEventNotFoundException {
}

@Test
void runDiscardedWithCartEvent() throws BizEventNotFoundException {
when(bizEventCosmosClientMock.getBizEventDocument(EVENT_ID)).thenReturn(generateValidBizEvent("2"));
void runDiscardedWithCartEventWithInvalidTotalNotice() throws BizEventNotFoundException {
when(bizEventCosmosClientMock.getBizEventDocument(EVENT_ID))
.thenReturn(generateValidBizEvent("invalid string"));

doAnswer((Answer<HttpResponseMessage.Builder>) invocation -> {
HttpStatus status = (HttpStatus) invocation.getArguments()[0];
Expand All @@ -452,16 +456,17 @@ void runDiscardedWithCartEvent() throws BizEventNotFoundException {
}

@Test
void runDiscardedWithCartEventWithInvalidTotalNotice() throws BizEventNotFoundException {
void runDiscardedWithInvalidCartAmounts() throws BizEventNotFoundException {
BizEvent bizEvent = generateValidBizEvent(null);
bizEvent.getTransactionDetails().getTransaction().setAmount(10);
when(bizEventCosmosClientMock.getBizEventDocument(EVENT_ID))
.thenReturn(generateValidBizEvent("invalid string"));
.thenReturn(bizEvent);

doAnswer((Answer<HttpResponseMessage.Builder>) invocation -> {
HttpStatus status = (HttpStatus) invocation.getArguments()[0];
return new HttpResponseMessageMock.HttpResponseMessageBuilderMock().status(status);
}).when(requestMock).createResponseBuilder(any(HttpStatus.class));

// test execution
HttpResponseMessage response = assertDoesNotThrow(() -> sut.run(requestMock, EVENT_ID, documentdb, contextMock));

// test assertion
Expand All @@ -471,6 +476,7 @@ void runDiscardedWithCartEventWithInvalidTotalNotice() throws BizEventNotFoundEx

verifyNoInteractions(receiptCosmosServiceMock);
verifyNoInteractions(queueClientMock);

}

@Test
Expand Down Expand Up @@ -539,11 +545,13 @@ private BizEvent generateValidBizEvent(String totalNotice){
TransactionDetails transactionDetails = new TransactionDetails();
Transaction transaction = new Transaction();
transaction.setCreationDate(String.valueOf(LocalDateTime.now()));
transaction.setAmount(10000);
transactionDetails.setTransaction(transaction);
transactionDetails.setOrigin("INFO");

PaymentInfo paymentInfo = new PaymentInfo();
paymentInfo.setTotalNotice(totalNotice);
paymentInfo.setAmount("100.0");

item.setEventStatus(BizEventStatusType.DONE);
item.setId(EVENT_ID);
Expand Down
Loading