feat(tickets): staff ticket view, door check-in, resend ticket and ticketed venue check-in results

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-04 17:25:40 +08:00
1 parent 8f3818414d
commit 031ec8449e
10 files changed
+418 -8

No files matched your search

@@ -63,6 +63,9 @@ public class RestApiCounterServiceConstants {
public static final String API_REST_COUNTER_TICKET_BY_CODE = "/counter/ticket/byCode/{code}";
public static final String API_REST_COUNTER_TICKET_ATTENDEE = "/counter/ticket/attendee";
public static final String API_REST_COUNTER_TICKET_CONSENT = "/counter/ticket/consent";
public static final String API_REST_COUNTER_TICKET_STAFF = "/counter/ticket/staff";
public static final String API_REST_COUNTER_TICKET_CHECKIN = "/counter/ticket/checkin";
public static final String API_REST_COUNTER_TICKET_ORDER_RESEND_TICKET = "/counter/ticketOrder/resendTicket";
public static final String API_REST_COUNTER_EVENT_SALESPERSON_FIND_BY_EVENT_UUID="/counter/eventSalesperson/findByEventUuid/{eventUuid}";
public static final String API_REST_COUNTER_EVENT_SALESPERSON_REPLACE="/counter/eventSalesperson/replace";
public static final String API_REST_COUNTER_INTEREST_FIND_BY_COMPANY="/counter/interest/findByCompany/{companyId}";
@@ -0,0 +1,41 @@
package com.solvway.mobile.api.controller.admin;
import com.solvway.core.annotation.AppAuth;
import com.solvway.mobile.api.service.AdminTicketService;
import com.solvway.mobile.api.useraccess.AdminModule;
import com.solvway.mobile.api.useraccess.Audited;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/** add-event-tickets: the staff view of a scanned ticket and door check-in. Must stay under {@code controller..} for AppAccessAspect. */
@RestController
@RequestMapping("/api/admin/tickets/{code}")
@RequiredArgsConstructor
public class AdminTicketCodeController {
private final AdminTicketService tickets;
@AppAuth
@AdminModule("BO_EVENTS")
@GetMapping
public ResponseEntity<Map<String, Object>> ticket(@PathVariable String code) {
return ResponseEntity.ok(tickets.ticket(code));
}
/** The ticket code is a bearer link, so it is not recorded as the audit target; the ticket keeps who checked it in. */
@AppAuth
@AdminModule("BO_EVENTS")
@Audited(target = false)
@PostMapping("/checkin")
public ResponseEntity<Map<String, Object>> checkIn(@PathVariable String code,
@RequestBody(required = false) AdminTicketService.CheckInBody body) {
return ResponseEntity.ok(tickets.checkIn(code, body));
}
}
@@ -127,4 +127,13 @@ public class AdminTicketController {
tickets.resend(uuid, orderId);
return ResponseEntity.noContent().build();
}
@AppAuth
@AdminModule(value = "BO_EVENT_TICKETS", also = "BO_EVENTS")
@Audited(targetVariable = "ticketId")
@PostMapping("/orders/{orderId}/tickets/{ticketId}/resend")
public ResponseEntity<Void> resendTicket(@PathVariable String uuid, @PathVariable String orderId, @PathVariable String ticketId) {
tickets.resendTicket(uuid, orderId, ticketId);
return ResponseEntity.noContent().build();
}
}
@@ -2,6 +2,7 @@ package com.solvway.mobile.api.service;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.solvway.mobile.api.constant.api.RestApiSystemServiceConstants;
import com.solvway.mobile.api.dto.admin.CompanyEvent;
import com.solvway.mobile.api.util.RestTemplateCustomUtil;
import lombok.RequiredArgsConstructor;
@@ -31,10 +32,12 @@ public class AdminTicketService {
private static final ObjectMapper JSON = new ObjectMapper();
private static final int PAGE_SIZE = 50;
/** The form field a counter refusal belongs to, so the portal can show it beside that field. */
private static final Map<String, String> FIELDS = Map.of(
"PAYMENT_INSTRUCTIONS_REQUIRED", "paymentInstructions", "PAYMENT_INSTRUCTIONS_TOO_LONG", "paymentInstructions",
"HOLD_DAYS_INVALID", "holdDays", "NAME_INVALID", "name", "NAME_TAKEN", "name", "PRICE_INVALID", "priceSen",
"QUANTITY_INVALID", "quantity", "QUANTITY_BELOW_HELD", "quantity", "PAYMENT_REF_TOO_LONG", "paymentRef");
private static final Map<String, String> FIELDS = Map.ofEntries(
Map.entry("PAYMENT_INSTRUCTIONS_REQUIRED", "paymentInstructions"), Map.entry("PAYMENT_INSTRUCTIONS_TOO_LONG", "paymentInstructions"),
Map.entry("HOLD_DAYS_INVALID", "holdDays"), Map.entry("NAME_INVALID", "name"), Map.entry("NAME_TAKEN", "name"),
Map.entry("PRICE_INVALID", "priceSen"), Map.entry("QUANTITY_INVALID", "quantity"), Map.entry("QUANTITY_BELOW_HELD", "quantity"),
Map.entry("PAYMENT_REF_TOO_LONG", "paymentRef"), Map.entry("NAME_REQUIRED", "name"), Map.entry("NAME_TOO_LONG", "name"),
Map.entry("MOBILE_OR_EMAIL_REQUIRED", "mobile"));
private final RestTemplateCustomUtil rest;
private final AdminEventLeadService leads;
@@ -45,6 +48,11 @@ public class AdminTicketService {
public record PayBody(String paymentRef) {}
/** Door check-in: name, mobile and email only for an unnamed ticket; consent ticked by the attendee at the door. */
public record CheckInBody(String name, String mobile, String email, Boolean consent) {}
private record Staff(CompanyEvent event, Map<String, Object> body) {}
public Map<String, Object> settings(String uuid) {
CompanyEvent e = leads.loadEvent(uuid, null);
Map<String, Object> out = new LinkedHashMap<>();
@@ -127,6 +135,75 @@ public class AdminTicketService {
post(API_REST_COUNTER_TICKET_ORDER_RESEND, MAP, orderBody(read(uuid), orderId));
}
public void resendTicket(String uuid, String orderId, String ticketId) {
Map<String, Object> body = orderBody(write(uuid), orderId);
body.put("ticketId", AdminEventLeadService.parseOr(ticketId, AdminTicketService::ticketNotFound));
post(API_REST_COUNTER_TICKET_ORDER_RESEND_TICKET, MAP, body);
}
/** add-event-tickets: the staff view of a scanned ticket; only for the event's company (super admins: any), else not found. */
public Map<String, Object> ticket(String code) {
Staff s = staff(code);
return view(post(API_REST_COUNTER_TICKET_STAFF, MAP, s.body()), s.event());
}
/** Door check-in; the counter refuses a second check-in, an invalid ticket and a day outside the event. */
public Map<String, Object> checkIn(String code, CheckInBody b) {
Staff s = staff(code);
Map<String, Object> body = s.body();
if (b != null) {
body.put("name", AdminEventLeadService.trimmed(b.name()));
body.put("mobileE164", AdminEventLeadService.mobile(b.mobile()));
body.put("email", AdminEventLeadService.email(b.email()));
if (Boolean.TRUE.equals(b.consent())) body.put("noticeId", notice(s.event()).get("id"));
}
body.put("doneBy", leads.caller().getUsername());
return view(post(API_REST_COUNTER_TICKET_CHECKIN, MAP, body), s.event());
}
private Staff staff(String code) {
if (code == null || !PublicRegistrationService.TOKEN_SHAPE.matcher(code).matches()) throw ticketNotFound();
Map<String, Object> t = PublicRegistrationService.found(() -> rest.getForEntity(rest.getURLforApiService(API_REST_COUNTER_TICKET_BY_CODE),
MAP, code).getBody());
if (t == null || !(t.get("eventUuid") instanceof Number uuid)) throw ticketNotFound();
CompanyEvent e;
try {
e = leads.loadEvent(String.valueOf(uuid.longValue()), null);
} catch (com.solvway.mobile.api.errorhandler.CodedResponseStatusException x) {
if (x.getStatusCode().value() == 404) throw ticketNotFound(); // another company's ticket looks unknown
throw x;
}
Map<String, Object> body = new LinkedHashMap<>();
body.put("companyId", e.getCompanyId());
body.put("code", code);
return new Staff(e, body);
}
private Map<String, Object> view(Map<String, Object> staffView, CompanyEvent e) {
Map<String, Object> out = new LinkedHashMap<>(staffView == null ? Map.of() : staffView);
out.put("eventName", e.getName());
out.put("startDate", e.getDateStart() == null ? null : e.getDateStart().toLocalDate().toString());
out.put("endDate", e.getDateEnd() == null ? null : e.getDateEnd().toLocalDate().toString());
out.put("location", e.getLocation());
if (!Boolean.TRUE.equals(out.get("consented"))) {
Map<String, Object> n = notice(e);
if (n.get("id") != null) {
out.put("notice", Map.of("id", n.get("id"), "textEn", String.valueOf(n.get("textEn")), "textMs", String.valueOf(n.get("textMs"))));
}
}
return out;
}
private Map<String, Object> notice(CompanyEvent e) {
Map<String, Object> n = PublicRegistrationService.found(() -> rest.getForEntity(
rest.getURLforApiService(RestApiSystemServiceConstants.API_REST_COMPANY_PRIVACY_NOTICE), MAP, e.getCompanyId()).getBody());
return n == null ? Map.of() : n;
}
private static com.solvway.mobile.api.errorhandler.CodedResponseStatusException ticketNotFound() {
return AdminEventLeadService.error(HttpStatus.NOT_FOUND, "Ticket not found", "TICKET_NOT_FOUND", null);
}
private Map<String, Object> read(String uuid) {
CompanyEvent e = leads.loadEvent(uuid, null);
Map<String, Object> body = new LinkedHashMap<>();
@@ -163,7 +240,11 @@ public class AdminTicketService {
} catch (Exception ignored) {
// not a ProblemDetail: keep the generic code
}
throw AdminEventLeadService.error(HttpStatus.valueOf(e.getStatusCode().value()), code, code, FIELDS.get(code));
// "CODE|value" (add-event-tickets: ALREADY_CHECKED_IN|<time>, NOT_VALID|<state>): the value goes in details
String[] p = code.split("\\|", 2);
var x = AdminEventLeadService.error(HttpStatus.valueOf(e.getStatusCode().value()), p[0], p[0], FIELDS.get(p[0]));
if (p.length > 1) x.getBody().setProperty("details", Map.of("value", p[1]));
throw x;
}
}
}
@@ -123,6 +123,7 @@ public class PublicInviteService {
body.put(email ? "email" : "mobileE164", normalised);
Map<String, Object> out = post(RestApiCounterServiceConstants.API_REST_COUNTER_CHECKIN_LOOKUP, body);
if (out != null && "CHECKED_IN".equals(out.get("result"))) return Map.of("result", "CHECKED_IN", "firstName", firstName(out));
if (out != null && "SHOW_TICKET".equals(out.get("result"))) return Map.of("result", "SHOW_TICKET"); // a ticketed event
return Map.of("result", "FORM");
}
@@ -167,7 +168,7 @@ public class PublicInviteService {
}
}
/** A counter 409 (EVENT_FULL, NOT_REGISTERED, NOT_EVENT_DAY) goes to the visitor with its own code. */
/** A counter 409 (EVENT_FULL, NOT_REGISTERED, NOT_EVENT_DAY, TICKETS_ONLY) goes to the visitor with its own code. */
private Map<String, Object> post(String api, Object body) {
try {
return rest.postForEntity(url(api), MAP, body).getBody();
@@ -177,6 +178,7 @@ public class PublicInviteService {
case "EVENT_FULL" -> "This event is full";
case "NOT_REGISTERED" -> "Register before checking in";
case "NOT_EVENT_DAY" -> "Check-in opens on the event day";
case "TICKETS_ONLY" -> "Please show your ticket at the entrance.";
default -> "This could not be completed";
}, code, null);
}
@@ -0,0 +1,74 @@
package com.solvway.mobile.api.controller.admin;
import com.solvway.core.annotation.AppAuth;
import com.solvway.mobile.api.service.AdminTicketService;
import com.solvway.mobile.api.useraccess.AdminModule;
import com.solvway.mobile.api.useraccess.Audited;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.bind.annotation.GetMapping;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/** add-event-tickets: the staff ticket view and door check-in need BO_EVENTS; check-in is audited without the code as target. */
@ExtendWith(MockitoExtension.class)
class AdminTicketCodeControllerTest {
private static final String CODE = "abcdefghijklmnopqrstu_";
@Mock private AdminTicketService tickets;
@InjectMocks private AdminTicketCodeController controller;
private MockMvc mvc;
@BeforeEach
void setUp() {
mvc = MockMvcBuilders.standaloneSetup(controller).build();
}
private static List<Method> handlers() {
return Arrays.stream(AdminTicketCodeController.class.getDeclaredMethods())
.filter(m -> Modifier.isPublic(m.getModifiers()) && !m.isSynthetic()).toList();
}
@Test
void bothEndpointsNeedTheEventsModuleAndOnlyCheckInIsAudited() {
assertThat(handlers()).hasSize(2);
for (Method m : handlers()) {
assertThat(m.isAnnotationPresent(AppAuth.class)).as(m.getName()).isTrue();
assertThat(m.getAnnotation(AdminModule.class).value()).as(m.getName()).containsExactly("BO_EVENTS");
boolean read = m.isAnnotationPresent(GetMapping.class);
assertThat(m.isAnnotationPresent(Audited.class)).as(m.getName() + " @Audited").isEqualTo(!read);
if (!read) assertThat(m.getAnnotation(Audited.class).target()).isFalse();
}
}
@Test
void routesBindToTheService() throws Exception {
when(tickets.ticket(CODE)).thenReturn(Map.of());
mvc.perform(get("/api/admin/tickets/" + CODE)).andExpect(status().isOk());
when(tickets.checkIn(eq(CODE), any())).thenReturn(Map.of());
mvc.perform(post("/api/admin/tickets/" + CODE + "/checkin").contentType(MediaType.APPLICATION_JSON)
.content("{\"name\":\"Lim Wei\",\"mobile\":\"0125550101\",\"consent\":true}")).andExpect(status().isOk());
verify(tickets).checkIn(CODE, new AdminTicketService.CheckInBody("Lim Wei", "0125550101", null, true));
mvc.perform(post("/api/admin/tickets/" + CODE + "/checkin")).andExpect(status().isOk());
}
}
@@ -52,7 +52,7 @@ class AdminTicketControllerTest {
@Test
void everyEndpointNeedsTheTicketsModule() {
assertThat(handlers()).hasSize(12);
assertThat(handlers()).hasSize(13);
for (Method m : handlers()) {
assertThat(m.isAnnotationPresent(AppAuth.class)).as(m.getName() + " @AppAuth").isTrue();
AdminModule module = m.getAnnotation(AdminModule.class);
@@ -0,0 +1,182 @@
package com.solvway.mobile.api.service;
import com.solvway.core.model.User;
import com.solvway.core.utils.HttpReqRespUtils;
import com.solvway.mobile.api.dto.admin.CompanyEvent;
import com.solvway.mobile.api.errorhandler.CodedResponseStatusException;
import com.solvway.mobile.api.useraccess.AdminCompanyScope;
import com.solvway.mobile.api.util.RestTemplateCustomUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.MockedStatic;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
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.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** add-event-tickets: staff ticket view, door check-in, resend ticket and the ticket counts (spec: Staff Ticket View, Door Check-In, Resend Ticket). */
@SuppressWarnings({"unchecked", "rawtypes"})
class AdminTicketCheckInTest {
private static final String EVENT = "/counter/event/findByUuid/{uuid}";
private static final String SETTINGS = "/counter/ticketType/settings";
private static final String TYPES = "/counter/ticketType/list";
private static final String TYPE_SAVE = "/counter/ticketType/save";
private static final String TYPE_DELETE = "/counter/ticketType/delete";
private static final String ORDERS = "/counter/ticketOrder/list";
private static final String ORDER = "/counter/ticketOrder/get";
private static final String PAID = "/counter/ticketOrder/markPaid";
private static final String CANCEL = "/counter/ticketOrder/cancel";
private static final String CANCEL_TICKET = "/counter/ticketOrder/cancelTicket";
private static final String RESEND = "/counter/ticketOrder/resend";
private static final String BY_CODE = "/counter/ticket/byCode/{code}";
private static final String STAFF = "/counter/ticket/staff";
private static final String CHECKIN = "/counter/ticket/checkin";
private static final String RESEND_TICKET = "/counter/ticketOrder/resendTicket";
private static final String NOTICE = "/company/{id}/privacyNotice";
private static final String CODE = "abcdefghijklmnopqrstu_";
private static final long EV = 3312726793093644288L;
private static final long COMPANY = 5L;
private RestTemplateCustomUtil rest;
private AdminTicketService service;
private MockedStatic<HttpReqRespUtils> http;
@BeforeEach
void setUp() {
rest = mock(RestTemplateCustomUtil.class);
AdminAuthenticationService auth = mock(AdminAuthenticationService.class);
service = new AdminTicketService(rest, new AdminEventLeadService(rest, auth, new AdminCompanyScope()));
when(rest.getURLforApiService(any())).thenAnswer(i -> i.getArgument(0));
http = mockStatic(HttpReqRespUtils.class);
http.when(HttpReqRespUtils::getJwtToken).thenReturn("tok");
User caller = new User();
caller.setId(21L);
caller.setUsername("finance1");
caller.setCompanyId(COMPANY);
when(auth.loadUserByToken("tok")).thenReturn(caller);
stubEvent(COMPANY);
stubTicket(COMPANY);
when(rest.getForEntity(eq(NOTICE), any(ParameterizedTypeReference.class), eq(COMPANY)))
.thenReturn(ResponseEntity.ok(Map.of("id", 9L, "textEn", "English notice", "textMs", "Notis")));
when(rest.postForEntity(anyString(), any(ParameterizedTypeReference.class), any())).thenReturn(ResponseEntity.ok(Map.of()));
}
@AfterEach
void close() { http.close(); }
private void stubEvent(long company) {
CompanyEvent e = new CompanyEvent();
e.setCompanyId(company);
e.setUuid(EV);
e.setName("KL Hotel Tech Day");
e.setDateStart(LocalDateTime.of(2027, 1, 15, 9, 0));
e.setDateEnd(LocalDateTime.of(2027, 1, 16, 18, 0));
e.setTicketsEnabled(true);
e.setPaymentInstructions("Maybank 5140");
e.setHoldDays(3);
when(rest.getForEntity(eq(EVENT), any(ParameterizedTypeReference.class), eq(EV))).thenReturn(ResponseEntity.ok(e));
}
private void stubTicket(long company) {
when(rest.getForEntity(eq(BY_CODE), any(ParameterizedTypeReference.class), eq(CODE)))
.thenReturn(ResponseEntity.ok(Map.of("companyId", company, "eventUuid", EV, "state", "VALID")));
}
private Map<String, Object> sent(String api) {
ArgumentCaptor<Object> c = ArgumentCaptor.forClass(Object.class);
verify(rest).postForEntity(eq(api), any(ParameterizedTypeReference.class), c.capture());
return (Map<String, Object>) c.getValue();
}
private static void assertCoded(Runnable r, HttpStatus status, String code) {
assertThatThrownBy(r::run).isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
assertThat(e.getStatusCode()).isEqualTo(status);
assertThat(e.getCode()).isEqualTo(code);
});
}
private static HttpClientErrorException counter(HttpStatus status, String code) {
String body = "{\"type\":\"about:blank\",\"status\":" + status.value() + ",\"detail\":\"" + code + "\"}";
return HttpClientErrorException.create(status, status.getReasonPhrase(), null, body.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8);
}
private final String ev = String.valueOf(EV);
@Test
void theStaffViewIsScopedToTheCallersCompanyAndAddsTheEvent() {
when(rest.postForEntity(eq(STAFF), any(ParameterizedTypeReference.class), any())).thenReturn(ResponseEntity.ok(
Map.of("typeName", "General", "attendeeName", "Tan Mei Ling", "named", true, "consented", false, "state", "VALID")));
Map<String, Object> out = service.ticket(CODE);
assertThat(sent(STAFF)).containsEntry("companyId", COMPANY).containsEntry("code", CODE);
assertThat(out).containsEntry("attendeeName", "Tan Mei Ling").containsEntry("eventName", "KL Hotel Tech Day");
assertThat((Map<String, Object>) out.get("notice")).containsEntry("id", 9L);
}
@Test
void anotherCompanysTicketOrABadCodeIsNotFound() {
stubEvent(99L);
assertCoded(() -> service.ticket(CODE), HttpStatus.NOT_FOUND, "TICKET_NOT_FOUND");
assertCoded(() -> service.checkIn(CODE, null), HttpStatus.NOT_FOUND, "TICKET_NOT_FOUND");
assertCoded(() -> service.ticket("short"), HttpStatus.NOT_FOUND, "TICKET_NOT_FOUND");
verify(rest, never()).postForEntity(eq(STAFF), any(ParameterizedTypeReference.class), any());
verify(rest, never()).postForEntity(eq(CHECKIN), any(ParameterizedTypeReference.class), any());
}
@Test
void checkInSendsTheNormalisedAttendeeTheConsentNoticeAndTheStaffUser() {
service.checkIn(CODE, new AdminTicketService.CheckInBody(" Lim Wei ", "012-555 0101", null, true));
assertThat(sent(CHECKIN)).containsEntry("companyId", COMPANY).containsEntry("code", CODE).containsEntry("name", "Lim Wei")
.containsEntry("mobileE164", "+60125550101").containsEntry("noticeId", 9L).containsEntry("doneBy", "finance1");
}
@Test
void checkInWithoutConsentSendsNoNotice() {
service.checkIn(CODE, new AdminTicketService.CheckInBody(null, null, null, false));
assertThat(sent(CHECKIN)).doesNotContainKey("noticeId").containsEntry("doneBy", "finance1");
}
@Test
void checkInRefusalsKeepTheirCodeAndValue() {
when(rest.postForEntity(eq(CHECKIN), any(ParameterizedTypeReference.class), any()))
.thenThrow(counter(HttpStatus.CONFLICT, "ALREADY_CHECKED_IN|2027-01-15T09:30"))
.thenThrow(counter(HttpStatus.CONFLICT, "NOT_VALID|AWAITING"))
.thenThrow(counter(HttpStatus.CONFLICT, "NOT_EVENT_DAY"))
.thenThrow(counter(HttpStatus.BAD_REQUEST, "NAME_REQUIRED"));
assertThatThrownBy(() -> service.checkIn(CODE, null)).isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
assertThat(e.getCode()).isEqualTo("ALREADY_CHECKED_IN");
assertThat(e.getBody().getProperties()).containsEntry("details", Map.of("value", "2027-01-15T09:30"));
});
assertThatThrownBy(() -> service.checkIn(CODE, null)).isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
assertThat(e.getCode()).isEqualTo("NOT_VALID");
assertThat(e.getBody().getProperties()).containsEntry("details", Map.of("value", "AWAITING"));
});
assertCoded(() -> service.checkIn(CODE, null), HttpStatus.CONFLICT, "NOT_EVENT_DAY");
assertThatThrownBy(() -> service.checkIn(CODE, null)).isInstanceOfSatisfying(CodedResponseStatusException.class,
e -> assertThat(e.getBody().getProperties()).containsEntry("details", Map.of("field", "name")));
}
@Test
void resendTicketSendsTheTicketAndTheStaffUser() {
service.resendTicket(ev, "300", "1");
assertThat(sent(RESEND_TICKET)).containsEntry("companyId", COMPANY).containsEntry("orderId", 300L).containsEntry("ticketId", 1L)
.containsEntry("doneBy", "finance1");
}
}
@@ -488,4 +488,22 @@ class PublicInviteServiceTest {
verify(rest, never()).getForEntity(eq(COMPANY_URL), any(ParameterizedTypeReference.class), any());
verify(rest, never()).getForEntity(eq(NOTICE), any(ParameterizedTypeReference.class), any());
}
// --- ticketed events (add-event-tickets) ---
@Test
void lookup_showTicketPassesThrough() {
post(LOOKUP, Map.of("result", "SHOW_TICKET"));
assertThat(service.lookup(CK, new PublicCheckinLookupRequest("a@x.com"))).isEqualTo(Map.of("result", "SHOW_TICKET"));
}
@Test
void walkIn_onATicketedEventIsRefused() {
postConflict(REGISTER, "TICKETS_ONLY");
assertThatThrownBy(() -> service.walkIn(CK, ok())).isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
assertThat(e.getStatusCode()).isEqualTo(HttpStatus.CONFLICT);
assertThat(e.getCode()).isEqualTo("TICKETS_ONLY");
assertThat(e.getReason()).isEqualTo("Please show your ticket at the entrance.");
});
}
}