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

do not fail when option is blank #1102

Merged
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
5 changes: 4 additions & 1 deletion src/main/java/alfio/manager/system/ConfigurationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.util.function.Predicate;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static alfio.model.system.ConfigurationKeys.*;
import static alfio.model.system.ConfigurationPathLevel.*;
Expand Down Expand Up @@ -582,10 +583,12 @@ public List<PaymentMethod> getBlacklistedMethodsForReservation(PurchaseContext p
return categoryIds.stream()
.filter(blacklistForCategories::containsKey)
.flatMap(id -> Arrays.stream(blacklistForCategories.get(id).split(",")))
.filter(StringUtils::isNotBlank)
.map(name -> PaymentProxy.valueOf(name).getPaymentMethod())
.collect(toList());
} else if (categoryIds.size() > 0) {
} else if (!categoryIds.isEmpty()) {
return configurationRepository.findByKeyAtCategoryLevel(e.getId(), e.getOrganizationId(), IterableUtils.get(categoryIds, 0), PAYMENT_METHODS_BLACKLIST.name())
.filter(v -> StringUtils.isNotBlank(v.getValue()))
.map(v -> Arrays.stream(v.getValue().split(",")).map(name -> PaymentProxy.valueOf(name).getPaymentMethod()).collect(toList()))
.orElse(List.of());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import alfio.manager.system.ConfigurationManager;
import alfio.manager.user.UserManager;
import alfio.model.Event;
import alfio.model.PurchaseContext;
import alfio.model.TicketCategory;
import alfio.model.TicketReservation;
import alfio.model.metadata.AlfioMetadata;
import alfio.model.modification.ConfigurationModification;
import alfio.model.modification.DateTimeModification;
Expand All @@ -43,6 +45,7 @@
import alfio.util.ClockProvider;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
Expand All @@ -58,6 +61,8 @@

import static alfio.model.system.ConfigurationKeys.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;


@SpringBootTest
Expand Down Expand Up @@ -102,8 +107,13 @@ public void prepareEnv() {
desc.put("it", "muh description");
desc.put("de", "muh description");

List<TicketCategoryModification> ticketsCategory = Collections.singletonList(
List<TicketCategoryModification> ticketsCategory = List.of(
new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, 20,
new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())),
new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())),
Collections.singletonMap("en", "desc"), BigDecimal.TEN, false, "", false, null, null,
null, null, null, 0, null, null, AlfioMetadata.empty()),
new TicketCategoryModification(null, "second", TicketCategory.TicketAccessType.INHERIT, 20,
new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())),
new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())),
Collections.singletonMap("en", "desc"), BigDecimal.TEN, false, "", false, null, null,
Expand Down Expand Up @@ -382,4 +392,20 @@ void testSystemApiKeyGeneration() {
assertFalse(apiKey2.isEmpty());
assertNotEquals(apiKey, apiKey2);
}

@Test
void ensureNoErrorsWhenDeniedMethodsOptionIsEmpty() {
var categories = ticketCategoryRepository.findAllTicketCategories(event.getId());
// insert empty value
configurationRepository.insertTicketCategoryLevel(event.getOrganizationId(), event.getId(), categories.get(0).getId(), PAYMENT_METHODS_BLACKLIST.name(), "", "");
// try with single category
var deniedMethods = configurationManager.getBlacklistedMethodsForReservation(event, List.of(categories.get(0).getId()));
assertNotNull(deniedMethods);
assertTrue(deniedMethods.isEmpty());

// try with multiple categories
deniedMethods = configurationManager.getBlacklistedMethodsForReservation(event, categories.stream().map(TicketCategory::getId).collect(Collectors.toList()));
assertNotNull(deniedMethods);
assertTrue(deniedMethods.isEmpty());
}
}