Search in sources :

Example 11 with Event

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

the class CreateTicketViewModel method createTicket.

public void createTicket() {
    if (!verify())
        return;
    long eventId = ContextManager.getSelectedEvent().getId();
    Event event = new Event();
    event.setId(eventId);
    ticket.setEvent(event);
    compositeDisposable.add(ticketRepository.createTicket(ticket).doOnSubscribe(disposable -> progress.setValue(true)).doFinally(() -> progress.setValue(false)).subscribe(createdTicket -> {
        success.setValue("Ticket Created");
        dismiss.call();
    }, throwable -> error.setValue(ErrorUtils.getMessage(throwable).toString())));
}
Also used : DateUtils(com.eventyay.organizer.utils.DateUtils) LiveData(androidx.lifecycle.LiveData) SingleEventLiveData(com.eventyay.organizer.common.livedata.SingleEventLiveData) Event(com.eventyay.organizer.data.event.Event) ViewModel(androidx.lifecycle.ViewModel) ContextManager(com.eventyay.organizer.common.ContextManager) TicketRepository(com.eventyay.organizer.data.ticket.TicketRepository) ZonedDateTime(org.threeten.bp.ZonedDateTime) Inject(javax.inject.Inject) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) LocalDateTime(org.threeten.bp.LocalDateTime) ErrorUtils(com.eventyay.organizer.utils.ErrorUtils) Ticket(com.eventyay.organizer.data.ticket.Ticket) DateTimeParseException(org.threeten.bp.format.DateTimeParseException) Event(com.eventyay.organizer.data.event.Event)

Example 12 with Event

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

the class EventRepositoryTest method shouldFetchEventOnForceReload.

@Test
public void shouldFetchEventOnForceReload() {
    long id = 45L;
    Event event = new Event();
    when(repository.save(Event.class, event)).thenReturn(Completable.complete());
    when(repository.getItems(eq(Event.class), refEq(Event_Table.id.eq(id)))).thenReturn(Observable.just(event));
    when(repository.isConnected()).thenReturn(true);
    when(eventApi.getEvent(id)).thenReturn(Observable.just(event));
    // Force reload ensures no use of cache
    Observable<Event> userObservable = eventRepository.getEvent(id, true);
    userObservable.test().assertValue(event);
    // Verify loads from network
    verify(eventApi).getEvent(id);
}
Also used : Event(com.eventyay.organizer.data.event.Event) Test(org.junit.Test)

Example 13 with Event

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

the class DateServiceTest method testClashPast.

@Test
public void testClashPast() {
    Event pastLatest = new Event();
    String min = DateUtils.formatDateToIso(LocalDateTime.MIN);
    String minPlus5 = DateUtils.formatDateToIso(LocalDateTime.MIN.plusDays(5));
    pastLatest.setStartsAt(min);
    pastLatest.setEndsAt(minPlus5);
    assertEquals(1, DateService.compareEventDates(PAST, pastLatest));
}
Also used : Event(com.eventyay.organizer.data.event.Event) Test(org.junit.Test)

Example 14 with Event

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

the class DateServiceTest method testClashLive.

@Test
public void testClashLive() {
    Event liveLatest = new Event();
    String nowMinus5 = DateUtils.formatDateToIso(LocalDateTime.now().minusDays(5));
    String nowPlus5 = DateUtils.formatDateToIso(LocalDateTime.now().plusDays(5));
    liveLatest.setStartsAt(nowMinus5);
    liveLatest.setEndsAt(nowPlus5);
    assertEquals(1, DateService.compareEventDates(LIVE, liveLatest));
}
Also used : Event(com.eventyay.organizer.data.event.Event) Test(org.junit.Test)

Example 15 with Event

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

the class DateServiceTest method testClashUpcoming.

@Test
public void testClashUpcoming() {
    Event upcomingEarliest = new Event();
    String max = DateUtils.formatDateToIso(LocalDateTime.MAX);
    String maxMinus5 = DateUtils.formatDateToIso(LocalDateTime.MAX.minusDays(5));
    upcomingEarliest.setStartsAt(maxMinus5);
    upcomingEarliest.setEndsAt(max);
    assertEquals(1, DateService.compareEventDates(UPCOMING, upcomingEarliest));
}
Also used : Event(com.eventyay.organizer.data.event.Event) Test(org.junit.Test)

Aggregations

Event (com.eventyay.organizer.data.event.Event)36 LiveData (androidx.lifecycle.LiveData)15 ViewModel (androidx.lifecycle.ViewModel)15 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)15 Inject (javax.inject.Inject)15 ErrorUtils (com.eventyay.organizer.utils.ErrorUtils)14 Test (org.junit.Test)14 SingleEventLiveData (com.eventyay.organizer.common.livedata.SingleEventLiveData)13 ContextManager (com.eventyay.organizer.common.ContextManager)10 StringUtils (com.eventyay.organizer.utils.StringUtils)8 DateUtils (com.eventyay.organizer.utils.DateUtils)5 LocalDateTime (org.threeten.bp.LocalDateTime)5 ZonedDateTime (org.threeten.bp.ZonedDateTime)5 DateTimeParseException (org.threeten.bp.format.DateTimeParseException)5 VisibleForTesting (androidx.annotation.VisibleForTesting)4 MutableLiveData (androidx.lifecycle.MutableLiveData)4 Track (com.eventyay.organizer.data.tracks.Track)4 InOrder (org.mockito.InOrder)4 Logger (com.eventyay.organizer.common.rx.Logger)3 Ticket (com.eventyay.organizer.data.ticket.Ticket)3