diff --git a/openspec/changes/add-event-invitations/design.md b/openspec/changes/add-event-invitations/design.md index e316dbc..3e44eb6 100644 --- a/openspec/changes/add-event-invitations/design.md +++ b/openspec/changes/add-event-invitations/design.md @@ -65,7 +65,7 @@ The services run with `TZ=Asia/Kuala_Lumpur`, so every stored time is Malaysian ### 2. Shared rules in services-counter - **`EventDays.isDuring(event, now)`:** true when `now.toLocalDate()` (Malaysian time) is between `dateStart.toLocalDate()` and `dateEnd.toLocalDate()` inclusive. When `dateStart` is null, only the end counts. When `dateEnd` is null, it is false. This one static helper is used by: - - staff capture, QR register, invite register and check-in capture, to set `attended_at`; + - staff capture, QR register and check-in capture, to set `attended_at` (an invite registration never does: the link can be opened anywhere, so the guest checks in); - the capacity rule; - the check-in window. - **`GuestLinker.link(eventUuid, eventLead, lead)`:** called in the same transaction after any capture creates or finds an event lead. It finds an unlinked guest of the event by the lead's `mobile_e164`, else by `email_normalised`. It sets `event_lead_id` and `registered_at` (if empty). It is a no-op when the event lead is already linked to a guest. diff --git a/solvway-services-counter/src/main/java/com/solvway/services/counter/service/RegistrationService.java b/solvway-services-counter/src/main/java/com/solvway/services/counter/service/RegistrationService.java index 395435b..7cbe3c2 100644 --- a/solvway-services-counter/src/main/java/com/solvway/services/counter/service/RegistrationService.java +++ b/solvway-services-counter/src/main/java/com/solvway/services/counter/service/RegistrationService.java @@ -112,7 +112,9 @@ public class RegistrationService { e.setCapturedBy(QR); e.setConsentAt(req.consentAt()); e.setConsentNoticeId(req.consentNoticeId()); - if (req.attend() || eventLeadService.isDuringEvent(req.eventUuid())) e.setAttendedAt(LocalDateTime.now()); + // An invite link can be opened anywhere, so an invite registration never counts as attending; the guest checks in. + boolean atVenue = !"INVITE".equals(req.source()) && eventLeadService.isDuringEvent(req.eventUuid()); + if (req.attend() || atVenue) e.setAttendedAt(LocalDateTime.now()); e = eventLeadRepository.saveAndFlush(e); eventLeadService.recordStatusChange(e, null, "OPEN", e.getCapturedAt(), QR); eventLeadService.saveInterests(e.getId(), req.companyId(), req.interestIds()); diff --git a/solvway-services-counter/src/test/java/com/solvway/services/counter/service/InviteRegistrationAttendanceTest.java b/solvway-services-counter/src/test/java/com/solvway/services/counter/service/InviteRegistrationAttendanceTest.java new file mode 100644 index 0000000..4f12d48 --- /dev/null +++ b/solvway-services-counter/src/test/java/com/solvway/services/counter/service/InviteRegistrationAttendanceTest.java @@ -0,0 +1,79 @@ +package com.solvway.services.counter.service; + +import com.solvway.services.counter.model.Event; +import com.solvway.services.counter.model.EventLead; +import com.solvway.services.counter.model.Lead; +import com.solvway.services.counter.repo.EventGuestRepository; +import com.solvway.services.counter.repo.EventLeadInterestRepository; +import com.solvway.services.counter.repo.EventLeadRepository; +import com.solvway.services.counter.repo.EventLeadStatusChangeRepository; +import com.solvway.services.counter.repo.EventRepository; +import com.solvway.services.counter.repo.LeadRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.support.TransactionTemplate; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.AdditionalAnswers.returnsFirstArg; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * Spec "Attendance at capture": staff capture, walk-in QR and check-in capture on the event days set attended. + * An invite link is personal and can be opened anywhere, so registering by invite never does: the guest checks in. + */ +class InviteRegistrationAttendanceTest { + + private static final long EVENT = 1000L; + private final EventLeadRepository eventLeads = mock(EventLeadRepository.class); + private RegistrationService registration; + + @BeforeEach + void setUp() { + LeadRepository leads = mock(LeadRepository.class); + EventRepository events = mock(EventRepository.class); + Event today = new Event(); + today.setDateStart(LocalDateTime.now().minusHours(1)); + today.setDateEnd(LocalDateTime.now().plusDays(1)); + when(events.findByUuid(EVENT)).thenReturn(Optional.of(today)); + when(leads.saveAndFlush(any(Lead.class))).then(returnsFirstArg()); + when(eventLeads.saveAndFlush(any(EventLead.class))).then(i -> { + EventLead e = i.getArgument(0); + e.setId(1L); + return e; + }); + GuestLinker linker = new GuestLinker(mock(EventGuestRepository.class)); + EventLeadService eventLeadService = new EventLeadService(leads, eventLeads, mock(EventLeadInterestRepository.class), + mock(EventLeadStatusChangeRepository.class), events, linker); + registration = new RegistrationService(new TransactionTemplate(mock(PlatformTransactionManager.class)), + leads, eventLeads, eventLeadService, linker); + } + + private EventLead saved() { + ArgumentCaptor c = ArgumentCaptor.forClass(EventLead.class); + verify(eventLeads).saveAndFlush(c.capture()); + return c.getValue(); + } + + @Test + void inviteRegistrationOnAnEventDayIsNotAttended() { + registration.register(new RegistrationService.RegisterRequest(42L, EVENT, 7L, "Tan", "+60125550101", null, null, null, + List.of(), null, null, false, "INVITE", null)); + assertThat(saved().getAttendedAt()).isNull(); + } + + @Test + void qrRegistrationOnAnEventDayIsAttended() { + registration.register(new RegistrationService.RegisterRequest(42L, EVENT, 7L, "Tan", "+60125550101", null, null, null, + List.of(), null, null)); + assertThat(saved().getAttendedAt()).isNotNull(); + } +}