From 5793b738272d542a2acfe50ca42ee3299d5eb02c Mon Sep 17 00:00:00 2001 From: Sylvain Jermini Date: Fri, 7 Jun 2019 21:41:06 +0200 Subject: [PATCH] rest api: integration tests #588 --- .../api/v2/user/TicketApiV2Controller.java | 1 - .../user/ReservationFlowIntegrationTest.java | 53 +++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/main/java/alfio/controller/api/v2/user/TicketApiV2Controller.java b/src/main/java/alfio/controller/api/v2/user/TicketApiV2Controller.java index de2becbcde..a1cf7b2796 100644 --- a/src/main/java/alfio/controller/api/v2/user/TicketApiV2Controller.java +++ b/src/main/java/alfio/controller/api/v2/user/TicketApiV2Controller.java @@ -141,7 +141,6 @@ public ResponseEntity getTicketInfo(@PathVariable("eventName") Strin @PutMapping("/event/{eventName}/ticket/{ticketIdentifier}") public ValidatedResponse updateTicketInfo(@PathVariable("eventName") String eventName, @PathVariable("ticketIdentifier") String ticketIdentifier, - @RequestParam(value = "single-ticket", required = false, defaultValue = "false") boolean singleTicket, @RequestBody UpdateTicketOwnerForm updateTicketOwner, BindingResult bindingResult, HttpServletRequest request, 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 d18e709ade..b6a7e6c052 100644 --- a/src/test/java/alfio/controller/api/v2/user/ReservationFlowIntegrationTest.java +++ b/src/test/java/alfio/controller/api/v2/user/ReservationFlowIntegrationTest.java @@ -393,9 +393,9 @@ public void reservationFlowTest() throws Exception { contactForm.setLastName("name"); var ticketForm = new UpdateTicketOwnerForm(); - ticketForm.setFirstName("full"); - ticketForm.setLastName("name"); - ticketForm.setEmail("test@test.com"); + ticketForm.setFirstName("ticketfull"); + ticketForm.setLastName("ticketname"); + ticketForm.setEmail("tickettest@test.com"); contactForm.setTickets(Collections.singletonMap(reservation.getTicketsByCategory().get(0).getTickets().get(0).getUuid(), ticketForm)); var overviewRes = reservationApiV2Controller.validateToOverview(event.getShortName(), reservationId, "en", contactForm, new BeanPropertyBindingResult(contactForm, "paymentForm"), new MockHttpServletRequest(), new RedirectAttributesModelMap()); @@ -441,6 +441,53 @@ public void reservationFlowTest() throws Exception { reservation = reservationApiV2Controller.getReservationInfo(event.getShortName(), reservationId, new MockHttpSession()).getBody(); orderSummary = reservation.getOrderSummary(); assertFalse(orderSummary.getNotYetPaid()); + + + var confRes = reservationApiV2Controller.reSendReservationConfirmationEmail(event.getShortName(), reservationId, new MockHttpServletRequest()); + assertEquals(HttpStatus.OK, confRes.getStatusCode()); + assertTrue(confRes.getBody()); + + var ticket = reservation.getTicketsByCategory().stream().findFirst().get().getTickets().get(0); + assertEquals("tickettest@test.com", ticket.getEmail()); + assertEquals("ticketfull", ticket.getFirstName()); + assertEquals("ticketname", ticket.getLastName()); + + var ticketNotFoundRes = ticketApiV2Controller.getTicketInfo(event.getShortName(), "DONT_EXISTS"); + assertEquals(HttpStatus.NOT_FOUND, ticketNotFoundRes.getStatusCode()); + + var ticketFoundRes = ticketApiV2Controller.getTicketInfo(event.getShortName(), ticket.getUuid()); + assertEquals(HttpStatus.OK, ticketFoundRes.getStatusCode()); + var ticketFoundBody = ticketFoundRes.getBody(); + assertEquals("tickettest@test.com", ticketFoundBody.getEmail()); + assertEquals("ticketfull ticketname", ticketFoundBody.getFullName()); + assertEquals("full name", ticketFoundBody.getReservationFullName()); + assertTrue(reservationId.startsWith(ticketFoundBody.getReservationId().toLowerCase(Locale.ENGLISH))); + + var sendTicketByEmailRes = ticketApiV2Controller.sendTicketByEmail(event.getShortName(), ticket.getUuid(), new MockHttpServletRequest()); + assertEquals(HttpStatus.OK, sendTicketByEmailRes.getStatusCode()); + assertTrue(sendTicketByEmailRes.getBody()); + + //update ticket + var updateTicketOwnerForm = new UpdateTicketOwnerForm(); + updateTicketOwnerForm.setFirstName("Test"); + updateTicketOwnerForm.setLastName("Testson"); + updateTicketOwnerForm.setEmail("testmctest@test.com"); + var updateTicketRes = ticketApiV2Controller.updateTicketInfo(event.getShortName(), ticket.getUuid(), updateTicketOwnerForm, new BeanPropertyBindingResult(updateTicketOwnerForm, "ticket"), new MockHttpServletRequest(), null); + assertTrue(updateTicketRes.isSuccess()); + + + ticketFoundRes = ticketApiV2Controller.getTicketInfo(event.getShortName(), ticket.getUuid()); + ticketFoundBody = ticketFoundRes.getBody(); + assertEquals("testmctest@test.com", ticketFoundBody.getEmail()); + assertEquals("Test Testson", ticketFoundBody.getFullName()); + assertEquals("full name", ticketFoundBody.getReservationFullName()); + reservation = reservationApiV2Controller.getReservationInfo(event.getShortName(), reservationId, new MockHttpSession()).getBody(); + ticket = reservation.getTicketsByCategory().stream().findFirst().get().getTickets().get(0); + assertEquals("testmctest@test.com", ticket.getEmail()); + assertEquals("Test", ticket.getFirstName()); + assertEquals("Testson", ticket.getLastName()); + + } }