Skip to content

Commit

Permalink
fix typo, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed Jan 20, 2020
1 parent d33063a commit 8ff4cfd
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/alfio/manager/ExtensionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
71 changes: 71 additions & 0 deletions src/test/java/alfio/manager/ExtensionManagerTest.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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());
}
}

0 comments on commit 8ff4cfd

Please sign in to comment.