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

feat: [RTD-954] add min and max validation on amount input field #297

Merged
merged 2 commits into from
Nov 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package it.gov.pagopa.rtd.transaction_filter.batch.model;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import lombok.*;

import javax.validation.constraints.NotBlank;
Expand Down Expand Up @@ -84,8 +86,11 @@

/**
* Transaction amount
* max value: 999.999.999,99€
*/
@NotNull
@Min(value = 0)
@Max(value = 99999999999L)
Long amount;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void processTransactionWithValidCorrelationId(String correlationId) {
}

@ParameterizedTest
@ValueSource(longs = {1000, 200000})
@ValueSource(longs = {0, 1000, 200000, Integer.MAX_VALUE + 1L, 3000000000L, 99999999999L})
void processTransactionWithValidAmount(Long amount) {
BDDMockito.doReturn(true).when(storeServiceMock).hasHpan(FAKE_ENROLLED_PAN);
BDDMockito.doReturn(FAKE_SALT).when(storeServiceMock).getSalt();
Expand All @@ -241,6 +241,17 @@ void processTransactionWithValidAmount(Long amount) {
Assertions.assertEquals(amount, outbound.getAmount());
}

@ParameterizedTest
@ValueSource(longs = {-100L, 100000000000L})
void processTransactionWithInvalidAmount(Long amount) {
BDDMockito.doReturn(true).when(storeServiceMock).hasHpan(FAKE_ENROLLED_PAN);
BDDMockito.doReturn(FAKE_SALT).when(storeServiceMock).getSalt();
InboundTransaction transaction = fakeInboundTransaction();
transaction.setAmount(amount);
InboundTransactionItemProcessor processor = new InboundTransactionItemProcessor(storeServiceMock, false);
Assertions.assertThrows(ConstraintViolationException.class, () -> processor.process(transaction));
}

@ParameterizedTest
@ValueSource(strings = {"1234", "412", "15", ""})
void processTransactionWithInvalidAmountCurrencyThrowsException(String amountCurrency) {
Expand Down