diff --git a/src/test/java/alfio/controller/api/v2/user/ReservationFlowIntegrationTest.java b/src/test/java/alfio/controller/api/v2/user/ReservationFlowIntegrationTest.java index 593e45446a..3f033c113c 100644 --- a/src/test/java/alfio/controller/api/v2/user/ReservationFlowIntegrationTest.java +++ b/src/test/java/alfio/controller/api/v2/user/ReservationFlowIntegrationTest.java @@ -311,15 +311,18 @@ public void reservationFlowTest() throws Exception { List extensionStream = IOUtils.readLines(new InputStreamReader(extensionInputStream, StandardCharsets.UTF_8)); String concatenation = String.join("\n", extensionStream); extensionService.createOrUpdate(null, null, new Extension("-", "syncName", concatenation.replace("placeHolder", "false"), true)); + extensionService.createOrUpdate(null, null, new Extension("-", "asyncName", concatenation.replace("placeHolder", "true"), true)); +// System.out.println(extensionRepository.getScript("-", "asyncName")); } List body = eventApiV2Controller.listEvents().getBody(); assertNotNull(body); assertTrue(body.isEmpty()); ensureConfiguration(); + // check if EVENT_CREATED was logged List extLogs = extensionLogRepository.getPage(null, null, null, 100, 0); - assertEquals("Size of log", 2, extLogs.size()); - assertEquals("EVENT_CREATED", extLogs.get(1).getDescription()); + assertEventLogged(extLogs, "EVENT_CREATED", 4, 1); + assertEventLogged(extLogs, "EVENT_CREATED", 4, 3); { @@ -576,7 +579,14 @@ public void reservationFlowTest() throws Exception { assertTrue(activePaymentMethods.isEmpty()); configurationRepository.deleteCategoryLevelByKey(ConfigurationKeys.PAYMENT_METHODS_BLACKLIST.name(), event.getId(), hiddenCategoryId); + + // clear the extension_log table so that we can check the very next additions + // cannot have just one row in the log, every event adds EXACTLY two logs + // log expected: RESERVATION_CANCELLED + cleanupExtensionLog(); reservationApiV2Controller.cancelPendingReservation(event.getShortName(), res.getBody().getValue()); + extLogs = extensionLogRepository.getPage(null, null, null, 100, 0); + assertEventLogged(extLogs, "RESERVATION_CANCELLED", 2, 1); // this is run by a job, but given the fact that it's in another separate transaction, it cannot work in this test (WaitingQueueSubscriptionProcessor.handleWaitingTickets) assertEquals(1, ticketReservationManager.revertTicketsToFreeIfAccessRestricted(event.getId())); @@ -896,6 +906,7 @@ public void reservationFlowTest() throws Exception { var handleRes = reservationApiV2Controller.confirmOverview(event.getShortName(), reservationId, "en", paymentForm, new BeanPropertyBindingResult(paymentForm, "paymentForm"), new MockHttpServletRequest()); + assertEquals(HttpStatus.OK, handleRes.getStatusCode()); checkStatus(reservationId, HttpStatus.OK, true, TicketReservation.TicketReservationStatus.OFFLINE_PAYMENT); @@ -912,8 +923,16 @@ public void reservationFlowTest() throws Exception { assertEquals("0.10", orderSummary.getTotalVAT()); assertEquals("1.00", orderSummary.getVatPercentage()); + //clear the extension_log table so that we can check the expectation + cleanupExtensionLog(); + validatePayment(event.getShortName(), reservationId); + extLogs = extensionLogRepository.getPage(null, null, null, 100, 0); + assertEventLogged(extLogs, "RESERVATION_CONFIRMED", 4, 1); + assertEventLogged(extLogs, "TICKET_ASSIGNED", 4, 3); + + checkStatus(reservationId, HttpStatus.OK, true, TicketReservation.TicketReservationStatus.COMPLETE); tStatus = reservationApiV2Controller.getTransactionStatus(event.getShortName(), reservationId, "BANK_TRANSFER"); @@ -1002,6 +1021,9 @@ public void reservationFlowTest() throws Exception { // { + //clear the extension_log table so that we can check the expectation + cleanupExtensionLog(); + Principal principal = mock(Principal.class); Mockito.when(principal.getName()).thenReturn(user); String ticketIdentifier = fullTicketInfo.getUuid(); @@ -1017,6 +1039,10 @@ public void reservationFlowTest() throws Exception { assertFalse(audits.isEmpty()); assertTrue(audits.stream().anyMatch(sa -> sa.getTicketUuid().equals(ticketIdentifier))); + extLogs = extensionLogRepository.getPage(null, null, null, 100, 0); + assertEventLogged(extLogs, "TICKET_CHECKED_IN", 2, 1); + + TicketAndCheckInResult ticketAndCheckInResultOk = checkInApiController.findTicketWithUUID(event.getId(), ticketIdentifier, ticketCode); assertEquals(CheckInStatus.ALREADY_CHECK_IN, ticketAndCheckInResultOk.getResult().getStatus()); @@ -1032,6 +1058,7 @@ public void reservationFlowTest() throws Exception { //test revert check in assertTrue(checkInApiController.revertCheckIn(event.getId(), ticketIdentifier, principal)); + assertFalse(checkInApiController.revertCheckIn(event.getId(), ticketIdentifier, principal)); TicketAndCheckInResult ticketAndCheckInResult2 = checkInApiController.findTicketWithUUID(event.getId(), ticketIdentifier, ticketCode); assertEquals(CheckInStatus.OK_READY_TO_BE_CHECKED_IN, ticketAndCheckInResult2.getResult().getStatus()); @@ -1056,14 +1083,16 @@ public void reservationFlowTest() throws Exception { assertEquals(0, eventWithAdditionalInfo4.getCheckedInTickets()); + cleanupExtensionLog(); + CheckInApiController.TicketCode tc2 = new CheckInApiController.TicketCode(); tc2.setCode(ticketCode); TicketAndCheckInResult ticketAndcheckInResult = checkInApiController.checkIn(event.getId(), ticketIdentifier, tc2, new TestingAuthenticationToken("ciccio", "ciccio")); assertEquals(CheckInStatus.SUCCESS, ticketAndcheckInResult.getResult().getStatus()); - // + extLogs = extensionLogRepository.getPage(null, null, null, 100, 0); + assertEventLogged(extLogs, "TICKET_CHECKED_IN", 2, 1); - // var offlineIdentifiers = checkInApiController.getOfflineIdentifiers(event.getShortName(), 0L, new MockHttpServletResponse(), principal); assertFalse("Alf.io-PI integration must be enabled by default", offlineIdentifiers.isEmpty()); @@ -1177,6 +1206,15 @@ public void reservationFlowTest() throws Exception { } + private void cleanupExtensionLog() { + jdbcTemplate.update("delete from extension_log", Map.of()); + } + + private void assertEventLogged(List extLog, String event, int logSize, int index){ + assertEquals(logSize, extLog.size()); // each event logs exactly two logs + assertEquals(event, extLog.get(index).getDescription()); + } + private void checkStatus(String reservationId, HttpStatus expectedHttpStatus, Boolean validated, TicketReservation.TicketReservationStatus reservationStatus) { var statusRes = reservationApiV2Controller.getReservationStatus(event.getShortName(), reservationId); assertEquals(expectedHttpStatus, statusRes.getStatusCode()); diff --git a/src/test/resources/extension.js b/src/test/resources/extension.js index 9b6c29f491..21a34329e1 100644 --- a/src/test/resources/extension.js +++ b/src/test/resources/extension.js @@ -15,6 +15,7 @@ function getScriptMetadata() { 'RESERVATION_CANCELLED', //fired when reservation(s) are cancelled 'TICKET_CANCELLED', //fired when ticket(s) (but not the entire reservation) are cancelled 'TICKET_ASSIGNED', //fired on ticket assignment. No results expected. + 'TICKET_CHECKED_IN', //fired when a ticket has been checked in. No results expected. 'WAITING_QUEUE_SUBSCRIPTION', //fired on waiting queue subscription. No results expected. 'EVENT_CREATED', //fired when an event has been created. Return boolean for synchronous variant, no results expected for the asynchronous one. 'EVENT_STATUS_CHANGE', //fired when an event status has changed (normally, from DRAFT to PUBLIC). Return boolean for synchronous variant, no results expected for the asynchronous one.