Search in sources :

Example 11 with Ticket

use of com.eventyay.organizer.data.ticket.Ticket in project open-event-orga-app by fossasia.

the class TicketRepositoryTest method shouldSetEventOnCreatedTicket.

@Test
public void shouldSetEventOnCreatedTicket() {
    Ticket created = mock(Ticket.class);
    when(repository.isConnected()).thenReturn(true);
    when(ticketApi.postTicket(TICKET)).thenReturn(Observable.just(created));
    when(repository.save(eq(Ticket.class), eq(created))).thenReturn(Completable.complete());
    ticketRepository.createTicket(TICKET).subscribe();
    verify(created).setEvent(EVENT);
}
Also used : Ticket(com.eventyay.organizer.data.ticket.Ticket) Test(org.junit.Test)

Example 12 with Ticket

use of com.eventyay.organizer.data.ticket.Ticket in project open-event-orga-app by fossasia.

the class TicketCreateViewModelTest method shouldShowSuccessOnCreated.

@Test
public void shouldShowSuccessOnCreated() {
    String successString = "Ticket Created";
    Ticket ticket = createTicketViewModel.getTicket();
    when(ticketRepository.createTicket(ticket)).thenReturn(Observable.just(ticket));
    ContextManager.setSelectedEvent(event);
    String isoDateNow = DateUtils.formatDateToIso(LocalDateTime.now());
    String isoDateThen = DateUtils.formatDateToIso(LocalDateTime.MAX);
    ticket.setSalesStartsAt(isoDateNow);
    ticket.setSalesEndsAt(isoDateThen);
    InOrder inOrder = inOrder(progress, dismiss, success);
    createTicketViewModel.getProgress().observeForever(progress);
    createTicketViewModel.getDismiss().observeForever(dismiss);
    createTicketViewModel.getSuccess().observeForever(success);
    createTicketViewModel.createTicket();
    inOrder.verify(progress).onChanged(true);
    inOrder.verify(success).onChanged(successString);
    inOrder.verify(dismiss).onChanged(null);
    inOrder.verify(progress).onChanged(false);
    ContextManager.setSelectedEvent(null);
}
Also used : Ticket(com.eventyay.organizer.data.ticket.Ticket) InOrder(org.mockito.InOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 13 with Ticket

use of com.eventyay.organizer.data.ticket.Ticket in project open-event-orga-app by fossasia.

the class TicketCreateViewModelTest method shouldAcceptCorrectSaleDates.

@Test
public void shouldAcceptCorrectSaleDates() {
    Ticket ticket = createTicketViewModel.getTicket();
    ContextManager.setSelectedEvent(event);
    when(ticketRepository.createTicket(ticket)).thenReturn(Observable.empty());
    String isoDateNow = DateUtils.formatDateToIso(LocalDateTime.now());
    String isoDateThen = DateUtils.formatDateToIso(LocalDateTime.MAX);
    ticket.setSalesStartsAt(isoDateNow);
    ticket.setSalesEndsAt(isoDateThen);
    InOrder inOrder = inOrder(error);
    createTicketViewModel.getError().observeForever(error);
    createTicketViewModel.createTicket();
    inOrder.verify(error, never()).onChanged(anyString());
    verify(ticketRepository).createTicket(ticket);
    ContextManager.setSelectedEvent(null);
}
Also used : Ticket(com.eventyay.organizer.data.ticket.Ticket) InOrder(org.mockito.InOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 14 with Ticket

use of com.eventyay.organizer.data.ticket.Ticket in project open-event-orga-app by fossasia.

the class TicketTest method setUp.

@Override
public void setUp() {
    RxJavaPlugins.setIoSchedulerHandler(scheduler -> Schedulers.trampoline());
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> Schedulers.trampoline());
    Event event = new Event();
    event.setId(12L);
    Ticket ticket1 = Ticket.builder().id(1L).quantity(120L).type(FREE).event(event).build();
    Ticket ticket2 = Ticket.builder().id(2L).quantity(20L).type(PAID).price(25.99f).event(event).build();
    Ticket ticket3 = Ticket.builder().id(3L).quantity(30L).type(DONATION).event(event).build();
    Ticket ticket4 = Ticket.builder().id(4L).quantity(10L).type(DONATION).event(event).build();
    Ticket ticket5 = Ticket.builder().id(5L).quantity(50L).type(PAID).price(99.99f).event(event).build();
    Attendee attendee = Attendee.builder().id(1L).ticket(ticket1).event(event).build();
    Attendee attendee2 = Attendee.builder().id(2L).ticket(ticket1).event(event).build();
    Attendee attendee3 = Attendee.builder().id(3L).ticket(ticket1).event(event).build();
    Attendee attendee4 = Attendee.builder().id(4L).ticket(ticket2).event(event).build();
    Attendee attendee5 = Attendee.builder().id(5L).ticket(ticket2).event(event).build();
    Attendee attendee6 = Attendee.builder().id(6L).ticket(ticket4).event(event).build();
    Attendee attendee7 = Attendee.builder().id(7L).ticket(ticket5).event(event).build();
    event.setTickets(Arrays.asList(ticket1, ticket2, ticket3, ticket4, ticket5));
    DbFlowDatabaseRepository databaseRepository = new DbFlowDatabaseRepository();
    databaseRepository.save(Event.class, event).subscribe();
    databaseRepository.saveList(Ticket.class, Arrays.asList(ticket1, ticket2, ticket3, ticket4, ticket5)).subscribe();
    databaseRepository.saveList(Attendee.class, Arrays.asList(attendee, attendee2, attendee3, attendee4, attendee5, attendee6, attendee7)).subscribe();
    Repository repository = new Repository(null, null, null, databaseRepository);
    ticketRepository = new TicketRepositoryImpl(null, repository);
}
Also used : Ticket(com.eventyay.organizer.data.ticket.Ticket) Repository(com.eventyay.organizer.data.Repository) DbFlowDatabaseRepository(com.eventyay.organizer.data.db.DbFlowDatabaseRepository) DbFlowDatabaseRepository(com.eventyay.organizer.data.db.DbFlowDatabaseRepository) Event(com.eventyay.organizer.data.event.Event) TicketRepositoryImpl(com.eventyay.organizer.data.ticket.TicketRepositoryImpl) Attendee(com.eventyay.organizer.data.attendee.Attendee)

Aggregations

Ticket (com.eventyay.organizer.data.ticket.Ticket)14 Test (org.junit.Test)8 InOrder (org.mockito.InOrder)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Event (com.eventyay.organizer.data.event.Event)2 PrintManager (android.print.PrintManager)1 LiveData (androidx.lifecycle.LiveData)1 ViewModel (androidx.lifecycle.ViewModel)1 ContextManager (com.eventyay.organizer.common.ContextManager)1 SingleEventLiveData (com.eventyay.organizer.common.livedata.SingleEventLiveData)1 Repository (com.eventyay.organizer.data.Repository)1 Attendee (com.eventyay.organizer.data.attendee.Attendee)1 DbFlowDatabaseRepository (com.eventyay.organizer.data.db.DbFlowDatabaseRepository)1 TicketRepository (com.eventyay.organizer.data.ticket.TicketRepository)1 TicketRepositoryImpl (com.eventyay.organizer.data.ticket.TicketRepositoryImpl)1 DateUtils (com.eventyay.organizer.utils.DateUtils)1 ErrorUtils (com.eventyay.organizer.utils.ErrorUtils)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 ArrayList (java.util.ArrayList)1 Inject (javax.inject.Inject)1