Search in sources :

Example 1 with PollModification

use of alfio.model.modification.PollModification in project alf.io by alfio-event.

the class PollAdminApiControllerTest method allowPeopleToVote.

@Test
void allowPeopleToVote() {
    var options = List.of(new PollOptionModification(null, Map.of("en", "Homer J. Simpson"), null), new PollOptionModification(null, Map.of("en", "Bender B. Rodriguez"), Map.of()));
    // this must not have an impact
    var form = new PollModification(null, Map.of("en", "Best Employee of the Year"), null, null, options, true, Poll.PollStatus.OPEN);
    var eventName = event.getShortName();
    var createResponse = controller.createNewPoll(eventName, form);
    assertTrue(createResponse.getStatusCode().is2xxSuccessful());
    assertNotNull(createResponse.getBody());
    var pollId = createResponse.getBody();
    var reservationId = UUID.randomUUID().toString();
    ticketReservationRepository.createNewReservation(reservationId, ZonedDateTime.now(event.getZoneId()), DateUtils.addMinutes(new Date(), 1), null, "en", event.getId(), null, null, null, event.getOrganizationId(), null);
    var firstCategory = CollectionUtils.get(ticketCategoryRepository.findByEventIdAsMap(event.getId()), 0);
    int categoryId = firstCategory.getKey();
    var tickets = ticketRepository.findFreeByEventId(event.getId());
    var firstTicket = tickets.get(0);
    int ticketId = firstTicket.getId();
    ticketRepository.reserveTickets(reservationId, List.of(ticketId), firstCategory.getValue(), "en", event.getVatStatus(), i -> null);
    ticketReservationRepository.updateReservationStatus(reservationId, TicketReservation.TicketReservationStatus.COMPLETE.name());
    ticketRepository.updateTicketOwner(firstTicket.getUuid(), "test@test.ch", "First Last", "First", "Last");
    ticketRepository.updateTicketsStatusWithReservationId(reservationId, Ticket.TicketStatus.ACQUIRED.name());
    // find compatible tickets
    var res = controller.findAdditionalAttendees(event.getShortName(), pollId, "First");
    assertTrue(res.getStatusCode().is2xxSuccessful());
    assertTrue(CollectionUtils.isNotEmpty(res.getBody()));
    assertEquals(1, res.getBody().size());
    assertEquals(firstTicket.getId(), res.getBody().get(0).getId());
    // allow tickets to vote
    var poll = pollRepository.findSingleForEvent(event.getId(), pollId).orElseThrow();
    assertNotNull(poll);
    var participantForm = new PollAdminApiController.UpdateParticipantsForm(List.of(ticketId));
    var allowRes = controller.allowAttendees(event.getShortName(), pollId, participantForm);
    assertTrue(allowRes.getStatusCode().is2xxSuccessful());
    assertEquals(1, auditingRepository.countAuditsOfTypeForReservation(reservationId, Audit.EventType.TAG_TICKET));
    assertEquals(0, auditingRepository.countAuditsOfTypeForReservation(reservationId, Audit.EventType.UNTAG_TICKET));
    var participantRes = controller.getAllowedAttendees(eventName, pollId);
    assertTrue(participantRes.getStatusCode().is2xxSuccessful());
    assertTrue(CollectionUtils.isNotEmpty(participantRes.getBody()));
    assertEquals(1, participantRes.getBody().size());
    assertEquals(firstTicket.getId(), participantRes.getBody().get(0).getId());
    // now ticket should not be returned anymore
    res = controller.findAdditionalAttendees(event.getShortName(), pollId, "First");
    assertTrue(res.getStatusCode().is2xxSuccessful());
    assertTrue(CollectionUtils.isEmpty(res.getBody()));
    // get statistics
    var statsRes = controller.getStatisticsForEvent(event.getShortName(), pollId);
    assertTrue(statsRes.getStatusCode().is2xxSuccessful());
    assertNotNull(statsRes.getBody());
    assertTrue(CollectionUtils.isEmpty(statsRes.getBody().getOptionStatistics()));
    assertEquals("0", statsRes.getBody().getParticipationPercentage());
    // forbid access to attendee
    var forbidRes = controller.forbidAttendees(event.getShortName(), pollId, participantForm);
    assertTrue(forbidRes.getStatusCode().is2xxSuccessful());
    assertTrue(CollectionUtils.isEmpty(forbidRes.getBody()));
    assertEquals(1, auditingRepository.countAuditsOfTypeForReservation(reservationId, Audit.EventType.TAG_TICKET));
    assertEquals(1, auditingRepository.countAuditsOfTypeForReservation(reservationId, Audit.EventType.UNTAG_TICKET));
    // remove option
    var pollWithOptions = controller.getPollDetail(event.getShortName(), pollId).getBody();
    assertNotNull(pollWithOptions);
    var firstOptionId = pollWithOptions.getOptions().get(0).getId();
    var removeOptionResponse = controller.removeOption(event.getShortName(), pollId, firstOptionId);
    assertTrue(removeOptionResponse.getStatusCode().is2xxSuccessful());
    assertTrue(Objects.requireNonNull(removeOptionResponse.getBody()).getOptions().stream().noneMatch(po -> firstOptionId.equals(po.getId())));
    // delete poll
    var deletePollResponse = controller.deletePoll(eventName, pollId);
    assertTrue(deletePollResponse.getStatusCode().is2xxSuccessful());
    assertNotNull(deletePollResponse.getBody());
    assertTrue(deletePollResponse.getBody());
}
Also used : alfio.repository(alfio.repository) BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) ZonedDateTime(java.time.ZonedDateTime) AlfioMetadata(alfio.model.metadata.AlfioMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) CollectionUtils(org.apache.commons.collections4.CollectionUtils) DateTimeModification(alfio.model.modification.DateTimeModification) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair) ControllerConfiguration(alfio.controller.api.ControllerConfiguration) LocalTime(java.time.LocalTime) TestUtil.clockProvider(alfio.test.util.TestUtil.clockProvider) PollOptionModification(alfio.model.modification.PollOptionModification) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) PollModification(alfio.model.modification.PollModification) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) DateUtils(org.apache.commons.lang3.time.DateUtils) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) Initializer(alfio.config.Initializer) EventManager(alfio.manager.EventManager) Poll(alfio.model.poll.Poll) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) alfio.model(alfio.model) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) Assertions(org.junit.jupiter.api.Assertions) DataSourceConfiguration(alfio.config.DataSourceConfiguration) TestConfiguration(alfio.TestConfiguration) Transactional(org.springframework.transaction.annotation.Transactional) PollOptionModification(alfio.model.modification.PollOptionModification) PollModification(alfio.model.modification.PollModification) LocalDate(java.time.LocalDate) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with PollModification

use of alfio.model.modification.PollModification in project alf.io by alfio-event.

the class PollAdminApiControllerTest method createAndUpdatePoll.

@Test
void createAndUpdatePoll() {
    // create poll
    var options = List.of(new PollOptionModification(null, Map.of("en", "Homer J. Simpson"), null), new PollOptionModification(null, Map.of("en", "Bender B. Rodriguez"), Map.of()));
    // this must not have an impact
    var form = new PollModification(null, Map.of("en", "Best Employee of the Year"), null, null, options, false, Poll.PollStatus.OPEN);
    var eventName = event.getShortName();
    var createResponse = controller.createNewPoll(eventName, form);
    assertTrue(createResponse.getStatusCode().is2xxSuccessful());
    assertNotNull(createResponse.getBody());
    var pollId = createResponse.getBody();
    // retrieve poll and check
    var getResponse = controller.getPollDetail(eventName, pollId);
    assertTrue(getResponse.getStatusCode().is2xxSuccessful());
    assertNotNull(getResponse.getBody());
    var poll = getResponse.getBody();
    assertEquals(2, poll.getOptions().size());
    assertEquals("Homer J. Simpson", poll.getOptions().get(0).getTitle().get("en"));
    assertEquals(Poll.PollStatus.DRAFT, poll.getStatus());
    // update poll status
    var updateStatusResponse = controller.updateStatus(eventName, pollId, new PollAdminApiController.UpdatePollStatusForm(Poll.PollStatus.OPEN));
    assertTrue(updateStatusResponse.getStatusCode().is2xxSuccessful());
    assertNotNull(updateStatusResponse.getBody());
    assertEquals(Poll.PollStatus.OPEN, updateStatusResponse.getBody().getStatus());
    // update poll
    var newOptionsList = new ArrayList<>(poll.getOptions());
    newOptionsList.addAll(List.of(new PollOptionModification(null, Map.of("en", "Lisa M. Simpson"), null), new PollOptionModification(null, Map.of("en", "Turanga Leela"), Map.of())));
    var updateForm = new PollModification(poll.getId(), poll.getTitle(), poll.getDescription(), poll.getOrder(), newOptionsList, false, Poll.PollStatus.DRAFT);
    var updatePollResponse = controller.updatePoll(eventName, pollId, updateForm);
    assertTrue(updatePollResponse.getStatusCode().is2xxSuccessful());
    assertNotNull(updatePollResponse.getBody());
    assertEquals(Poll.PollStatus.OPEN, updatePollResponse.getBody().getStatus());
    assertEquals(4, updatePollResponse.getBody().getOptions().size());
    assertEquals("Homer J. Simpson", updatePollResponse.getBody().getOptions().get(0).getTitle().get("en"));
}
Also used : PollOptionModification(alfio.model.modification.PollOptionModification) PollModification(alfio.model.modification.PollModification) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

PollModification (alfio.model.modification.PollModification)2 PollOptionModification (alfio.model.modification.PollOptionModification)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 TestConfiguration (alfio.TestConfiguration)1 DataSourceConfiguration (alfio.config.DataSourceConfiguration)1 Initializer (alfio.config.Initializer)1 ControllerConfiguration (alfio.controller.api.ControllerConfiguration)1 EventManager (alfio.manager.EventManager)1 UserManager (alfio.manager.user.UserManager)1 alfio.model (alfio.model)1 AlfioMetadata (alfio.model.metadata.AlfioMetadata)1 DateTimeModification (alfio.model.modification.DateTimeModification)1 TicketCategoryModification (alfio.model.modification.TicketCategoryModification)1 Poll (alfio.model.poll.Poll)1 alfio.repository (alfio.repository)1 ConfigurationRepository (alfio.repository.system.ConfigurationRepository)1 OrganizationRepository (alfio.repository.user.OrganizationRepository)1 IntegrationTestUtil (alfio.test.util.IntegrationTestUtil)1 TestUtil.clockProvider (alfio.test.util.TestUtil.clockProvider)1