Skip to content

Commit

Permalink
Updated integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey authored and Sergey committed Jan 31, 2025
1 parent 7627891 commit d711801
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
36 changes: 28 additions & 8 deletions src/main/java/alfio/repository/TicketReservationRepository.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
/**
* This file is part of alf.io.
*
* <p>
* 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.
*
* <p>
* 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.
*
* <p>
* 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.repository;

import alfio.model.*;
import alfio.model.BillingDetails;
import alfio.model.PriceContainer;
import alfio.model.ReservationIdAndEventId;
import alfio.model.ReservationMetadata;
import alfio.model.ReservationWithPurchaseContext;
import alfio.model.TicketReservation;
import alfio.model.TicketReservationAdditionalInfo;
import alfio.model.TicketReservationInfo;
import alfio.model.TicketReservationStatusAndValidation;
import alfio.model.TicketReservationWithEventIdentifier;
import alfio.model.TicketsByDateStatistic;
import alfio.model.support.Array;
import alfio.model.support.JSONData;
import alfio.model.support.UserIdAndOrganizationId;
Expand All @@ -26,7 +36,12 @@

import java.math.BigDecimal;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

@QueryRepository
public interface TicketReservationRepository {
Expand All @@ -46,6 +61,12 @@ int createNewReservation(@Bind("id") String id,
@Bind("organizationId") int organizationId,
@Bind("userId") Integer userId);

@Query("""
update tickets_reservation set promo_code_id_fk = :promotionCodeDiscountId\
where email_address = :email
""")
int setPromotionCodeDiscountId(@Bind("email") String email, @Bind("promotionCodeDiscountId") Integer promotionCodeDiscountId);

@Query("update tickets_reservation set user_id_fk = :userId where id = :reservationId")
int setReservationOwner(@Bind("reservationId") String reservationId, @Bind("userId") Integer userId);

Expand Down Expand Up @@ -177,7 +198,7 @@ int updateBillingData(@Bind("vatStatus") PriceContainer.VatStatus vatStatus,
@Bind("vatCountry") String country,
@Bind("invoiceRequested") boolean invoiceRequested,
@Bind("reservationId") String reservationId);


@Query("select min(confirmation_ts) from tickets_reservation where event_id_fk = :eventId and confirmation_ts is not null")
Optional<ZonedDateTime> getFirstConfirmationTimestampForEvent(@Bind("eventId") int eventId);
Expand All @@ -204,7 +225,6 @@ left join (select id, creation_ts from tickets_reservation where event_id_fk = :
List<TicketsByDateStatistic> getReservedStatistic(@Bind("eventId") int eventId, @Bind("fromDate") ZonedDateTime from, @Bind("toDate") ZonedDateTime to, @Bind("granularity") String granularity);



@Query("select id, event_id_fk from tickets_reservation where id in (:ids) and event_id_fk is not null")
List<ReservationIdAndEventId> getReservationIdAndEventId(@Bind("ids") Collection<String> ids);

Expand Down Expand Up @@ -285,7 +305,7 @@ int resetVat(@Bind("reservationId") String reservationId,


default Integer countTicketsInReservationForCategories(String reservationId, Collection<Integer> categories) {
if(categories == null || categories.isEmpty()) {
if (categories == null || categories.isEmpty()) {
return this.countTicketsInReservationNoCategories(reservationId);
} else {
return this.countTicketsInReservationForExistingCategories(reservationId, categories);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* This file is part of alf.io.
*
* <p>
* 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.
*
* <p>
* 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.
*
* <p>
* You should have received a copy of the GNU General Public License
* along with alf.io. If not, see <http://www.gnu.org/licenses/>.
*/
Expand All @@ -24,15 +24,18 @@
import alfio.manager.EventManager;
import alfio.manager.user.UserManager;
import alfio.model.Event;
import alfio.model.PromoCodeDiscount;
import alfio.model.TicketCategory;
import alfio.model.metadata.AlfioMetadata;
import alfio.model.modification.AdminReservationModification;
import alfio.model.modification.DateTimeModification;
import alfio.model.modification.TicketCategoryModification;
import alfio.repository.EventDeleterRepository;
import alfio.repository.EventRepository;
import alfio.repository.PromoCodeDiscountRepository;
import alfio.repository.TicketCategoryRepository;
import alfio.repository.TicketRepository;
import alfio.repository.TicketReservationRepository;
import alfio.repository.system.ConfigurationRepository;
import alfio.repository.user.OrganizationRepository;
import alfio.test.util.AlfioIntegrationTest;
Expand All @@ -58,7 +61,10 @@
import java.util.List;

import static alfio.controller.api.admin.EventApiController.FIXED_FIELDS;
import static alfio.test.util.IntegrationTestUtil.*;
import static alfio.test.util.IntegrationTestUtil.AVAILABLE_SEATS;
import static alfio.test.util.IntegrationTestUtil.DESCRIPTION;
import static alfio.test.util.IntegrationTestUtil.initEvent;
import static alfio.test.util.IntegrationTestUtil.owner;
import static alfio.test.util.TestUtil.clockProvider;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -92,13 +98,18 @@ class EventApiControllerIntegrationTest {
private TicketCategoryRepository ticketCategoryRepository;
@Autowired
private TicketRepository ticketRepository;
@Autowired
private PromoCodeDiscountRepository promoCodeDiscountRepository;
@Autowired
private TicketReservationRepository ticketReservationRepository;

private Event event;
private static final String TEST_ATTENDEE_EXTERNAL_REFERENCE = "123";
private static final String TEST_ATTENDEE_USER_LANGUAGE = "en";
private static final String TEST_ATTENDEE_FIRST_NAME = "Attendee";
private static final String TEST_ATTENDEE_LAST_NAME = "Test";
private static final String TEST_ATTENDEE_EMAIL = "[email protected]";
private static final String TEST_PROMO_CODE = "test-promo-code";

@Test
void getAllEventsForExternalInPerson() {
Expand Down Expand Up @@ -152,13 +163,15 @@ void testGivenListOfAttendeesWithFieldsUploadThenSameFieldsAvailableOnCsvDownloa
when(principal.getName()).thenReturn(owner(eventAndUser.getValue()));
var modification = getTestAdminReservationModification();
var result = this.attendeeBulkImportApiController.createReservations(eventAndUser.getKey().getShortName(), modification, false, principal);
var organizationId = organizationRepository.findAllForUser(eventAndUser.getRight()).get(0).getId();

// GIVEN - invocation of async processing job
var requestStatus = this.attendeeBulkImportApiController.getRequestsStatus(eventAndUser.getKey().getShortName(), result.getData(), principal);
assertEquals(1, requestStatus.getData().getCountPending());

// WHEN - processing of pending reservations completes
this.adminReservationRequestManager.processPendingReservations();
createPromoCode(organizationId, modification.getCustomerData().getEmailAddress());

// THEN - assert correctness of data persisted
var tickets = this.ticketRepository.findAllConfirmedForCSV(event.getId());
Expand All @@ -178,7 +191,7 @@ void testGivenListOfAttendeesWithFieldsUploadThenSameFieldsAvailableOnCsvDownloa
String expectedTestAttendeeCsvLine = "\""+foundTicket.getUuid()+"\""+",default,"+"\""+event.getShortName()+"\""+",ACQUIRED,0,0,0,0,"+"\""+foundTicket.getTicketsReservationId()+"\""+",\""+TEST_ATTENDEE_FIRST_NAME+" "+TEST_ATTENDEE_LAST_NAME+"\","+TEST_ATTENDEE_FIRST_NAME+","+TEST_ATTENDEE_LAST_NAME+","+TEST_ATTENDEE_EMAIL+",false,"+TEST_ATTENDEE_USER_LANGUAGE;
String returnedCsvContent = mockResponse.getContentAsString().trim().replace("\uFEFF", ""); // remove BOM
assertTrue(returnedCsvContent.startsWith(getExpectedHeaderCsvLine() + "\n" + expectedTestAttendeeCsvLine));
assertTrue(returnedCsvContent.endsWith("\"Billing Address\",,,," + TEST_ATTENDEE_EXTERNAL_REFERENCE));
assertTrue(returnedCsvContent.endsWith("\"Billing Address\",,"+TEST_PROMO_CODE+",,," + TEST_ATTENDEE_EXTERNAL_REFERENCE));
}

private AdminReservationModification getTestAdminReservationModification() {
Expand All @@ -202,13 +215,22 @@ private Pair<Event,String> createEvent(Event.EventFormat format) {

}

private void createPromoCode(int organizationId, String email) {
var eventId = event.getId();
promoCodeDiscountRepository.addPromoCode(TEST_PROMO_CODE, eventId, organizationId, ZonedDateTime.now(), ZonedDateTime.now()
.plusDays(3), 10, PromoCodeDiscount.DiscountType.FIXED_AMOUNT, "[1,2,3]", 1, "test promo code", "[email protected]", PromoCodeDiscount.CodeType.DISCOUNT, 21, "usd");
var promoCodeId = promoCodeDiscountRepository.findAllInEvent(eventId).get(0).getId();
ticketReservationRepository.setPromotionCodeDiscountId(email, promoCodeId);
}

private String getExpectedHeaderCsvLine() {
String expectedHeaderCsvLine = String.join(",", FIXED_FIELDS);
expectedHeaderCsvLine = expectedHeaderCsvLine.replaceAll("Full Name", "\"Full Name\"");
expectedHeaderCsvLine = expectedHeaderCsvLine.replaceAll("First Name", "\"First Name\"");
expectedHeaderCsvLine = expectedHeaderCsvLine.replaceAll("Last Name", "\"Last Name\"");
expectedHeaderCsvLine = expectedHeaderCsvLine.replaceAll("Billing Address", "\"Billing Address\"");
expectedHeaderCsvLine = expectedHeaderCsvLine.replaceAll("Country Code", "\"Country Code\"");
expectedHeaderCsvLine = expectedHeaderCsvLine.replaceAll("Voucher Code", "\"Voucher Code\"");
expectedHeaderCsvLine = expectedHeaderCsvLine.replaceAll("Payment ID", "\"Payment ID\"");
expectedHeaderCsvLine = expectedHeaderCsvLine.replaceAll("Payment Method", "\"Payment Method\"");
expectedHeaderCsvLine = expectedHeaderCsvLine.replaceAll("External Reference", "\"External Reference\"");
Expand Down

0 comments on commit d711801

Please sign in to comment.