use of alfio.test.util.IntegrationTestUtil.AVAILABLE_SEATS in project alf.io by alfio-event.
the class TicketReservationManagerIntegrationTest method testTicketSelection.
@Test
void testTicketSelection() {
List<TicketCategoryModification> categories = List.of(new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())), new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()), new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, 10, new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())), new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
Pair<Event, String> eventAndUsername = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
Event event = eventAndUsername.getKey();
TicketCategory bounded = ticketCategoryRepository.findAllTicketCategories(event.getId()).stream().filter(TicketCategory::isBounded).findFirst().orElseThrow(IllegalStateException::new);
TicketCategory unbounded = ticketCategoryRepository.findAllTicketCategories(event.getId()).stream().filter(t -> !t.isBounded()).findFirst().orElseThrow(IllegalStateException::new);
assertEquals(0, eventStatisticsManager.loadModifiedTickets(event.getId(), bounded.getId(), 0, null).size());
assertEquals(Integer.valueOf(0), eventStatisticsManager.countModifiedTicket(event.getId(), bounded.getId(), null));
assertEquals(0, eventStatisticsManager.loadModifiedTickets(event.getId(), unbounded.getId(), 0, null).size());
TicketReservationModification tr = new TicketReservationModification();
tr.setQuantity(10);
tr.setTicketCategoryId(bounded.getId());
TicketReservationModification tr2 = new TicketReservationModification();
tr2.setQuantity(9);
tr2.setTicketCategoryId(unbounded.getId());
TicketReservationWithOptionalCodeModification mod = new TicketReservationWithOptionalCodeModification(tr, Optional.empty());
TicketReservationWithOptionalCodeModification mod2 = new TicketReservationWithOptionalCodeModification(tr2, Optional.empty());
String reservationId = ticketReservationManager.createTicketReservation(event, List.of(mod, mod2), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Locale.ENGLISH, false, null);
List<TicketReservation> reservations = purchaseContextSearchManager.findAllReservationsFor(event, 0, null, null).getKey();
assertEquals(1, reservations.size());
assertEquals(reservationId, reservations.get(0).getId());
List<Ticket> pendingTickets = ticketRepository.findPendingTicketsInCategories(List.of(bounded.getId(), unbounded.getId()));
assertEquals(19, pendingTickets.size());
pendingTickets.forEach(t -> assertEquals(1000, t.getFinalPriceCts()));
List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
assertEquals(1, tickets.size());
assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() == null));
Pair<TotalPrice, Optional<PromoCodeDiscount>> priceAndDiscount = ticketReservationManager.totalReservationCostWithVAT(reservationId);
TotalPrice totalPrice = priceAndDiscount.getLeft();
assertTrue(priceAndDiscount.getRight().isEmpty());
assertEquals(0, ticketReservationManager.getPendingPayments(event.getShortName()).size());
PaymentSpecification specification = new PaymentSpecification(reservationId, null, totalPrice.getPriceWithVAT(), event, "email@example.com", new CustomerName("full name", "full", "name", event.mustUseFirstAndLastName()), "billing address", null, Locale.ENGLISH, true, false, null, "IT", "123456", PriceContainer.VatStatus.INCLUDED, true, false);
PaymentResult confirm = ticketReservationManager.performPayment(specification, totalPrice, PaymentProxy.OFFLINE, PaymentMethod.BANK_TRANSFER, null);
assertTrue(confirm.isSuccessful());
assertEquals(TicketReservation.TicketReservationStatus.OFFLINE_PAYMENT, ticketReservationManager.findById(reservationId).get().getStatus());
assertEquals(1, ticketReservationManager.getPendingPayments(event.getShortName()).size());
var from = ZonedDateTime.now(Clock.systemUTC()).minusDays(1).with(d -> d.with(ChronoField.HOUR_OF_DAY, 0));
var to = ZonedDateTime.now(Clock.systemUTC()).plusDays(1).with(ChronoField.HOUR_OF_DAY, 23);
// -> no reservations
assertTrue(ticketReservationRepository.getSoldStatistic(event.getId(), from, to, "day").stream().allMatch(tds -> tds.getCount() == 0L));
ticketReservationManager.validateAndConfirmOfflinePayment(reservationId, event, new BigDecimal("190.00"), eventAndUsername.getValue());
var soldStatisticsList = ticketReservationRepository.getSoldStatistic(event.getId(), from, to, "day");
assertEquals(3, soldStatisticsList.size());
assertEquals(LocalDate.now(ClockProvider.clock()).toString(), soldStatisticsList.get(1).getDate());
// -> 19 tickets reserved
assertEquals(19L, soldStatisticsList.get(1).getCount());
assertEquals(19L, soldStatisticsList.stream().mapToLong(TicketsByDateStatistic::getCount).sum());
assertEquals(10, eventStatisticsManager.loadModifiedTickets(event.getId(), bounded.getId(), 0, null).size());
assertEquals(Integer.valueOf(10), eventStatisticsManager.countModifiedTicket(event.getId(), bounded.getId(), null));
assertEquals(9, eventStatisticsManager.loadModifiedTickets(event.getId(), unbounded.getId(), 0, null).size());
assertEquals(Integer.valueOf(9), eventStatisticsManager.countModifiedTicket(event.getId(), unbounded.getId(), null));
assertEquals(TicketReservation.TicketReservationStatus.COMPLETE, ticketReservationManager.findById(reservationId).get().getStatus());
// -------------------
TicketReservationModification trForDelete = new TicketReservationModification();
trForDelete.setQuantity(1);
trForDelete.setTicketCategoryId(unbounded.getId());
TicketReservationWithOptionalCodeModification modForDelete = new TicketReservationWithOptionalCodeModification(trForDelete, Optional.empty());
String reservationId2 = ticketReservationManager.createTicketReservation(event, Collections.singletonList(modForDelete), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Locale.ENGLISH, false, null);
PaymentSpecification specification2 = new PaymentSpecification(reservationId2, null, totalPrice.getPriceWithVAT(), event, "email@example.com", new CustomerName("full name", "full", "name", event.mustUseFirstAndLastName()), "billing address", null, Locale.ENGLISH, true, false, null, "IT", "123456", PriceContainer.VatStatus.INCLUDED, true, false);
PaymentResult confirm2 = ticketReservationManager.performPayment(specification2, totalPrice, PaymentProxy.OFFLINE, PaymentMethod.BANK_TRANSFER, null);
assertTrue(confirm2.isSuccessful());
ticketReservationManager.deleteOfflinePayment(event, reservationId2, false, false, null);
assertFalse(ticketReservationManager.findById(reservationId2).isPresent());
}
use of alfio.test.util.IntegrationTestUtil.AVAILABLE_SEATS in project alf.io by alfio-event.
the class TicketReservationManagerIntegrationTest method testPriceIsOverridden.
@Test
void testPriceIsOverridden() {
List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())), new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository).getKey();
TicketReservationModification tr = new TicketReservationModification();
tr.setQuantity(2);
TicketCategory category = ticketCategoryRepository.findAllTicketCategories(event.getId()).get(0);
tr.setTicketCategoryId(category.getId());
TicketReservationWithOptionalCodeModification mod = new TicketReservationWithOptionalCodeModification(tr, Optional.empty());
ticketReservationManager.createTicketReservation(event, Collections.singletonList(mod), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Locale.ENGLISH, false, null);
List<Ticket> pendingTickets = ticketRepository.findPendingTicketsInCategories(Collections.singletonList(category.getId()));
assertEquals(2, pendingTickets.size());
pendingTickets.forEach(t -> assertEquals(1000, t.getFinalPriceCts()));
List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
assertEquals(18, tickets.size());
assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() == null));
}
use of alfio.test.util.IntegrationTestUtil.AVAILABLE_SEATS in project alf.io by alfio-event.
the class TicketReservationManagerIntegrationTest method testWithAdditionalServices.
@Test
void testWithAdditionalServices() {
List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())), new DateTimeModification(LocalDate.now(ClockProvider.clock()), LocalTime.now(ClockProvider.clock())), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
List<EventModification.AdditionalService> additionalServices = Collections.singletonList(new EventModification.AdditionalService(null, BigDecimal.TEN, true, 1, 100, 5, DateTimeModification.fromZonedDateTime(ZonedDateTime.now(ClockProvider.clock()).minusDays(1L)), DateTimeModification.fromZonedDateTime(ZonedDateTime.now(ClockProvider.clock()).plusDays(1L)), BigDecimal.TEN, AdditionalService.VatType.INHERITED, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), AdditionalService.AdditionalServiceType.SUPPLEMENT, AdditionalService.SupplementPolicy.OPTIONAL_UNLIMITED_AMOUNT));
Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository, additionalServices, Event.EventFormat.IN_PERSON).getKey();
TicketCategory unbounded = ticketCategoryRepository.findAllTicketCategories(event.getId()).stream().filter(t -> !t.isBounded()).findFirst().orElseThrow(IllegalStateException::new);
TicketReservationModification tr = new TicketReservationModification();
tr.setQuantity(3);
tr.setTicketCategoryId(unbounded.getId());
TicketReservationWithOptionalCodeModification mod = new TicketReservationWithOptionalCodeModification(tr, Optional.empty());
AdditionalServiceReservationModification asrm = new AdditionalServiceReservationModification();
asrm.setAdditionalServiceId(additionalServiceRepository.loadAllForEvent(event.getId()).get(0).getId());
asrm.setQuantity(1);
ASReservationWithOptionalCodeModification asMod = new ASReservationWithOptionalCodeModification(asrm, Optional.empty());
String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(mod), Collections.singletonList(asMod), DateUtils.addDays(new Date(), 1), Optional.of("MYPROMOCODE"), Locale.ENGLISH, false, null);
Pair<TotalPrice, Optional<PromoCodeDiscount>> priceAndDiscount = ticketReservationManager.totalReservationCostWithVAT(reservationId);
TotalPrice totalPrice = priceAndDiscount.getLeft();
assertTrue(priceAndDiscount.getRight().isEmpty());
// 3 tickets + 1 AS
assertEquals(4000, totalPrice.getPriceWithVAT());
assertEquals(40, totalPrice.getVAT());
assertEquals(0, totalPrice.getDiscount());
assertEquals(0, totalPrice.getDiscountAppliedCount());
OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, event);
assertEquals("40.00", orderSummary.getTotalPrice());
assertEquals("0.40", orderSummary.getTotalVAT());
assertEquals(3, orderSummary.getTicketAmount());
List<SummaryRow> asRows = orderSummary.getSummary().stream().filter(s -> s.getType() == SummaryRow.SummaryType.ADDITIONAL_SERVICE).collect(Collectors.toList());
assertEquals(1, asRows.size());
assertEquals("9.90", asRows.get(0).getPriceBeforeVat());
assertEquals("9.90", asRows.get(0).getSubTotalBeforeVat());
assertEquals("10.00", asRows.get(0).getSubTotal());
}
Aggregations