Search in sources :

Example 1 with MaybeConfiguration

use of alfio.manager.system.ConfigurationManager.MaybeConfiguration in project alf.io by alfio-event.

the class TicketReservationManagerTest method doNotSendReminderIfPreviousNotifications.

@Test
void doNotSendReminderIfPreviousNotifications() {
    initReminder();
    when(event.getId()).thenReturn(EVENT_ID);
    when(configurationManager.getFor(eq(ASSIGNMENT_REMINDER_START), any())).thenReturn(new MaybeConfiguration(ASSIGNMENT_REMINDER_START));
    // when(configurationManager.getStringConfigValue(any())).thenReturn(Optional.empty());
    when(configurationManager.getFor(eq(OPTIONAL_DATA_REMINDER_ENABLED), any())).thenReturn(MaybeConfigurationBuilder.existing(OPTIONAL_DATA_REMINDER_ENABLED, "true"));
    when(ticketReservation.latestNotificationTimestamp(any())).thenReturn(Optional.of(ZonedDateTime.now(ClockProvider.clock()).minusDays(10)));
    String RESERVATION_ID = "abcd";
    when(ticketReservation.getId()).thenReturn(RESERVATION_ID);
    when(ticket.getTicketsReservationId()).thenReturn(RESERVATION_ID);
    int ticketId = 2;
    when(ticket.getId()).thenReturn(ticketId);
    when(ticketRepository.findAllAssignedButNotYetNotifiedForUpdate(EVENT_ID)).thenReturn(singletonList(ticket));
    when(ticketReservationRepository.findReservationByIdForUpdate(eq(RESERVATION_ID))).thenReturn(ticketReservation);
    when(eventRepository.findByReservationId(RESERVATION_ID)).thenReturn(event);
    when(event.getZoneId()).thenReturn(ClockProvider.clock().getZone());
    when(event.getBegin()).thenReturn(ZonedDateTime.now(ClockProvider.clock()).plusDays(1));
    when(eventRepository.findAll()).thenReturn(singletonList(event));
    when(ticketRepository.flagTicketAsReminderSent(ticketId)).thenReturn(1);
    trm.sendReminderForOptionalData();
    verify(notificationManager, never()).sendSimpleEmail(eq(event), anyString(), anyString(), anyString(), any(TemplateGenerator.class));
}
Also used : TemplateGenerator(alfio.manager.support.TemplateGenerator) MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with MaybeConfiguration

use of alfio.manager.system.ConfigurationManager.MaybeConfiguration in project alf.io by alfio-event.

the class TicketReservationManagerTest method doNotSendReminderTooEarly.

@Test
void doNotSendReminderTooEarly() {
    TicketReservation reservation = mock(TicketReservation.class);
    when(configurationManager.getFor(eq(ASSIGNMENT_REMINDER_START), any())).thenReturn(new MaybeConfiguration(ASSIGNMENT_REMINDER_START));
    // when(configurationManager.getStringConfigValue(any())).thenReturn(Optional.empty());
    when(reservation.latestNotificationTimestamp(any())).thenReturn(Optional.empty());
    when(reservation.getId()).thenReturn("abcd");
    when(ticketReservationRepository.findReservationById(eq("abcd"))).thenReturn(reservation);
    when(eventRepository.findByReservationId("abcd")).thenReturn(event);
    when(event.getZoneId()).thenReturn(ZoneId.of("UTC-8"));
    when(event.getBegin()).thenReturn(ZonedDateTime.now(ZoneId.of("UTC-8")).plusMonths(3).plusDays(1));
    when(eventRepository.findAll()).thenReturn(singletonList(event));
    when(ticketRepository.findAllReservationsConfirmedButNotAssignedForUpdate(anyInt())).thenReturn(singleton("abcd"));
    List<Event> events = trm.getNotifiableEventsStream().collect(Collectors.toList());
    Assertions.assertEquals(0, events.size());
    verify(notificationManager, never()).sendSimpleEmail(eq(event), anyString(), anyString(), anyString(), any(TemplateGenerator.class));
}
Also used : TemplateGenerator(alfio.manager.support.TemplateGenerator) MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration) Test(org.junit.jupiter.api.Test)

Example 3 with MaybeConfiguration

use of alfio.manager.system.ConfigurationManager.MaybeConfiguration in project alf.io by alfio-event.

the class TicketReservationManagerTest method confirmPaidReservationButDoNotSendEmail.

@Test
void confirmPaidReservationButDoNotSendEmail() {
    when(ticketReservationRepository.findOptionalStatusAndValidationById(eq(RESERVATION_ID))).thenReturn(Optional.of(new TicketReservationStatusAndValidation(PENDING, true)));
    when(configurationManager.getFor(eq(ENABLE_TICKET_TRANSFER), any())).thenReturn(new MaybeConfiguration(ENABLE_TICKET_TRANSFER));
    when(configurationManager.getFor(eq(SEND_TICKETS_AUTOMATICALLY), any())).thenReturn(new MaybeConfiguration(SEND_TICKETS_AUTOMATICALLY, new ConfigurationKeyValuePathLevel(null, "false", null)));
    when(configurationManager.getFor(eq(BANKING_KEY), any())).thenReturn(BANKING_INFO);
    mockBillingDocument();
    testPaidReservation(true, true);
    verify(notificationManager, never()).sendTicketByEmail(any(), any(), any(), any(), any(), any(), any());
}
Also used : ConfigurationKeyValuePathLevel(alfio.model.system.ConfigurationKeyValuePathLevel) MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with MaybeConfiguration

use of alfio.manager.system.ConfigurationManager.MaybeConfiguration in project alf.io by alfio-event.

the class TicketReservationManagerTest method considerZoneIdWhileChecking.

@Test
void considerZoneIdWhileChecking() {
    TicketReservation reservation = mock(TicketReservation.class);
    when(configurationManager.getFor(eq(ASSIGNMENT_REMINDER_START), any())).thenReturn(new MaybeConfiguration(ASSIGNMENT_REMINDER_START));
    when(configurationManager.getFor(eq(ASSIGNMENT_REMINDER_INTERVAL), any())).thenReturn(new MaybeConfiguration(ASSIGNMENT_REMINDER_INTERVAL));
    // when(configurationManager.getStringConfigValue(any())).thenReturn(Optional.empty());
    when(reservation.latestNotificationTimestamp(any())).thenReturn(Optional.empty());
    when(reservation.getId()).thenReturn("abcd");
    when(reservation.getUserLanguage()).thenReturn("en");
    when(reservation.getValidity()).thenReturn(new Date(Instant.now(ClockProvider.clock()).getEpochSecond()));
    when(ticketReservationRepository.findReservationById(eq("abcd"))).thenReturn(reservation);
    when(ticketReservationRepository.findOptionalReservationById(eq("abcd"))).thenReturn(Optional.of(reservation));
    when(configurationManager.getFor(eq(BANKING_KEY), any())).thenReturn(BANKING_INFO);
    when(eventRepository.findByReservationId("abcd")).thenReturn(event);
    var zoneClock = Clock.offset(ClockProvider.clock(), Duration.ofHours(4).negated());
    when(event.getZoneId()).thenReturn(zoneClock.getZone());
    when(event.getBegin()).thenReturn(ZonedDateTime.now(zoneClock.getZone()).plusDays(1));
    when(eventRepository.findAll()).thenReturn(singletonList(event));
    when(ticketRepository.findAllReservationsConfirmedButNotAssignedForUpdate(anyInt())).thenReturn(singleton("abcd"));
    when(reservation.getEmail()).thenReturn("ciccio");
    trm.sendReminderForTicketAssignment();
    verify(notificationManager, times(1)).sendSimpleEmail(eq(event), eq("abcd"), anyString(), anyString(), any(TemplateGenerator.class));
}
Also used : TemplateGenerator(alfio.manager.support.TemplateGenerator) MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration) Test(org.junit.jupiter.api.Test)

Example 5 with MaybeConfiguration

use of alfio.manager.system.ConfigurationManager.MaybeConfiguration in project alf.io by alfio-event.

the class TicketReservationManagerTest method handleOnSitePaymentMethod.

@Test
void handleOnSitePaymentMethod() {
    when(ticketReservationRepository.findOptionalStatusAndValidationById(eq(RESERVATION_ID))).thenReturn(Optional.of(new TicketReservationStatusAndValidation(PENDING, true)));
    initConfirmReservation();
    when(ticketRepository.updateTicketsStatusWithReservationId(eq(RESERVATION_ID), eq(TicketStatus.TO_BE_PAID.toString()))).thenReturn(1);
    when(ticketReservationRepository.updateTicketReservation(eq(RESERVATION_ID), eq(COMPLETE.toString()), anyString(), anyString(), isNull(), isNull(), anyString(), anyString(), any(ZonedDateTime.class), eq(PaymentProxy.ON_SITE.toString()), isNull())).thenReturn(1);
    when(ticketReservationRepository.findOptionalReservationById(eq(RESERVATION_ID))).thenReturn(Optional.of(ticketReservation));
    when(configurationManager.getFor(eq(ENABLE_TICKET_TRANSFER), any())).thenReturn(new MaybeConfiguration(ENABLE_TICKET_TRANSFER));
    when(configurationManager.getFor(eq(BANKING_KEY), any())).thenReturn(BANKING_INFO);
    OnSiteManager onSiteManager = mock(OnSiteManager.class);
    when(onSiteManager.accept(eq(PaymentMethod.ON_SITE), any(), any())).thenReturn(true);
    when(paymentManager.streamActiveProvidersByProxy(eq(PaymentProxy.ON_SITE), any())).thenReturn(Stream.of(onSiteManager));
    when(ticketReservation.getPromoCodeDiscountId()).thenReturn(null);
    when(onSiteManager.getTokenAndPay(any())).thenReturn(PaymentResult.successful(TicketReservationManager.NOT_YET_PAID_TRANSACTION_ID));
    PaymentSpecification spec = new PaymentSpecification(RESERVATION_ID, new StripeCreditCardToken(GATEWAY_TOKEN), 100, event, "test@email", new CustomerName("Full Name", null, null, event.mustUseFirstAndLastName()), "", null, Locale.ENGLISH, true, false, null, "IT", "123456", PriceContainer.VatStatus.INCLUDED, true, false);
    when(ticketReservationRepository.updateTicketReservation(eq(RESERVATION_ID), anyString(), anyString(), anyString(), isNull(), isNull(), eq(Locale.ENGLISH.getLanguage()), isNull(), any(), any(), isNull())).thenReturn(1);
    PaymentResult result = trm.performPayment(spec, new TotalPrice(100, 0, 0, 0, "CHF"), PaymentProxy.ON_SITE, PaymentMethod.ON_SITE, null);
    Assertions.assertTrue(result.isSuccessful());
    Assertions.assertEquals(Optional.of(TicketReservationManager.NOT_YET_PAID_TRANSACTION_ID), result.getGatewayId());
    verify(ticketReservationRepository).updateTicketReservation(eq(RESERVATION_ID), eq(TicketReservationStatus.COMPLETE.toString()), anyString(), anyString(), isNull(), isNull(), anyString(), anyString(), any(), eq(PaymentProxy.ON_SITE.toString()), isNull());
    verify(ticketReservationRepository).findReservationByIdForUpdate(eq(RESERVATION_ID));
    verify(ticketRepository).updateTicketsStatusWithReservationId(eq(RESERVATION_ID), eq(TicketStatus.TO_BE_PAID.toString()));
    verify(specialPriceRepository).updateStatusForReservation(eq(singletonList(RESERVATION_ID)), eq(SpecialPrice.Status.TAKEN.toString()));
    verify(waitingQueueManager).fireReservationConfirmed(eq(RESERVATION_ID));
    verify(ticketReservationRepository, atLeastOnce()).findReservationById(RESERVATION_ID);
    verify(billingDocumentManager).generateInvoiceNumber(eq(spec), any());
    verify(ticketReservationRepository).updateBillingData(eq(PriceContainer.VatStatus.INCLUDED), eq(100), eq(100), eq(0), eq(0), eq(EVENT_CURRENCY), eq("123456"), eq("IT"), eq(true), eq(RESERVATION_ID));
    verify(ticketRepository, atLeastOnce()).findTicketsInReservation(anyString());
}
Also used : PaymentResult(alfio.manager.support.PaymentResult) StripeCreditCardToken(alfio.model.transaction.token.StripeCreditCardToken) MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

MaybeConfiguration (alfio.manager.system.ConfigurationManager.MaybeConfiguration)25 Test (org.junit.jupiter.api.Test)21 TemplateGenerator (alfio.manager.support.TemplateGenerator)8 ConfigurationKeyValuePathLevel (alfio.model.system.ConfigurationKeyValuePathLevel)7 PaymentResult (alfio.manager.support.PaymentResult)2 ConfigurationManager (alfio.manager.system.ConfigurationManager)2 StripeCreditCardToken (alfio.model.transaction.token.StripeCreditCardToken)2 Organization (alfio.model.user.Organization)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 PaymentMethodDTO (alfio.manager.PaymentManager.PaymentMethodDTO)1 MessageSourceManager (alfio.manager.i18n.MessageSourceManager)1 EventAndOrganizationId (alfio.model.EventAndOrganizationId)1 TicketReservationWithOptionalCodeModification (alfio.model.modification.TicketReservationWithOptionalCodeModification)1 OrganizationRepository (alfio.repository.user.OrganizationRepository)1 UserRepository (alfio.repository.user.UserRepository)1 MessageSource (org.springframework.context.MessageSource)1 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)1 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)1