Search in sources :

Example 1 with AVAILABLE_SEATS

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());
}
Also used : alfio.repository(alfio.repository) BeforeEach(org.junit.jupiter.api.BeforeEach) ChronoField(java.time.temporal.ChronoField) java.util(java.util) PaymentProxy(alfio.model.transaction.PaymentProxy) ZonedDateTime(java.time.ZonedDateTime) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) PaymentResult(alfio.manager.support.PaymentResult) AlfioMetadata(alfio.model.metadata.AlfioMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) Supplier(java.util.function.Supplier) BigDecimal(java.math.BigDecimal) AVAILABLE_SEATS(alfio.test.util.IntegrationTestUtil.AVAILABLE_SEATS) Pair(org.apache.commons.lang3.tuple.Pair) DEFERRED_BANK_TRANSFER_ENABLED(alfio.model.system.ConfigurationKeys.DEFERRED_BANK_TRANSFER_ENABLED) LocalTime(java.time.LocalTime) Triple(org.apache.commons.lang3.tuple.Triple) BaseIntegrationTest(alfio.util.BaseIntegrationTest) OrganizationRepository(alfio.repository.user.OrganizationRepository) PaymentMethod(alfio.model.transaction.PaymentMethod) IntegrationTestUtil.initEvent(alfio.test.util.IntegrationTestUtil.initEvent) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) Collectors(java.util.stream.Collectors) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) DateUtils(org.apache.commons.lang3.time.DateUtils) Test(org.junit.jupiter.api.Test) Initializer(alfio.config.Initializer) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) AUTOMATIC_REMOVAL_EXPIRED_OFFLINE_PAYMENT(alfio.model.system.ConfigurationKeys.AUTOMATIC_REMOVAL_EXPIRED_OFFLINE_PAYMENT) alfio.model(alfio.model) PaymentSpecification(alfio.manager.payment.PaymentSpecification) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) Assertions(org.junit.jupiter.api.Assertions) Clock(java.time.Clock) DataSourceConfiguration(alfio.config.DataSourceConfiguration) ClockProvider(alfio.util.ClockProvider) TestConfiguration(alfio.TestConfiguration) alfio.model.modification(alfio.model.modification) Transactional(org.springframework.transaction.annotation.Transactional) PaymentResult(alfio.manager.support.PaymentResult) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) IntegrationTestUtil.initEvent(alfio.test.util.IntegrationTestUtil.initEvent) PaymentSpecification(alfio.manager.payment.PaymentSpecification) BaseIntegrationTest(alfio.util.BaseIntegrationTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with AVAILABLE_SEATS

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));
}
Also used : alfio.repository(alfio.repository) BeforeEach(org.junit.jupiter.api.BeforeEach) ChronoField(java.time.temporal.ChronoField) java.util(java.util) PaymentProxy(alfio.model.transaction.PaymentProxy) ZonedDateTime(java.time.ZonedDateTime) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) PaymentResult(alfio.manager.support.PaymentResult) AlfioMetadata(alfio.model.metadata.AlfioMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) Supplier(java.util.function.Supplier) BigDecimal(java.math.BigDecimal) AVAILABLE_SEATS(alfio.test.util.IntegrationTestUtil.AVAILABLE_SEATS) Pair(org.apache.commons.lang3.tuple.Pair) DEFERRED_BANK_TRANSFER_ENABLED(alfio.model.system.ConfigurationKeys.DEFERRED_BANK_TRANSFER_ENABLED) LocalTime(java.time.LocalTime) Triple(org.apache.commons.lang3.tuple.Triple) BaseIntegrationTest(alfio.util.BaseIntegrationTest) OrganizationRepository(alfio.repository.user.OrganizationRepository) PaymentMethod(alfio.model.transaction.PaymentMethod) IntegrationTestUtil.initEvent(alfio.test.util.IntegrationTestUtil.initEvent) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) Collectors(java.util.stream.Collectors) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) DateUtils(org.apache.commons.lang3.time.DateUtils) Test(org.junit.jupiter.api.Test) Initializer(alfio.config.Initializer) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) AUTOMATIC_REMOVAL_EXPIRED_OFFLINE_PAYMENT(alfio.model.system.ConfigurationKeys.AUTOMATIC_REMOVAL_EXPIRED_OFFLINE_PAYMENT) alfio.model(alfio.model) PaymentSpecification(alfio.manager.payment.PaymentSpecification) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) Assertions(org.junit.jupiter.api.Assertions) Clock(java.time.Clock) DataSourceConfiguration(alfio.config.DataSourceConfiguration) ClockProvider(alfio.util.ClockProvider) TestConfiguration(alfio.TestConfiguration) alfio.model.modification(alfio.model.modification) Transactional(org.springframework.transaction.annotation.Transactional) IntegrationTestUtil.initEvent(alfio.test.util.IntegrationTestUtil.initEvent) LocalDate(java.time.LocalDate) BaseIntegrationTest(alfio.util.BaseIntegrationTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with AVAILABLE_SEATS

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());
}
Also used : alfio.repository(alfio.repository) BeforeEach(org.junit.jupiter.api.BeforeEach) ChronoField(java.time.temporal.ChronoField) java.util(java.util) PaymentProxy(alfio.model.transaction.PaymentProxy) ZonedDateTime(java.time.ZonedDateTime) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) PaymentResult(alfio.manager.support.PaymentResult) AlfioMetadata(alfio.model.metadata.AlfioMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) Supplier(java.util.function.Supplier) BigDecimal(java.math.BigDecimal) AVAILABLE_SEATS(alfio.test.util.IntegrationTestUtil.AVAILABLE_SEATS) Pair(org.apache.commons.lang3.tuple.Pair) DEFERRED_BANK_TRANSFER_ENABLED(alfio.model.system.ConfigurationKeys.DEFERRED_BANK_TRANSFER_ENABLED) LocalTime(java.time.LocalTime) Triple(org.apache.commons.lang3.tuple.Triple) BaseIntegrationTest(alfio.util.BaseIntegrationTest) OrganizationRepository(alfio.repository.user.OrganizationRepository) PaymentMethod(alfio.model.transaction.PaymentMethod) IntegrationTestUtil.initEvent(alfio.test.util.IntegrationTestUtil.initEvent) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) Collectors(java.util.stream.Collectors) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) DateUtils(org.apache.commons.lang3.time.DateUtils) Test(org.junit.jupiter.api.Test) Initializer(alfio.config.Initializer) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) AUTOMATIC_REMOVAL_EXPIRED_OFFLINE_PAYMENT(alfio.model.system.ConfigurationKeys.AUTOMATIC_REMOVAL_EXPIRED_OFFLINE_PAYMENT) alfio.model(alfio.model) PaymentSpecification(alfio.manager.payment.PaymentSpecification) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) Assertions(org.junit.jupiter.api.Assertions) Clock(java.time.Clock) DataSourceConfiguration(alfio.config.DataSourceConfiguration) ClockProvider(alfio.util.ClockProvider) TestConfiguration(alfio.TestConfiguration) alfio.model.modification(alfio.model.modification) Transactional(org.springframework.transaction.annotation.Transactional) LocalDate(java.time.LocalDate) IntegrationTestUtil.initEvent(alfio.test.util.IntegrationTestUtil.initEvent) BaseIntegrationTest(alfio.util.BaseIntegrationTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TestConfiguration (alfio.TestConfiguration)3 DataSourceConfiguration (alfio.config.DataSourceConfiguration)3 Initializer (alfio.config.Initializer)3 PaymentSpecification (alfio.manager.payment.PaymentSpecification)3 PaymentResult (alfio.manager.support.PaymentResult)3 UserManager (alfio.manager.user.UserManager)3 alfio.model (alfio.model)3 AlfioMetadata (alfio.model.metadata.AlfioMetadata)3 alfio.model.modification (alfio.model.modification)3 AUTOMATIC_REMOVAL_EXPIRED_OFFLINE_PAYMENT (alfio.model.system.ConfigurationKeys.AUTOMATIC_REMOVAL_EXPIRED_OFFLINE_PAYMENT)3 DEFERRED_BANK_TRANSFER_ENABLED (alfio.model.system.ConfigurationKeys.DEFERRED_BANK_TRANSFER_ENABLED)3 PaymentMethod (alfio.model.transaction.PaymentMethod)3 PaymentProxy (alfio.model.transaction.PaymentProxy)3 alfio.repository (alfio.repository)3 ConfigurationRepository (alfio.repository.system.ConfigurationRepository)3 OrganizationRepository (alfio.repository.user.OrganizationRepository)3 IntegrationTestUtil (alfio.test.util.IntegrationTestUtil)3 AVAILABLE_SEATS (alfio.test.util.IntegrationTestUtil.AVAILABLE_SEATS)3 IntegrationTestUtil.initEvent (alfio.test.util.IntegrationTestUtil.initEvent)3 BaseIntegrationTest (alfio.util.BaseIntegrationTest)3