diff --git a/src/main/java/alfio/manager/ExtensionManager.java b/src/main/java/alfio/manager/ExtensionManager.java index e971c1fff3..6d9ca95726 100644 --- a/src/main/java/alfio/manager/ExtensionManager.java +++ b/src/main/java/alfio/manager/ExtensionManager.java @@ -111,7 +111,7 @@ void handleReservationConfirmation(TicketReservation reservation, BillingDetails } void handleTicketAssignment(Ticket ticket) { - if(ticket.getStatus() == Ticket.TicketStatus.ACQUIRED) { + if(!ticket.hasBeenSold()) { return; // ignore tickets if the reservation is not yet confirmed } int eventId = ticket.getEventId(); diff --git a/src/test/java/alfio/manager/ExtensionManagerTest.java b/src/test/java/alfio/manager/ExtensionManagerTest.java new file mode 100644 index 0000000000..c74e08e6df --- /dev/null +++ b/src/test/java/alfio/manager/ExtensionManagerTest.java @@ -0,0 +1,71 @@ +/** + * This file is part of alf.io. + * + * alf.io is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * alf.io is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with alf.io. If not, see . + */ +package alfio.manager; + +import alfio.extension.ExtensionService; +import alfio.manager.system.ConfigurationManager; +import alfio.model.Event; +import alfio.model.Ticket; +import alfio.repository.EventRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import static alfio.manager.ExtensionManager.ExtensionEvent.TICKET_ASSIGNED; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +class ExtensionManagerTest { + + private ExtensionManager extensionManager; + private EventRepository eventRepository; + private ExtensionService extensionService; + private Ticket ticket; + + @BeforeEach + void setUp() { + ticket = mock(Ticket.class); + when(ticket.getStatus()).thenReturn(Ticket.TicketStatus.ACQUIRED); + when(ticket.getEventId()).thenReturn(1); + var event = mock(Event.class); + when(event.getId()).thenReturn(1); + when(event.getShortName()).thenReturn("blabla"); + eventRepository = mock(EventRepository.class); + when(eventRepository.findOrganizationIdByEventId(1)).thenReturn(1); + when(eventRepository.findById(1)).thenReturn(event); + extensionService = mock(ExtensionService.class); + extensionManager = new ExtensionManager(extensionService, eventRepository, null, null, mock(ConfigurationManager.class), null); + } + + @Test + void handleTicketAssignmentTicketConfirmed() { + when(ticket.hasBeenSold()).thenReturn(true); + extensionManager.handleTicketAssignment(ticket); + verify(eventRepository).findOrganizationIdByEventId(eq(1)); + verify(eventRepository).findById(eq(1)); + verify(extensionService).executeScriptAsync(eq(TICKET_ASSIGNED.name()), anyString(), any()); + } + + @Test + void handleTicketAssignmentTicketNotConfirmed() { + when(ticket.hasBeenSold()).thenReturn(false); + extensionManager.handleTicketAssignment(ticket); + verify(eventRepository, never()).findOrganizationIdByEventId(eq(1)); + verify(eventRepository, never()).findById(eq(1)); + verify(extensionService, never()).executeScriptAsync(eq(TICKET_ASSIGNED.name()), anyString(), any()); + } +} \ No newline at end of file