feat(tickets): attendee naming, attendee consent, ticket emails and resend ticket
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
1 parent
1d6b265fd2
commit
cc81dc0fa5
10 files changed
+481
-7
No files matched your search
@@ -32,7 +32,7 @@ Design: `design.md` (technical contracts) and `docs/superpowers/specs/2026-12-04
|
|||||||
- **`byToken`:** lists tickets (id, type, attendee name, code, state) only when Paid, without contacts.
|
- **`byToken`:** lists tickets (id, type, attendee name, code, state) only when Paid, without contacts.
|
||||||
- Scope: `solvway-services-counter/src/**`
|
- Scope: `solvway-services-counter/src/**`
|
||||||
- Verify: `mvn -T 1C -q -pl solvway-services-counter verify`
|
- Verify: `mvn -T 1C -q -pl solvway-services-counter verify`
|
||||||
- [ ] 2.2 Naming attendees, consent and ticket emails.
|
- [x] 2.2 Naming attendees, consent and ticket emails.
|
||||||
- Depends on: 2.1
|
- Depends on: 2.1
|
||||||
- Tests first:
|
- Tests first:
|
||||||
- **Naming:**
|
- **Naming:**
|
||||||
|
|||||||
+16
-1
@@ -1,13 +1,16 @@
|
|||||||
package com.solvway.services.counter.controller;
|
package com.solvway.services.counter.controller;
|
||||||
|
|
||||||
|
import com.solvway.services.counter.service.TicketOrderService;
|
||||||
import com.solvway.services.counter.service.TicketService;
|
import com.solvway.services.counter.service.TicketService;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/** Tickets (add-event-tickets). byCode is a public path; mobile-api checks the code's shape first. */
|
/** Tickets (add-event-tickets). byCode, attendee and consent are public paths; mobile-api checks and normalises input first. */
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/counter/ticket")
|
@RequestMapping("/counter/ticket")
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@@ -18,4 +21,16 @@ public class TicketController {
|
|||||||
public TicketService.TicketView byCode(@PathVariable String code) {
|
public TicketService.TicketView byCode(@PathVariable String code) {
|
||||||
return service.byCode(code);
|
return service.byCode(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Public: the buyer names a ticket of their Paid order, by the order's link token. */
|
||||||
|
@PostMapping("/attendee")
|
||||||
|
public TicketOrderService.OrderTicket attendee(@RequestBody TicketService.AttendeeRequest req) {
|
||||||
|
return service.nameAttendee(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Public: the attendee opts in on their ticket page. */
|
||||||
|
@PostMapping("/consent")
|
||||||
|
public void consent(@RequestBody TicketService.ConsentRequest req) {
|
||||||
|
service.consent(req);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+6
@@ -57,4 +57,10 @@ public class TicketOrderController {
|
|||||||
public void resend(@RequestBody TicketOrderStaffService.OrderRef req) {
|
public void resend(@RequestBody TicketOrderStaffService.OrderRef req) {
|
||||||
staff.resend(req);
|
staff.resend(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** add-event-tickets: staff resend one ticket. */
|
||||||
|
@PostMapping("/resendTicket")
|
||||||
|
public void resendTicket(@RequestBody TicketOrderStaffService.ActionRequest req) {
|
||||||
|
staff.resendTicket(req);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+62
-3
@@ -8,6 +8,8 @@ import com.solvway.services.counter.model.ShopOrder;
|
|||||||
import com.solvway.services.counter.model.ShopOrderLine;
|
import com.solvway.services.counter.model.ShopOrderLine;
|
||||||
import com.solvway.services.counter.repo.EventRepository;
|
import com.solvway.services.counter.repo.EventRepository;
|
||||||
import com.solvway.services.counter.repo.ShopOrderLineRepository;
|
import com.solvway.services.counter.repo.ShopOrderLineRepository;
|
||||||
|
import com.solvway.services.counter.repo.TicketRepository;
|
||||||
|
import com.solvway.services.counter.model.Ticket;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -36,16 +38,66 @@ public class TicketOrderMailer {
|
|||||||
private final EmailService emailService;
|
private final EmailService emailService;
|
||||||
private final EventRepository events;
|
private final EventRepository events;
|
||||||
private final ShopOrderLineRepository lines;
|
private final ShopOrderLineRepository lines;
|
||||||
|
private final TicketRepository tickets;
|
||||||
private final String portalBase;
|
private final String portalBase;
|
||||||
|
|
||||||
public TicketOrderMailer(EmailService emailService, EventRepository events, ShopOrderLineRepository lines,
|
public TicketOrderMailer(EmailService emailService, EventRepository events, ShopOrderLineRepository lines, TicketRepository tickets,
|
||||||
@Value("${app.admin-portal-base-url}") String portalBase) {
|
@Value("${app.admin-portal-base-url}") String portalBase) {
|
||||||
this.emailService = emailService;
|
this.emailService = emailService;
|
||||||
this.events = events;
|
this.events = events;
|
||||||
this.lines = lines;
|
this.lines = lines;
|
||||||
|
this.tickets = tickets;
|
||||||
this.portalBase = portalBase;
|
this.portalBase = portalBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** add-event-tickets: one ticket to one address, after the surrounding transaction commits; best effort as above. */
|
||||||
|
public void sendTicket(Ticket ticket, String to) {
|
||||||
|
Runnable deliver = () -> deliverTicket(ticket, to);
|
||||||
|
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||||
|
deliver.run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||||
|
@Override public void afterCommit() { deliver.run(); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deliverTicket(Ticket t, String to) {
|
||||||
|
try {
|
||||||
|
Event event = events.findByUuid(t.getEventUuid()).orElse(null);
|
||||||
|
String eventName = event == null ? "" : event.getName();
|
||||||
|
String type = lines.findById(t.getOrderLineId()).map(ShopOrderLine::getName).orElse("");
|
||||||
|
String who = t.getAttendeeName() == null ? "" : "<p>" + esc(t.getAttendeeName()) + "</p>";
|
||||||
|
String card = eventLine(event) + "<p>" + esc(type) + "</p>" + who + ticketBlock(t.getCode());
|
||||||
|
Email email = new Email();
|
||||||
|
email.setCompanyId(t.getCompanyId());
|
||||||
|
email.setSubject("Your ticket: " + eventName + " / Tiket anda: " + eventName);
|
||||||
|
email.setBody("<p>Here is your ticket. Show this QR code at the entrance. Open the link to keep the ticket at hand; there you can"
|
||||||
|
+ " also choose to hear about future events.</p>" + card
|
||||||
|
+ "<hr><p><i>Bahasa Malaysia</i></p><p>Ini tiket anda. Tunjukkan kod QR ini di pintu masuk. Buka pautan untuk menyimpan tiket;"
|
||||||
|
+ " di situ anda juga boleh memilih untuk menerima berita acara akan datang.</p>" + card);
|
||||||
|
email.setStatus(EmailEnum.StatusType.P);
|
||||||
|
email.setRecipients(List.of(new Recipient(null, to, EmailEnum.RecipientType.R, EmailEnum.RecipientStatusType.Y)));
|
||||||
|
emailService.send(email);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
log.warn("Ticket {} email failed: {}", t.getId(), e.getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The ticket's QR image (a PNG mobile-api draws) and its link. */
|
||||||
|
private String ticketBlock(String code) {
|
||||||
|
String link = esc(portalBase + "/t/" + code);
|
||||||
|
return "<p><img src=\"" + esc(portalBase + "/api/public/tickets/" + code + "/qr.png") + "\" width=\"200\" height=\"200\" alt=\"Ticket QR\"><br>"
|
||||||
|
+ "<a href=\"" + link + "\">" + link + "</a></p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String eventLine(Event event) {
|
||||||
|
if (event == null) return "";
|
||||||
|
String dates = event.getDateStart() == null ? "" : "<br>" + esc(event.getDateStart().toLocalDate())
|
||||||
|
+ (event.getDateEnd() == null ? "" : " - " + esc(event.getDateEnd().toLocalDate()));
|
||||||
|
return "<p><strong>" + esc(event.getName()) + "</strong>" + dates + (event.getLocation() == null ? "" : "<br>" + esc(event.getLocation())) + "</p>";
|
||||||
|
}
|
||||||
|
|
||||||
public void send(ShopOrder order, String kind) {
|
public void send(ShopOrder order, String kind) {
|
||||||
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||||
deliver(order, kind);
|
deliver(order, kind);
|
||||||
@@ -99,8 +151,15 @@ public class TicketOrderMailer {
|
|||||||
String en, ms;
|
String en, ms;
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case PAID -> {
|
case PAID -> {
|
||||||
en = "<p>Your order " + esc(o.getReference()) + " is confirmed.</p>";
|
// add-event-tickets: the tickets, each with its QR and link, and where to name the attendees.
|
||||||
ms = "<p>Pesanan anda " + esc(o.getReference()) + " telah disahkan.</p>";
|
StringBuilder qrs = new StringBuilder();
|
||||||
|
for (Ticket t : tickets.findByOrderIdOrderByIdAsc(o.getId())) {
|
||||||
|
if (Ticket.ACTIVE.equals(t.getStatus()) && t.getCode() != null) qrs.append(ticketBlock(t.getCode()));
|
||||||
|
}
|
||||||
|
en = "<p>Your order " + esc(o.getReference()) + " is confirmed. Your tickets are below; show a QR code at the entrance.</p>" + qrs
|
||||||
|
+ "<p>Name your attendees, so each gets their own ticket: " + orderLink + "</p>";
|
||||||
|
ms = "<p>Pesanan anda " + esc(o.getReference()) + " telah disahkan. Tiket anda di bawah; tunjukkan kod QR di pintu masuk.</p>" + qrs
|
||||||
|
+ "<p>Namakan peserta anda supaya setiap seorang menerima tiket sendiri: " + orderLink + "</p>";
|
||||||
}
|
}
|
||||||
case EXPIRED -> {
|
case EXPIRED -> {
|
||||||
en = "<p>Your order " + esc(o.getReference()) + " was not paid in time, so its tickets were released.</p>";
|
en = "<p>Your order " + esc(o.getReference()) + " was not paid in time, so its tickets were released.</p>";
|
||||||
|
|||||||
+9
@@ -151,6 +151,15 @@ public class TicketOrderStaffService {
|
|||||||
orders.save(o);
|
orders.save(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** add-event-tickets: one valid ticket again, to its attendee's email, else the buyer (spec: Resend Ticket). */
|
||||||
|
public void resendTicket(ActionRequest r) {
|
||||||
|
ShopOrder o = order(r.companyId(), r.eventUuid(), r.orderId());
|
||||||
|
Ticket t = tickets.findByOrderIdOrderByIdAsc(o.getId()).stream().filter(x -> x.getId().equals(r.ticketId())).findFirst()
|
||||||
|
.orElseThrow(() -> status(HttpStatus.NOT_FOUND, "TICKET_NOT_FOUND"));
|
||||||
|
if (!TicketState.VALID.equals(TicketState.of(o, t))) throw status(HttpStatus.CONFLICT, "TICKET_NOT_VALID");
|
||||||
|
mailer.sendTicket(t, t.getAttendeeEmail() != null ? t.getAttendeeEmail() : o.getBuyerEmail());
|
||||||
|
}
|
||||||
|
|
||||||
public void resend(OrderRef r) {
|
public void resend(OrderRef r) {
|
||||||
ShopOrder o = order(r.companyId(), r.eventUuid(), r.orderId());
|
ShopOrder o = order(r.companyId(), r.eventUuid(), r.orderId());
|
||||||
mailer.send(o, o.getLastEmail() == null ? TicketOrderMailer.RECEIVED : o.getLastEmail());
|
mailer.send(o, o.getLastEmail() == null ? TicketOrderMailer.RECEIVED : o.getLastEmail());
|
||||||
|
|||||||
+71
@@ -12,7 +12,10 @@ import com.solvway.services.counter.model.Ticket;
|
|||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/** add-event-tickets: tickets by their code. */
|
/** add-event-tickets: tickets by their code. */
|
||||||
@Service
|
@Service
|
||||||
@@ -21,6 +24,74 @@ public class TicketService {
|
|||||||
private final TicketRepository tickets;
|
private final TicketRepository tickets;
|
||||||
private final ShopOrderRepository orders;
|
private final ShopOrderRepository orders;
|
||||||
private final ShopOrderLineRepository lines;
|
private final ShopOrderLineRepository lines;
|
||||||
|
private final RegistrationService registration;
|
||||||
|
private final TicketOrderMailer mailer;
|
||||||
|
|
||||||
|
public record AttendeeRequest(String orderToken, long ticketId, String name, String mobileE164, String email, boolean permission) {}
|
||||||
|
|
||||||
|
public record ConsentRequest(String code, Long noticeId) {}
|
||||||
|
|
||||||
|
/** The buyer names a Paid order's ticket: a new code, consent and lead link cleared, the ticket emailed (spec: Naming Effects). */
|
||||||
|
@Transactional
|
||||||
|
public TicketOrderService.OrderTicket nameAttendee(AttendeeRequest r) {
|
||||||
|
if (!r.permission()) throw status(HttpStatus.BAD_REQUEST, "PERMISSION_REQUIRED");
|
||||||
|
String name = r.name() == null ? "" : r.name().strip();
|
||||||
|
if (name.isEmpty()) throw status(HttpStatus.BAD_REQUEST, "NAME_REQUIRED");
|
||||||
|
if (name.length() > 100) throw status(HttpStatus.BAD_REQUEST, "NAME_TOO_LONG");
|
||||||
|
String mobile = blankToNull(r.mobileE164()), email = blankToNull(r.email());
|
||||||
|
if (mobile == null && email == null) throw status(HttpStatus.BAD_REQUEST, "MOBILE_OR_EMAIL_REQUIRED");
|
||||||
|
ShopOrder o = r.orderToken() == null ? null : orders.findByToken(r.orderToken()).orElse(null);
|
||||||
|
Ticket t = o == null ? null : tickets.findById(r.ticketId()).filter(x -> x.getOrderId() == o.getId()).orElse(null);
|
||||||
|
if (t == null) throw status(HttpStatus.NOT_FOUND, "ORDER_NOT_FOUND");
|
||||||
|
if (!ShopOrder.PAID.equals(o.getStatus())) throw status(HttpStatus.CONFLICT, "NOT_PAID");
|
||||||
|
if (Ticket.CANCELLED.equals(t.getStatus())) throw status(HttpStatus.CONFLICT, "TICKET_CANCELLED");
|
||||||
|
if (t.getCheckedInAt() != null) throw status(HttpStatus.CONFLICT, "ALREADY_CHECKED_IN");
|
||||||
|
t.setCode(TicketState.newCode());
|
||||||
|
t.setAttendeeName(name);
|
||||||
|
t.setAttendeeMobileE164(mobile);
|
||||||
|
t.setAttendeeEmail(email);
|
||||||
|
t.setAttendeeNamedAt(LocalDateTime.now());
|
||||||
|
t.setAttendeeConsentAt(null);
|
||||||
|
t.setAttendeeNoticeId(null);
|
||||||
|
t.setEventLeadUuid(null);
|
||||||
|
tickets.save(t);
|
||||||
|
if (email != null) mailer.sendTicket(t, email); // delivered after commit
|
||||||
|
String typeName = lines.findById(t.getOrderLineId()).map(ShopOrderLine::getName).orElse(null);
|
||||||
|
return new TicketOrderService.OrderTicket(t.getId(), typeName, name, t.getCode(), TicketState.of(o, t), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The attendee opts in on their ticket page: they become a TICKET event lead (spec: Attendee Consent). */
|
||||||
|
@Transactional
|
||||||
|
public void consent(ConsentRequest r) {
|
||||||
|
if (r.noticeId() == null) throw status(HttpStatus.BAD_REQUEST, "CONSENT_REQUIRED");
|
||||||
|
Ticket t = ticket(r.code());
|
||||||
|
ShopOrder o = orders.findById(t.getOrderId()).orElseThrow(TicketService::notFound);
|
||||||
|
String state = TicketState.of(o, t);
|
||||||
|
if (!TicketState.VALID.equals(state) && !TicketState.CHECKED_IN.equals(state)) throw status(HttpStatus.CONFLICT, "TICKET_NOT_VALID");
|
||||||
|
if (t.getAttendeeName() == null) throw status(HttpStatus.CONFLICT, "ATTENDEE_REQUIRED");
|
||||||
|
if (t.getAttendeeConsentAt() != null) return;
|
||||||
|
capture(t, r.noticeId(), t.getCheckedInAt() != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Records the attendee's consent and links their event lead, matched as in QR registration; attend marks it attended. */
|
||||||
|
void capture(Ticket t, long noticeId, boolean attend) {
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
RegistrationService.RegisterResult res = registration.register(new RegistrationService.RegisterRequest(t.getCompanyId(),
|
||||||
|
t.getEventUuid(), null, t.getAttendeeName(), t.getAttendeeMobileE164(), t.getAttendeeEmail(), null, null, List.of(),
|
||||||
|
noticeId, now, attend, "TICKET", null));
|
||||||
|
t.setAttendeeConsentAt(now);
|
||||||
|
t.setAttendeeNoticeId(noticeId);
|
||||||
|
if (res != null && res.eventLeadUuid() != null) t.setEventLeadUuid(Long.valueOf(res.eventLeadUuid()));
|
||||||
|
tickets.save(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String blankToNull(String s) {
|
||||||
|
return s == null || s.isBlank() ? null : s.strip();
|
||||||
|
}
|
||||||
|
|
||||||
|
static ResponseStatusException status(HttpStatus status, String reason) {
|
||||||
|
return new ResponseStatusException(status, reason);
|
||||||
|
}
|
||||||
|
|
||||||
/** The public ticket page: no buyer details and no attendee contact. */
|
/** The public ticket page: no buyer details and no attendee contact. */
|
||||||
public record TicketView(long companyId, long eventUuid, String typeName, String attendeeFirstName, boolean named, String state,
|
public record TicketView(long companyId, long eventUuid, String typeName, String attendeeFirstName, boolean named, String state,
|
||||||
|
|||||||
+205
@@ -0,0 +1,205 @@
|
|||||||
|
package com.solvway.services.counter.service;
|
||||||
|
|
||||||
|
import com.solvway.services.counter.model.Event;
|
||||||
|
import com.solvway.services.counter.model.ShopOrder;
|
||||||
|
import com.solvway.services.counter.model.ShopOrderLine;
|
||||||
|
import com.solvway.services.counter.model.Ticket;
|
||||||
|
import com.solvway.services.counter.repo.EventRepository;
|
||||||
|
import com.solvway.services.counter.repo.ShopOrderLineRepository;
|
||||||
|
import com.solvway.services.counter.repo.ShopOrderRepository;
|
||||||
|
import com.solvway.services.counter.repo.TicketRepository;
|
||||||
|
import com.solvway.services.counter.repo.TicketTypeRepository;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.lenient;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/** add-event-tickets: naming attendees, attendee consent and resend ticket (spec: Naming Attendees, Naming Effects, Naming Refusals,
|
||||||
|
* Attendee Is Not A Lead Without Consent, Attendee Consent, Resend Ticket). */
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class TicketAttendeeTest {
|
||||||
|
private static final long COMPANY = 7L;
|
||||||
|
private static final long EVENT = 900L;
|
||||||
|
private static final String TOKEN = "tokentokentokentokento";
|
||||||
|
private static final String CODE = "aaaaaaaaaaaaaaaaaaaaaa";
|
||||||
|
|
||||||
|
@Mock private TicketRepository tickets;
|
||||||
|
@Mock private ShopOrderRepository orders;
|
||||||
|
@Mock private ShopOrderLineRepository lines;
|
||||||
|
@Mock private EventRepository events;
|
||||||
|
@Mock private TicketTypeRepository types;
|
||||||
|
@Mock private RegistrationService registration;
|
||||||
|
@Mock private TicketOrderMailer mailer;
|
||||||
|
|
||||||
|
private TicketService service;
|
||||||
|
private TicketOrderStaffService staff;
|
||||||
|
private ShopOrder order;
|
||||||
|
private Ticket ticket;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
service = new TicketService(tickets, orders, lines, registration, mailer);
|
||||||
|
staff = new TicketOrderStaffService(events, new TicketTypeService(events, types, tickets, lines), types, tickets, orders, lines, mailer);
|
||||||
|
order = new ShopOrder();
|
||||||
|
order.setId(300L);
|
||||||
|
order.setCompanyId(COMPANY);
|
||||||
|
order.setEventUuid(EVENT);
|
||||||
|
order.setToken(TOKEN);
|
||||||
|
order.setStatus(ShopOrder.PAID);
|
||||||
|
order.setBuyerName("Aisyah Rahman");
|
||||||
|
order.setBuyerEmail("a@example.test");
|
||||||
|
lenient().when(orders.findByToken(TOKEN)).thenReturn(Optional.of(order));
|
||||||
|
lenient().when(orders.findById(300L)).thenReturn(Optional.of(order));
|
||||||
|
ticket = new Ticket();
|
||||||
|
ticket.setId(1L);
|
||||||
|
ticket.setCompanyId(COMPANY);
|
||||||
|
ticket.setEventUuid(EVENT);
|
||||||
|
ticket.setOrderId(300L);
|
||||||
|
ticket.setOrderLineId(400L);
|
||||||
|
ticket.setCode(CODE);
|
||||||
|
lenient().when(tickets.findById(1L)).thenReturn(Optional.of(ticket));
|
||||||
|
lenient().when(tickets.findByCode(CODE)).thenReturn(Optional.of(ticket));
|
||||||
|
lenient().when(tickets.findByOrderIdOrderByIdAsc(300L)).thenReturn(List.of(ticket));
|
||||||
|
lenient().when(tickets.save(any(Ticket.class))).thenAnswer(i -> i.getArgument(0));
|
||||||
|
ShopOrderLine line = new ShopOrderLine();
|
||||||
|
line.setId(400L);
|
||||||
|
line.setName("General");
|
||||||
|
lenient().when(lines.findById(400L)).thenReturn(Optional.of(line));
|
||||||
|
Event e = new Event();
|
||||||
|
e.setUuid(EVENT);
|
||||||
|
e.setCompanyId(COMPANY);
|
||||||
|
lenient().when(events.findByUuid(EVENT)).thenReturn(Optional.of(e));
|
||||||
|
lenient().when(registration.register(any())).thenReturn(new RegistrationService.RegisterResult("CREATED", "5000"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TicketService.AttendeeRequest name(String name, String mobile, String email, boolean permission) {
|
||||||
|
return new TicketService.AttendeeRequest(TOKEN, 1L, name, mobile, email, permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertStatus(Runnable r, int status, String reason) {
|
||||||
|
assertThatThrownBy(r::run).isInstanceOfSatisfying(ResponseStatusException.class, ex -> {
|
||||||
|
assertThat(ex.getStatusCode().value()).isEqualTo(status);
|
||||||
|
assertThat(ex.getReason()).isEqualTo(reason);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void namingNeedsThePermissionTick() {
|
||||||
|
assertStatus(() -> service.nameAttendee(name("Tan Mei Ling", null, "tan@example.test", false)), 400, "PERMISSION_REQUIRED");
|
||||||
|
assertThat(ticket.getCode()).isEqualTo(CODE);
|
||||||
|
verify(tickets, never()).save(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void namingNeedsANameAndOneContact() {
|
||||||
|
assertStatus(() -> service.nameAttendee(name(" ", null, "tan@example.test", true)), 400, "NAME_REQUIRED");
|
||||||
|
assertStatus(() -> service.nameAttendee(name("Tan", null, null, true)), 400, "MOBILE_OR_EMAIL_REQUIRED");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void namingIsRefusedForAnUnpaidOrderACancelledOrACheckedInTicket() {
|
||||||
|
order.setStatus(ShopOrder.AWAITING);
|
||||||
|
assertStatus(() -> service.nameAttendee(name("Tan", null, "tan@example.test", true)), 409, "NOT_PAID");
|
||||||
|
order.setStatus(ShopOrder.PAID);
|
||||||
|
ticket.setStatus(Ticket.CANCELLED);
|
||||||
|
assertStatus(() -> service.nameAttendee(name("Tan", null, "tan@example.test", true)), 409, "TICKET_CANCELLED");
|
||||||
|
ticket.setStatus(Ticket.ACTIVE);
|
||||||
|
ticket.setCheckedInAt(LocalDateTime.now());
|
||||||
|
assertStatus(() -> service.nameAttendee(name("Tan", null, "tan@example.test", true)), 409, "ALREADY_CHECKED_IN");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void anUnknownTokenOrAnotherOrdersTicketIsNotFound() {
|
||||||
|
when(orders.findByToken("zzzzzzzzzzzzzzzzzzzzzz")).thenReturn(Optional.empty());
|
||||||
|
assertStatus(() -> service.nameAttendee(new TicketService.AttendeeRequest("zzzzzzzzzzzzzzzzzzzzzz", 1L, "Tan", null, "t@x.test", true)),
|
||||||
|
404, "ORDER_NOT_FOUND");
|
||||||
|
ticket.setOrderId(301L);
|
||||||
|
assertStatus(() -> service.nameAttendee(name("Tan", null, "tan@example.test", true)), 404, "ORDER_NOT_FOUND");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void namingReplacesTheCodeClearsConsentAndEmailsTheAttendee() {
|
||||||
|
ticket.setAttendeeConsentAt(LocalDateTime.now());
|
||||||
|
ticket.setAttendeeNoticeId(77L);
|
||||||
|
ticket.setEventLeadUuid(5000L);
|
||||||
|
TicketOrderService.OrderTicket t = service.nameAttendee(name(" Tan Mei Ling ", null, "tan@example.test", true));
|
||||||
|
assertThat(ticket.getCode()).matches("[A-Za-z0-9_-]{22}").isNotEqualTo(CODE);
|
||||||
|
assertThat(t.code()).isEqualTo(ticket.getCode());
|
||||||
|
assertThat(ticket.getAttendeeName()).isEqualTo("Tan Mei Ling");
|
||||||
|
assertThat(ticket.getAttendeeEmail()).isEqualTo("tan@example.test");
|
||||||
|
assertThat(ticket.getAttendeeNamedAt()).isNotNull();
|
||||||
|
assertThat(ticket.getAttendeeConsentAt()).isNull();
|
||||||
|
assertThat(ticket.getAttendeeNoticeId()).isNull();
|
||||||
|
assertThat(ticket.getEventLeadUuid()).isNull();
|
||||||
|
verify(mailer).sendTicket(ticket, "tan@example.test");
|
||||||
|
verify(registration, never()).register(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void namingWithOnlyAMobileSendsNoEmail() {
|
||||||
|
service.nameAttendee(name("Lim Wei", "+60125550101", null, true));
|
||||||
|
assertThat(ticket.getAttendeeMobileE164()).isEqualTo("+60125550101");
|
||||||
|
verify(mailer, never()).sendTicket(any(), anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void consentCapturesTheAttendeeAsATicketLead() {
|
||||||
|
order.setStatus(ShopOrder.PAID);
|
||||||
|
ticket.setAttendeeName("Tan Mei Ling");
|
||||||
|
ticket.setAttendeeEmail("tan@example.test");
|
||||||
|
service.consent(new TicketService.ConsentRequest(CODE, 77L));
|
||||||
|
ArgumentCaptor<RegistrationService.RegisterRequest> r = ArgumentCaptor.forClass(RegistrationService.RegisterRequest.class);
|
||||||
|
verify(registration).register(r.capture());
|
||||||
|
assertThat(r.getValue().source()).isEqualTo("TICKET");
|
||||||
|
assertThat(r.getValue().salespersonUserId()).isNull();
|
||||||
|
assertThat(r.getValue().consentNoticeId()).isEqualTo(77L);
|
||||||
|
assertThat(r.getValue().email()).isEqualTo("tan@example.test");
|
||||||
|
assertThat(r.getValue().attend()).isFalse();
|
||||||
|
assertThat(ticket.getAttendeeConsentAt()).isNotNull();
|
||||||
|
assertThat(ticket.getAttendeeNoticeId()).isEqualTo(77L);
|
||||||
|
assertThat(ticket.getEventLeadUuid()).isEqualTo(5000L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void consentIsRefusedOnAnInvalidOrUnnamedTicket() {
|
||||||
|
assertStatus(() -> service.consent(new TicketService.ConsentRequest(CODE, 77L)), 409, "ATTENDEE_REQUIRED");
|
||||||
|
ticket.setAttendeeName("Tan");
|
||||||
|
ticket.setAttendeeEmail("tan@example.test");
|
||||||
|
order.setStatus(ShopOrder.CANCELLED);
|
||||||
|
assertStatus(() -> service.consent(new TicketService.ConsentRequest(CODE, 77L)), 409, "TICKET_NOT_VALID");
|
||||||
|
verify(registration, never()).register(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void resendTicketGoesToTheAttendeeElseTheBuyer() {
|
||||||
|
staff.resendTicket(new TicketOrderStaffService.ActionRequest(COMPANY, EVENT, 300L, 1L, "staff1"));
|
||||||
|
verify(mailer).sendTicket(ticket, "a@example.test");
|
||||||
|
ticket.setAttendeeName("Tan");
|
||||||
|
ticket.setAttendeeEmail("tan@example.test");
|
||||||
|
staff.resendTicket(new TicketOrderStaffService.ActionRequest(COMPANY, EVENT, 300L, 1L, "staff1"));
|
||||||
|
verify(mailer).sendTicket(ticket, "tan@example.test");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void resendTicketRefusesAnInvalidTicket() {
|
||||||
|
order.setStatus(ShopOrder.AWAITING);
|
||||||
|
assertStatus(() -> staff.resendTicket(new TicketOrderStaffService.ActionRequest(COMPANY, EVENT, 300L, 1L, "staff1")),
|
||||||
|
409, "TICKET_NOT_VALID");
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -68,7 +68,7 @@ class TicketCodesTest {
|
|||||||
orderService = new TicketOrderService(new TransactionTemplate(mock(PlatformTransactionManager.class)), events, typeService, types,
|
orderService = new TicketOrderService(new TransactionTemplate(mock(PlatformTransactionManager.class)), events, typeService, types,
|
||||||
orders, lines, tickets, guests, eventLeads, registration, mailer);
|
orders, lines, tickets, guests, eventLeads, registration, mailer);
|
||||||
staff = new TicketOrderStaffService(events, typeService, types, tickets, orders, lines, mailer);
|
staff = new TicketOrderStaffService(events, typeService, types, tickets, orders, lines, mailer);
|
||||||
ticketService = new TicketService(tickets, orders, lines);
|
ticketService = new TicketService(tickets, orders, lines, registration, mailer);
|
||||||
Event event = new Event();
|
Event event = new Event();
|
||||||
event.setUuid(EVENT);
|
event.setUuid(EVENT);
|
||||||
event.setCompanyId(COMPANY);
|
event.setCompanyId(COMPANY);
|
||||||
|
|||||||
+109
@@ -0,0 +1,109 @@
|
|||||||
|
package com.solvway.services.counter.service;
|
||||||
|
|
||||||
|
import com.solvway.core.model.Email;
|
||||||
|
import com.solvway.services.counter.model.Event;
|
||||||
|
import com.solvway.services.counter.model.ShopOrder;
|
||||||
|
import com.solvway.services.counter.model.ShopOrderLine;
|
||||||
|
import com.solvway.services.counter.model.Ticket;
|
||||||
|
import com.solvway.services.counter.repo.EventRepository;
|
||||||
|
import com.solvway.services.counter.repo.ShopOrderLineRepository;
|
||||||
|
import com.solvway.services.counter.repo.TicketRepository;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/** add-event-tickets: the paid email carries the tickets, and the ticket email (spec: Order Emails, Ticket Email). */
|
||||||
|
class TicketMailTest {
|
||||||
|
private static final String BASE = "https://co-lite.example";
|
||||||
|
private final ShopOrderLineRepository lines = mock(ShopOrderLineRepository.class);
|
||||||
|
private final EventRepository events = mock(EventRepository.class);
|
||||||
|
private final TicketRepository tickets = mock(TicketRepository.class);
|
||||||
|
private final EmailService emailService = mock(EmailService.class);
|
||||||
|
private final TicketOrderMailer mailer = new TicketOrderMailer(emailService, events, lines, tickets, BASE);
|
||||||
|
private ShopOrder order;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
order = new ShopOrder();
|
||||||
|
order.setId(300L);
|
||||||
|
order.setCompanyId(7L);
|
||||||
|
order.setEventUuid(900L);
|
||||||
|
order.setReference("T-7K3M9Q");
|
||||||
|
order.setToken("tokentokentokentokento");
|
||||||
|
order.setBuyerName("Aisyah");
|
||||||
|
order.setBuyerEmail("a@example.test");
|
||||||
|
order.setStatus(ShopOrder.PAID);
|
||||||
|
order.setTotalSen(50000);
|
||||||
|
Event e = new Event();
|
||||||
|
e.setName("KL Hotel Tech Day");
|
||||||
|
e.setLocation("KLCC");
|
||||||
|
e.setDateStart(LocalDateTime.of(2027, 1, 15, 9, 0));
|
||||||
|
e.setDateEnd(LocalDateTime.of(2027, 1, 16, 18, 0));
|
||||||
|
when(events.findByUuid(900L)).thenReturn(Optional.of(e));
|
||||||
|
ShopOrderLine l = new ShopOrderLine();
|
||||||
|
l.setId(400L);
|
||||||
|
l.setName("General");
|
||||||
|
l.setUnitPriceSen(25000);
|
||||||
|
l.setQuantity(2);
|
||||||
|
when(lines.findByOrderIdOrderByIdAsc(300L)).thenReturn(List.of(l));
|
||||||
|
when(lines.findById(400L)).thenReturn(Optional.of(l));
|
||||||
|
when(emailService.send(any())).thenReturn(Optional.of(new Email()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Ticket ticket(long id, String code, String status) {
|
||||||
|
Ticket t = new Ticket();
|
||||||
|
t.setId(id);
|
||||||
|
t.setCompanyId(7L);
|
||||||
|
t.setEventUuid(900L);
|
||||||
|
t.setOrderId(300L);
|
||||||
|
t.setOrderLineId(400L);
|
||||||
|
t.setCode(code);
|
||||||
|
t.setStatus(status);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Email sent() {
|
||||||
|
ArgumentCaptor<Email> e = ArgumentCaptor.forClass(Email.class);
|
||||||
|
verify(emailService).send(e.capture());
|
||||||
|
return e.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void thePaidEmailCarriesEachActiveTicketsQrAndLinkAndTheNamingLink() {
|
||||||
|
when(tickets.findByOrderIdOrderByIdAsc(300L)).thenReturn(List.of(
|
||||||
|
ticket(1L, "aaaaaaaaaaaaaaaaaaaaaa", Ticket.ACTIVE), ticket(2L, "bbbbbbbbbbbbbbbbbbbbbb", Ticket.ACTIVE),
|
||||||
|
ticket(3L, "cccccccccccccccccccccc", Ticket.CANCELLED)));
|
||||||
|
mailer.send(order, "PAID");
|
||||||
|
String body = sent().getBody();
|
||||||
|
assertThat(body).contains("<img src=\"" + BASE + "/api/public/tickets/aaaaaaaaaaaaaaaaaaaaaa/qr.png\"")
|
||||||
|
.contains(BASE + "/t/aaaaaaaaaaaaaaaaaaaaaa")
|
||||||
|
.contains(BASE + "/api/public/tickets/bbbbbbbbbbbbbbbbbbbbbb/qr.png")
|
||||||
|
.doesNotContain("cccccccccccccccccccccc")
|
||||||
|
.contains("Name your attendees").contains(BASE + "/o/tokentokentokentokento");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void theTicketEmailGoesToTheGivenAddressWithItsQrAndLink() {
|
||||||
|
Ticket t = ticket(1L, "aaaaaaaaaaaaaaaaaaaaaa", Ticket.ACTIVE);
|
||||||
|
t.setAttendeeName("Tan <Mei> Ling");
|
||||||
|
mailer.sendTicket(t, "tan@example.test");
|
||||||
|
Email e = sent();
|
||||||
|
assertThat(e.getCompanyId()).isEqualTo(7L);
|
||||||
|
assertThat(e.getRecipients()).extracting(r -> r.getRecipient()).containsExactly("tan@example.test");
|
||||||
|
assertThat(e.getSubject()).contains("KL Hotel Tech Day");
|
||||||
|
assertThat(e.getBody()).contains(BASE + "/api/public/tickets/aaaaaaaaaaaaaaaaaaaaaa/qr.png")
|
||||||
|
.contains(BASE + "/t/aaaaaaaaaaaaaaaaaaaaaa").contains("General").contains("KLCC")
|
||||||
|
.contains("Tan <Mei> Ling").contains("Bahasa Malaysia")
|
||||||
|
.doesNotContain("Aisyah");
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -31,7 +31,7 @@ class TicketOrderExpiryAndMailTest {
|
|||||||
private final ShopOrderLineRepository lines = mock(ShopOrderLineRepository.class);
|
private final ShopOrderLineRepository lines = mock(ShopOrderLineRepository.class);
|
||||||
private final EventRepository events = mock(EventRepository.class);
|
private final EventRepository events = mock(EventRepository.class);
|
||||||
private final EmailService emailService = mock(EmailService.class);
|
private final EmailService emailService = mock(EmailService.class);
|
||||||
private final TicketOrderMailer mailer = new TicketOrderMailer(emailService, events, lines, "https://co-lite.example");
|
private final TicketOrderMailer mailer = new TicketOrderMailer(emailService, events, lines, mock(com.solvway.services.counter.repo.TicketRepository.class), "https://co-lite.example");
|
||||||
private ShopOrder order;
|
private ShopOrder order;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
|||||||
Reference in new issue
Block a user