feat: event days, guest linking, attendance and event headcount

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-01 16:41:37 +08:00
1 parent d7a11ab71c
commit 84bc0e5e11
22 files changed
+1036 -19

No files matched your search

@@ -0,0 +1,41 @@
package com.solvway.services.counter.model;
import jakarta.persistence.Column;
import jakarta.persistence.Table;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
/** EventGuest maps the event_guest table of 01-event-guests.sql. */
class EventGuestMappingTest {
@Test
void tableAndUniqueKeys() {
Table t = EventGuest.class.getAnnotation(Table.class);
assertThat(t.name()).isEqualTo("event_guest");
List<List<String>> uniques = Arrays.stream(t.uniqueConstraints()).map(u -> List.of(u.columnNames())).toList();
assertThat(uniques).containsExactlyInAnyOrder(List.of("token"), List.of("event_uuid", "mobile_e164"), List.of("event_uuid", "email"));
}
@Test
void columnNames() throws Exception {
assertThat(columnOf("eventUuid")).isEqualTo("event_uuid");
assertThat(columnOf("mobileE164")).isEqualTo("mobile_e164");
assertThat(columnOf("eventLeadId")).isEqualTo("event_lead_id");
assertThat(columnOf("salespersonUserId")).isEqualTo("salesperson_user_id");
assertThat(EventGuest.class.getDeclaredField("token").getAnnotation(Column.class).length()).isEqualTo(32);
for (String f : List.of("companyId", "name", "companyName", "token", "invitedAt", "inviteSentCount", "registeredAt",
"createdBy", "createdAt", "updatedBy", "updatedAt")) {
assertThat(EventGuest.class.getDeclaredField(f)).isNotNull();
}
assertThat(new EventGuest().getInviteSentCount()).isZero();
}
private static String columnOf(String field) throws Exception {
Field f = EventGuest.class.getDeclaredField(field);
return f.getAnnotation(Column.class).name();
}
}
@@ -0,0 +1,265 @@
package com.solvway.services.counter.service;
import com.solvway.services.counter.dto.EventLeadCaptureRequest;
import com.solvway.services.counter.dto.EventLeadUpdateRequest;
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.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.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
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.inOrder;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** Attendance stamped at capture (staff and QR), the attend flag, the staff edit toggle, and the guest link call. */
@ExtendWith(MockitoExtension.class)
class AttendanceAtCaptureTest {
private static final long COMPANY = 42L;
private static final long EVENT = 1000L;
@Mock private LeadRepository leadRepository;
@Mock private EventLeadRepository eventLeadRepository;
@Mock private EventLeadInterestRepository interestRepository;
@Mock private EventLeadStatusChangeRepository statusChangeRepository;
@Mock private EventRepository eventRepository;
@Mock private GuestLinker guestLinker;
private EventLeadService eventLeadService;
private RegistrationService registration;
@BeforeEach
void setUp() {
eventLeadService = new EventLeadService(leadRepository, eventLeadRepository, interestRepository, statusChangeRepository,
eventRepository, guestLinker);
registration = new RegistrationService(new TransactionTemplate(mock(PlatformTransactionManager.class)),
leadRepository, eventLeadRepository, eventLeadService, guestLinker);
lenient().when(leadRepository.saveAndFlush(any(Lead.class))).then(returnsFirstArg());
lenient().when(eventLeadRepository.saveAndFlush(any(EventLead.class))).then(i -> {
EventLead e = i.getArgument(0);
e.setId(1L);
return e;
});
}
private void eventDays(int startOffset, int endOffset) {
Event ev = new Event();
ev.setDateStart(LocalDateTime.now().plusDays(startOffset));
ev.setDateEnd(LocalDateTime.now().plusDays(endOffset));
lenient().when(eventRepository.findByUuid(EVENT)).thenReturn(Optional.of(ev));
}
private EventLead staffCapture() {
eventLeadService.capture(new EventLeadCaptureRequest(COMPANY, EVENT, null, "Aisyah", "+60123456789", null, null, null,
7L, null, null, List.of(), null, null, "sales1"));
ArgumentCaptor<EventLead> c = ArgumentCaptor.forClass(EventLead.class);
verify(eventLeadRepository).saveAndFlush(c.capture());
return c.getValue();
}
private static RegistrationService.RegisterRequest qr(boolean attend) {
return new RegistrationService.RegisterRequest(COMPANY, EVENT, 7L, "Aisyah", "+60123456789", null, null, null,
List.of(), null, null, attend);
}
private EventLead qrNewEventLead(boolean attend) {
lenient().when(leadRepository.findFirstByCompanyIdAndMobileE164OrderByIdDesc(COMPANY, "+60123456789")).thenReturn(Optional.empty());
registration.register(qr(attend));
ArgumentCaptor<EventLead> c = ArgumentCaptor.forClass(EventLead.class);
verify(eventLeadRepository).saveAndFlush(c.capture());
return c.getValue();
}
private EventLead existingCaptured(LocalDateTime attendedAt) {
Lead lead = new Lead();
lead.setCompanyId(COMPANY);
EventLead existing = new EventLead();
existing.setId(9L);
existing.setLeadUuid(lead.getUuid());
existing.setSalespersonUserId(7L);
existing.setAttendedAt(attendedAt);
when(leadRepository.findFirstByCompanyIdAndMobileE164OrderByIdDesc(COMPANY, "+60123456789")).thenReturn(Optional.of(lead));
when(eventLeadRepository.findByEventUuidAndLeadUuid(EVENT, lead.getUuid())).thenReturn(Optional.of(existing));
return existing;
}
// --- staff capture ---
@Test
void staffCaptureDuringEventDaysSetsAttendedAt() {
eventDays(-1, 1);
assertThat(staffCapture().getAttendedAt()).isNotNull();
}
private EventLead staffCaptureOfExistingLead() {
Lead crm = new Lead();
crm.setName("Aisyah");
lenient().when(leadRepository.findByUuidAndCompanyId(crm.getUuid(), COMPANY)).thenReturn(Optional.of(crm));
eventLeadService.capture(new EventLeadCaptureRequest(COMPANY, EVENT, crm.getUuid(), "Aisyah", null, null, null, null,
7L, null, null, List.of(), null, null, "sales1"));
ArgumentCaptor<EventLead> c = ArgumentCaptor.forClass(EventLead.class);
verify(eventLeadRepository).saveAndFlush(c.capture());
return c.getValue();
}
@Test
void staffCaptureOfExistingLeadDuringEventDaysSetsAttendedAt() {
eventDays(-1, 1);
assertThat(staffCaptureOfExistingLead().getAttendedAt()).isNotNull();
}
@Test
void staffCaptureOfExistingLeadBeforeEventDaysLeavesAttendedAtEmpty() {
eventDays(2, 3);
assertThat(staffCaptureOfExistingLead().getAttendedAt()).isNull();
}
@Test
void staffCaptureBeforeEventDaysLeavesAttendedAtEmpty() {
eventDays(2, 3);
assertThat(staffCapture().getAttendedAt()).isNull();
}
@Test
void staffCaptureLinksGuestAfterTheEventLeadIsSaved() {
eventDays(-1, 1);
EventLead e = staffCapture();
var order = inOrder(eventLeadRepository, guestLinker);
order.verify(eventLeadRepository).saveAndFlush(e);
order.verify(guestLinker).link(org.mockito.ArgumentMatchers.eq(EVENT), org.mockito.ArgumentMatchers.same(e), any(Lead.class));
}
// --- QR register ---
@Test
void qrNewDuringEventDaysSetsAttendedAt() {
eventDays(-1, 1);
assertThat(qrNewEventLead(false).getAttendedAt()).isNotNull();
}
@Test
void qrNewBeforeEventDaysLeavesAttendedAtEmpty() {
eventDays(2, 3);
assertThat(qrNewEventLead(false).getAttendedAt()).isNull();
}
@Test
void attendTrueSetsAttendedAtOnNewEvenOutsideEventDays() {
eventDays(2, 3);
assertThat(qrNewEventLead(true).getAttendedAt()).isNotNull();
}
@Test
void attendTrueSetsAttendedAtOnAlreadyCapturedAndSaves() {
EventLead existing = existingCaptured(null);
RegistrationService.RegisterResult r = registration.register(qr(true));
assertThat(r.outcome()).isEqualTo("ALREADY_CAPTURED");
assertThat(existing.getAttendedAt()).isNotNull();
verify(eventLeadRepository).save(existing);
}
@Test
void repeatRegistrationDuringEventDaysDoesNotSetAttendedAt() {
eventDays(-1, 1);
EventLead existing = existingCaptured(null);
registration.register(qr(false));
assertThat(existing.getAttendedAt()).isNull();
}
@Test
void attendTrueKeepsAnExistingAttendedAt() {
LocalDateTime earlier = LocalDateTime.of(2026, 12, 1, 9, 0);
EventLead existing = existingCaptured(earlier);
registration.register(qr(true));
assertThat(existing.getAttendedAt()).isEqualTo(earlier);
}
@Test
void qrRegisterLinksGuestForNewAndForAlreadyCaptured() {
eventDays(-1, 1);
EventLead existing = existingCaptured(null);
registration.register(qr(false));
verify(guestLinker).link(org.mockito.ArgumentMatchers.eq(EVENT), org.mockito.ArgumentMatchers.same(existing), any(Lead.class));
}
@Test
void qrRegisterNewLinksGuest() {
eventDays(-1, 1);
EventLead e = qrNewEventLead(false);
verify(guestLinker).link(org.mockito.ArgumentMatchers.eq(EVENT), org.mockito.ArgumentMatchers.same(e), any(Lead.class));
}
// --- staff edit ---
private EventLeadUpdateRequest update(Boolean attended) {
return new EventLeadUpdateRequest(COMPANY, 3L, null, null, null, List.of(), null, null, "sales2", attended);
}
private EventLead editable(LocalDateTime attendedAt) {
EventLead el = new EventLead();
el.setId(5L);
el.setAttendedAt(attendedAt);
lenient().when(eventLeadRepository.findByUuidAndCompanyId(3L, COMPANY)).thenReturn(Optional.of(el));
lenient().when(eventLeadRepository.saveAndFlush(el)).thenReturn(el);
lenient().when(leadRepository.findByUuidAndCompanyId(el.getLeadUuid(), COMPANY)).thenReturn(Optional.of(new Lead()));
return el;
}
@Test
void updateAttendedTrueSetsTimeWhenEmpty() {
EventLead el = editable(null);
eventLeadService.update(update(true));
assertThat(el.getAttendedAt()).isNotNull();
}
@Test
void updateAttendedTrueKeepsExistingTime() {
LocalDateTime earlier = LocalDateTime.of(2026, 12, 1, 9, 0);
EventLead el = editable(earlier);
eventLeadService.update(update(true));
assertThat(el.getAttendedAt()).isEqualTo(earlier);
}
@Test
void updateAttendedFalseClears() {
EventLead el = editable(LocalDateTime.of(2026, 12, 1, 9, 0));
eventLeadService.update(update(false));
assertThat(el.getAttendedAt()).isNull();
}
@Test
void updateAttendedNullLeavesUnchanged() {
LocalDateTime earlier = LocalDateTime.of(2026, 12, 1, 9, 0);
EventLead el = editable(earlier);
eventLeadService.update(update(null));
assertThat(el.getAttendedAt()).isEqualTo(earlier);
}
}
@@ -0,0 +1,79 @@
package com.solvway.services.counter.service;
import com.solvway.services.counter.model.Event;
import com.solvway.services.counter.repo.EventGuestRepository;
import com.solvway.services.counter.repo.EventLeadRepository;
import com.solvway.services.counter.repo.EventRepository;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.web.server.ResponseStatusException;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class EventHeadcountServiceTest {
private static final long COMPANY = 42L;
private static final long EVENT = 1000L;
@Mock private EventRepository eventRepository;
@Mock private EventGuestRepository guestRepository;
@Mock private EventLeadRepository eventLeadRepository;
private EventHeadcountService service() {
return new EventHeadcountService(eventRepository, guestRepository, eventLeadRepository);
}
@Test
void reportsTheNumbers() {
Event e = new Event();
e.setCompanyId(COMPANY);
e.setCapacity(100);
e.setInvitationCap(50);
when(eventRepository.findByUuid(EVENT)).thenReturn(Optional.of(e));
when(guestRepository.countByEventUuid(EVENT)).thenReturn(40L);
when(guestRepository.countByEventUuidAndEventLeadIdIsNotNull(EVENT)).thenReturn(30L);
when(eventLeadRepository.countByEventUuidAndAttendedAtIsNotNull(EVENT)).thenReturn(35L);
when(eventLeadRepository.countWalkIns(EVENT)).thenReturn(15L);
EventHeadcountService.Headcount h = service().headcount(new EventHeadcountService.Request(COMPANY, EVENT));
assertThat(h).isEqualTo(new EventHeadcountService.Headcount(40, 50, 30, 35, 15, 45, 100));
}
@Test
void nullCapAndCapacityStayNull() {
Event e = new Event();
e.setCompanyId(COMPANY);
when(eventRepository.findByUuid(EVENT)).thenReturn(Optional.of(e));
EventHeadcountService.Headcount h = service().headcount(new EventHeadcountService.Request(COMPANY, EVENT));
assertThat(h.cap()).isNull();
assertThat(h.capacity()).isNull();
assertThat(h.total()).isZero();
}
@Test
void eventOfAnotherCompanyIs404() {
Event e = new Event();
e.setCompanyId(99L);
when(eventRepository.findByUuid(EVENT)).thenReturn(Optional.of(e));
assertThatThrownBy(() -> service().headcount(new EventHeadcountService.Request(COMPANY, EVENT)))
.isInstanceOfSatisfying(ResponseStatusException.class, ex -> assertThat(ex.getStatusCode().value()).isEqualTo(404));
}
@Test
void unknownEventIs404() {
when(eventRepository.findByUuid(EVENT)).thenReturn(Optional.empty());
assertThatThrownBy(() -> service().headcount(new EventHeadcountService.Request(COMPANY, EVENT)))
.isInstanceOfSatisfying(ResponseStatusException.class, ex -> assertThat(ex.getStatusCode().value()).isEqualTo(404));
}
}
@@ -0,0 +1,99 @@
package com.solvway.services.counter.service;
import com.solvway.services.counter.model.Event;
import com.solvway.services.counter.repo.EventGuestRepository;
import com.solvway.services.counter.repo.EventRepository;
import com.solvway.services.counter.util.redis.RedisUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.web.server.ResponseStatusException;
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.Mockito.lenient;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** Event capacity and invitation cap on save. */
@ExtendWith(MockitoExtension.class)
class EventSettingsTest {
@Mock private EventRepository eventRepository;
@Mock private RedisUtil<Event> redisUtil;
@Mock private EventGuestRepository guestRepository;
private EventService service;
@BeforeEach
void setUp() {
service = new EventService(eventRepository, redisUtil, guestRepository);
lenient().when(eventRepository.save(any(Event.class))).thenAnswer(i -> i.getArgument(0));
}
private static Event event(Long id, Integer capacity, Integer cap) {
Event e = new Event();
e.setId(id);
e.setCompanyId(7L);
e.setCapacity(capacity);
e.setInvitationCap(cap);
return e;
}
private void assertRejected(Event e, int status, String reason) {
assertThatThrownBy(() -> service.save(e)).isInstanceOfSatisfying(ResponseStatusException.class, ex -> {
assertThat(ex.getStatusCode().value()).isEqualTo(status);
assertThat(ex.getReason()).isEqualTo(reason);
});
verify(eventRepository, never()).save(any(Event.class));
}
@Test
void nullAndPositiveValuesAreAccepted() {
assertThat(service.save(event(null, null, null)).getCapacity()).isNull();
Event saved = service.save(event(null, 100, 1));
assertThat(saved.getCapacity()).isEqualTo(100);
assertThat(saved.getInvitationCap()).isEqualTo(1);
}
@Test
void capacityBelowOneIsRefused() {
assertRejected(event(null, 0, null), 400, "CAPACITY_INVALID");
}
@Test
void invitationCapBelowOneIsRefused() {
assertRejected(event(null, null, -3), 400, "INVITATION_CAP_INVALID");
}
@Test
void capBelowCurrentGuestCountIsConflict() {
Event stored = event(5L, null, null);
when(eventRepository.findById(5L)).thenReturn(Optional.of(stored));
when(guestRepository.countByEventUuid(stored.getUuid())).thenReturn(40L);
assertRejected(event(5L, null, 39), 409, "CAP_BELOW_GUESTS");
}
@Test
void capEqualToGuestCountIsAccepted() {
Event stored = event(5L, null, null);
when(eventRepository.findById(5L)).thenReturn(Optional.of(stored));
when(guestRepository.countByEventUuid(stored.getUuid())).thenReturn(40L);
assertThat(service.save(event(5L, null, 40)).getInvitationCap()).isEqualTo(40);
}
@Test
void eventExposesTheTwoFieldsAsJsonProperties() throws Exception {
Event e = event(1L, 100, 50);
var json = new com.fasterxml.jackson.databind.ObjectMapper().findAndRegisterModules().valueToTree(e);
assertThat(json.get("capacity").asInt()).isEqualTo(100);
assertThat(json.get("invitationCap").asInt()).isEqualTo(50);
}
}
@@ -0,0 +1,103 @@
package com.solvway.services.counter.service;
import com.solvway.services.counter.model.EventGuest;
import com.solvway.services.counter.model.EventLead;
import com.solvway.services.counter.model.Lead;
import com.solvway.services.counter.repo.EventGuestRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.time.LocalDateTime;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class GuestLinkerTest {
private static final long EVENT = 1000L;
private static final String MOBILE = "+60123456789";
private static final String EMAIL = "aisyah@example.com";
@Mock private EventGuestRepository guests;
private GuestLinker linker;
@BeforeEach
void setUp() {
linker = new GuestLinker(guests);
lenient().when(guests.findFirstByEventUuidAndEventLeadIdIsNullAndMobileE164(any(Long.class), any())).thenReturn(Optional.empty());
lenient().when(guests.findFirstByEventUuidAndEventLeadIdIsNullAndEmail(any(Long.class), any())).thenReturn(Optional.empty());
}
private static EventLead eventLead() {
EventLead e = new EventLead();
e.setId(55L);
return e;
}
private static Lead lead(String mobile, String email) {
Lead l = new Lead();
l.setMobileE164(mobile);
l.setEmailNormalised(email);
return l;
}
@Test
void linksByMobileAndStampsRegisteredAt() {
EventGuest g = new EventGuest();
when(guests.findFirstByEventUuidAndEventLeadIdIsNullAndMobileE164(EVENT, MOBILE)).thenReturn(Optional.of(g));
linker.link(EVENT, eventLead(), lead(MOBILE, EMAIL));
assertThat(g.getEventLeadId()).isEqualTo(55L);
assertThat(g.getRegisteredAt()).isNotNull();
verify(guests).save(g);
verify(guests, never()).findFirstByEventUuidAndEventLeadIdIsNullAndEmail(any(Long.class), any());
}
@Test
void fallsBackToEmailWhenNoMobileMatch() {
EventGuest g = new EventGuest();
when(guests.findFirstByEventUuidAndEventLeadIdIsNullAndEmail(EVENT, EMAIL)).thenReturn(Optional.of(g));
linker.link(EVENT, eventLead(), lead(MOBILE, EMAIL));
assertThat(g.getEventLeadId()).isEqualTo(55L);
verify(guests).save(g);
}
@Test
void keepsExistingRegisteredAt() {
EventGuest g = new EventGuest();
LocalDateTime earlier = LocalDateTime.of(2026, 12, 1, 9, 0);
g.setRegisteredAt(earlier);
when(guests.findFirstByEventUuidAndEventLeadIdIsNullAndEmail(EVENT, EMAIL)).thenReturn(Optional.of(g));
linker.link(EVENT, eventLead(), lead(null, EMAIL));
assertThat(g.getRegisteredAt()).isEqualTo(earlier);
}
@Test
void noOpWhenEventLeadAlreadyLinked() {
when(guests.existsByEventLeadId(55L)).thenReturn(true);
linker.link(EVENT, eventLead(), lead(MOBILE, EMAIL));
verify(guests, never()).save(any());
verify(guests, never()).findFirstByEventUuidAndEventLeadIdIsNullAndMobileE164(any(Long.class), any());
}
@Test
void noGuestNothingSaved() {
linker.link(EVENT, eventLead(), lead(MOBILE, EMAIL));
verify(guests, never()).save(any());
}
}
@@ -0,0 +1,43 @@
package com.solvway.services.counter.service;
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 com.solvway.services.counter.util.redis.RedisUtil;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.transaction.support.TransactionTemplate;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/** Spring must pick the full constructors, so production always gets the linker and the extra repositories. */
class InvitationWiringTest {
private static <T> void mockBean(AnnotationConfigApplicationContext ctx, Class<T> c) {
ctx.registerBean(c, () -> mock(c));
}
@Test
void servicesAreWiredWithTheirFullDependencies() {
try (var ctx = new AnnotationConfigApplicationContext()) {
for (Class<?> c : new Class<?>[]{LeadRepository.class, EventLeadRepository.class, EventLeadInterestRepository.class,
EventLeadStatusChangeRepository.class, EventRepository.class, EventGuestRepository.class,
RedisUtil.class, TransactionTemplate.class}) {
mockBean(ctx, c);
}
ctx.register(GuestLinker.class, EventLeadService.class, RegistrationService.class, EventService.class,
EventHeadcountService.class);
ctx.refresh();
assertThat(ReflectionTestUtils.getField(ctx.getBean(EventLeadService.class), "guestLinker")).isNotNull();
assertThat(ReflectionTestUtils.getField(ctx.getBean(EventLeadService.class), "eventRepository")).isNotNull();
assertThat(ReflectionTestUtils.getField(ctx.getBean(RegistrationService.class), "guestLinker")).isNotNull();
assertThat(ReflectionTestUtils.getField(ctx.getBean(EventService.class), "guestRepository")).isNotNull();
assertThat(ctx.getBean(EventHeadcountService.class)).isNotNull();
}
}
}
@@ -0,0 +1,67 @@
package com.solvway.services.counter.service;
import com.solvway.core.enums.GeneralEnum;
import com.solvway.services.counter.model.Event;
import com.solvway.services.counter.model.EventSalesperson;
import com.solvway.services.counter.model.RegistrationLink;
import com.solvway.services.counter.repo.EventRepository;
import com.solvway.services.counter.repo.EventSalespersonRepository;
import com.solvway.services.counter.repo.RegistrationLinkRepository;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.lang.reflect.Field;
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.anyCollection;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class RegistrationLinkMineAddedAtTest {
@Mock private RegistrationLinkRepository linkRepository;
@Mock private EventRepository eventRepository;
@Mock private EventSalespersonRepository eventSalespersonRepository;
@Test
void mineReturnsTheTeamRowCreateTimeAsAddedAt() throws Exception {
LocalDateTime added = LocalDateTime.of(2026, 11, 20, 14, 30);
assertThat(mineAddedAt(added)).isEqualTo(added.toString());
}
@Test
void mineReturnsNullAddedAtWhenCreateTimeIsMissing() throws Exception {
assertThat(mineAddedAt(null)).isNull();
}
private String mineAddedAt(LocalDateTime added) throws Exception {
EventSalesperson row = new EventSalesperson();
row.setEventUuid(1L);
row.setCreateDateTime(added);
when(eventSalespersonRepository.findByCompanyIdAndUserId(42L, 7L)).thenReturn(List.of(row));
Event ev = new Event();
Field uuid = Event.class.getDeclaredField("uuid");
uuid.setAccessible(true);
uuid.set(ev, 1L);
ev.setCompanyId(42L);
ev.setName("Expo");
ev.setEnabled(GeneralEnum.FlagYesNo.Y);
ev.setDateEnd(LocalDateTime.of(2026, 12, 12, 18, 0));
when(eventRepository.findByCompanyIdAndUuidIn(eq(42L), anyCollection())).thenReturn(List.of(ev));
RegistrationLink link = new RegistrationLink();
link.setToken("T");
when(linkRepository.findFirstByEventUuidAndSalespersonUserIdOrderByIdAsc(anyLong(), eq(7L))).thenReturn(Optional.of(link));
var out = new RegistrationLinkService(linkRepository, eventRepository, eventSalespersonRepository)
.mine(new RegistrationLinkService.MineRequest(42L, 7L, "2026-12-01"));
assertThat(out).hasSize(1);
return out.get(0).addedAt();
}
}
@@ -0,0 +1,51 @@
package com.solvway.services.counter.util;
import com.solvway.services.counter.model.Event;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import static org.assertj.core.api.Assertions.assertThat;
class EventDaysTest {
private static Event event(LocalDateTime start, LocalDateTime end) {
Event e = new Event();
e.setDateStart(start);
e.setDateEnd(end);
return e;
}
private static final Event EVENT = event(LocalDateTime.of(2026, 12, 5, 18, 0), LocalDateTime.of(2026, 12, 7, 9, 0));
@Test
void firstDayCountsEvenBeforeTheStartTime() {
assertThat(EventDays.isDuring(EVENT, LocalDateTime.of(2026, 12, 5, 0, 1))).isTrue();
}
@Test
void lastDayCountsEvenAfterTheEndTime() {
assertThat(EventDays.isDuring(EVENT, LocalDateTime.of(2026, 12, 7, 23, 59))).isTrue();
}
@Test
void dayBeforeDoesNotCount() {
assertThat(EventDays.isDuring(EVENT, LocalDateTime.of(2026, 12, 4, 23, 59))).isFalse();
}
@Test
void dayAfterDoesNotCount() {
assertThat(EventDays.isDuring(EVENT, LocalDateTime.of(2026, 12, 8, 0, 0))).isFalse();
}
@Test
void nullStartOnlyTheEndCounts() {
Event e = event(null, LocalDateTime.of(2026, 12, 7, 9, 0));
assertThat(EventDays.isDuring(e, LocalDateTime.of(2020, 1, 1, 0, 0))).isTrue();
assertThat(EventDays.isDuring(e, LocalDateTime.of(2026, 12, 8, 0, 0))).isFalse();
}
@Test
void nullEndIsNeverDuring() {
assertThat(EventDays.isDuring(event(LocalDateTime.of(2026, 12, 5, 18, 0), null), LocalDateTime.of(2026, 12, 5, 19, 0))).isFalse();
}
}