feat: event lead rows carry attendance and source, with an attended filter

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 21:31:03 +08:00
1 parent cba2929a00
commit 3af5cccd59
16 files changed
+160 -55

No files matched your search

@@ -85,15 +85,15 @@ class AdminEventLeadControllerTest {
@Test
void listPassesFiltersAndPaging() throws Exception {
when(eventLeads.list(EV, 21L, "HOT", "OPEN", 3L, "NEW", 1, 25, null)).thenReturn(Map.of("content", List.of(), "totalElements", 0));
when(eventLeads.list(EV, 21L, "HOT", "OPEN", 3L, "NEW", false, 1, 25, null)).thenReturn(Map.of("content", List.of(), "totalElements", 0));
mvc.perform(get("/api/admin/event-leads/" + EV + "/leads").param("salespersonId", "21").param("temperature", "HOT")
.param("status", "OPEN").param("interestId", "3").param("leadType", "NEW").param("page", "1").param("size", "25"))
.param("status", "OPEN").param("interestId", "3").param("leadType", "NEW").param("attended", "false").param("page", "1").param("size", "25"))
.andExpect(status().isOk());
verify(eventLeads).list(EV, 21L, "HOT", "OPEN", 3L, "NEW", 1, 25, null);
verify(eventLeads).list(EV, 21L, "HOT", "OPEN", 3L, "NEW", false, 1, 25, null);
when(eventLeads.list(EV, null, null, null, null, null, 0, 20, null)).thenReturn(Map.of("content", List.of()));
when(eventLeads.list(EV, null, null, null, null, null, null, 0, 20, null)).thenReturn(Map.of("content", List.of()));
mvc.perform(get("/api/admin/event-leads/" + EV + "/leads")).andExpect(status().isOk());
verify(eventLeads).list(EV, null, null, null, null, null, 0, 20, null);
verify(eventLeads).list(EV, null, null, null, null, null, null, 0, 20, null);
}
@Test
@@ -56,10 +56,10 @@ class AdminLeadExportControllerTest {
@Test
void eventLeadExportPassesFiltersAndNamesTheFile() throws Exception {
AdminEventLeadService svc = mock(AdminEventLeadService.class);
when(svc.export("77", 22L, "HOT", "OPEN", 3L, "NEW", null)).thenReturn(new byte[]{9});
when(svc.export("77", 22L, "HOT", "OPEN", 3L, "NEW", true, null)).thenReturn(new byte[]{9});
MockMvc mvc = MockMvcBuilders.standaloneSetup(new AdminEventLeadExportController(svc)).build();
mvc.perform(get("/api/admin/event-leads/77/export").param("salespersonId", "22").param("temperature", "HOT")
.param("status", "OPEN").param("interestId", "3").param("leadType", "NEW")).andExpect(status().isOk())
.param("status", "OPEN").param("interestId", "3").param("leadType", "NEW").param("attended", "true")).andExpect(status().isOk())
.andExpect(header().string("Content-Type", XLSX))
.andExpect(header().string("Content-Disposition", org.hamcrest.Matchers.matchesPattern("attachment; filename=\"event-leads-77-\\d{8}-\\d{4}\\.xlsx\"")))
.andExpect(content().bytes(new byte[]{9}));
@@ -70,7 +70,7 @@ class AdminLeadExportControllerTest {
// The service accepts " 77\r\n" (it trims before parsing); none of those characters may reach the header.
AdminEventLeadService svc = mock(AdminEventLeadService.class);
when(svc.export(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(),
org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any())).thenReturn(new byte[]{9});
org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any())).thenReturn(new byte[]{9});
MockMvc mvc = MockMvcBuilders.standaloneSetup(new AdminEventLeadExportController(svc)).build();
mvc.perform(get("/api/admin/event-leads/{uuid}/export", " 77\r\n")).andExpect(status().isOk())
.andExpect(header().string("Content-Disposition", org.hamcrest.Matchers.matchesPattern("attachment; filename=\"event-leads-77-\\d{8}-\\d{4}\\.xlsx\"")));
@@ -113,6 +113,8 @@ class AdminEventLeadExportTest {
r.put("status", "QUALIFIED");
r.put("nextFollowUpDate", "2027-01-20");
r.put("interestIds", List.of(3, 5));
r.put("attendedAt", i % 2 == 0 ? "2027-01-20T09:30:00" : null);
r.put("source", i % 2 == 0 ? "QR" : "INVITE");
return r;
}
@@ -127,7 +129,7 @@ class AdminEventLeadExportTest {
}
private byte[] export() {
return service.export(String.valueOf(EV), 22L, "HOT", null, 3L, null, null);
return service.export(String.valueOf(EV), 22L, "HOT", null, 3L, null, true, null);
}
private static Sheet sheet(byte[] bytes) throws Exception {
@@ -141,7 +143,7 @@ class AdminEventLeadExportTest {
assertThat(s.getSheetName()).isEqualTo("Event leads");
List<String> header = new ArrayList<>();
s.getRow(0).forEach(c -> header.add(c.getStringCellValue()));
assertThat(header).containsExactly("Name", "Mobile", "Email", "Lead type", "Salesperson", "Temperature", "Status", "Interests", "Next follow-up");
assertThat(header).containsExactly("Name", "Mobile", "Email", "Lead type", "Salesperson", "Temperature", "Status", "Interests", "Next follow-up", "Attended", "Source");
assertThat(s.getLastRowNum()).isEqualTo(2);
}
@@ -163,6 +165,10 @@ class AdminEventLeadExportTest {
assertThat(DateUtil.isCellDateFormatted(d)).isTrue();
assertThat(d.getCellStyle().getDataFormatString()).isEqualTo("dd/mm/yyyy");
assertThat(d.getDateCellValue().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate()).isEqualTo(LocalDate.of(2027, 1, 20));
assertThat(r.getCell(9).getStringCellValue()).isEqualTo("Yes");
assertThat(r.getCell(10).getStringCellValue()).isEqualTo("QR");
assertThat(s.getRow(2).getCell(9).getStringCellValue()).isEqualTo("No");
assertThat(s.getRow(2).getCell(10).getStringCellValue()).isEqualTo("Invite");
}
@Test
@@ -187,7 +193,7 @@ class AdminEventLeadExportTest {
verify(rest, times(3)).postForEntity(eq(SEARCH), any(ParameterizedTypeReference.class), bodies.capture());
for (Object b : bodies.getAllValues()) {
assertThat((Map<String, Object>) b).containsEntry("size", 100).containsEntry("eventUuid", EV).containsEntry("salespersonUserId", 22L)
.containsEntry("temperature", "HOT").containsEntry("interestId", 3L);
.containsEntry("temperature", "HOT").containsEntry("interestId", 3L).containsEntry("attended", true);
}
verify(rest, times(1)).getForEntity(eq(EVENT), any(ParameterizedTypeReference.class), eq(EV));
verify(rest, times(1)).getForEntity(eq(INTERESTS), any(ParameterizedTypeReference.class), eq(COMPANY));
@@ -209,7 +215,7 @@ class AdminEventLeadExportTest {
@Test
void invalidFilterIsStillRejectedBeforeAnything() {
assertThatThrownBy(() -> service.export(String.valueOf(EV), null, "BOILING", null, null, null, null))
assertThatThrownBy(() -> service.export(String.valueOf(EV), null, "BOILING", null, null, null, null, null))
.isInstanceOfSatisfying(CodedResponseStatusException.class, e -> assertThat(e.getCode()).isEqualTo("INVALID_VALUE"));
}
@@ -193,8 +193,8 @@ class AdminEventLeadServiceCompanyScopeTest {
void list_andExport_otherCompanysEventIsNotFoundForStaff() {
caller(5L, false);
stubEvent(9L);
assertEventNotFound(() -> service.list(String.valueOf(EV), null, null, null, null, null, 0, 20, null));
assertEventNotFound(() -> service.export(String.valueOf(EV), null, null, null, null, null, 9L));
assertEventNotFound(() -> service.list(String.valueOf(EV), null, null, null, null, null, null, 0, 20, null));
assertEventNotFound(() -> service.export(String.valueOf(EV), null, null, null, null, null, null, 9L));
verify(rest, never()).postForEntity(eq(SEARCH), any(ParameterizedTypeReference.class), any());
}
@@ -202,7 +202,7 @@ class AdminEventLeadServiceCompanyScopeTest {
void list_staffIgnoresRequestedCompany() {
caller(5L, false);
stubEvent(5L);
service.list(String.valueOf(EV), null, null, null, null, null, 0, 20, 9L);
service.list(String.valueOf(EV), null, null, null, null, null, null, 0, 20, 9L);
assertThat(sentOnce(SEARCH)).containsEntry("companyId", 5L).containsEntry("eventUuid", EV);
}
@@ -210,15 +210,15 @@ class AdminEventLeadServiceCompanyScopeTest {
void list_andExport_superRequestingAnotherCompanyThanTheEventsIsNotFound() {
caller(null, true);
stubEvent(9L);
assertEventNotFound(() -> service.list(String.valueOf(EV), null, null, null, null, null, 0, 20, 7L));
assertEventNotFound(() -> service.export(String.valueOf(EV), null, null, null, null, null, 7L));
assertEventNotFound(() -> service.list(String.valueOf(EV), null, null, null, null, null, null, 0, 20, 7L));
assertEventNotFound(() -> service.export(String.valueOf(EV), null, null, null, null, null, null, 7L));
}
@Test
void list_andExport_superWithoutCompanyUsesTheEventsCompany() {
caller(null, true);
stubEvent(9L);
service.list(String.valueOf(EV), null, null, null, null, null, 0, 20, null);
service.list(String.valueOf(EV), null, null, null, null, null, null, 0, 20, null);
assertThat(sentOnce(SEARCH)).containsEntry("companyId", 9L);
}
@@ -226,7 +226,7 @@ class AdminEventLeadServiceCompanyScopeTest {
void export_staffGetsOwnEventsRowsOnly() {
caller(5L, false);
stubEvent(5L);
service.export(String.valueOf(EV), null, null, null, null, null, 9L);
service.export(String.valueOf(EV), null, null, null, null, null, null, 9L);
assertThat(sentOnce(SEARCH)).containsEntry("companyId", 5L);
}
@@ -159,6 +159,7 @@ class AdminEventLeadServiceTest {
d.put("leadType", "NEW");
d.put("salespersonUserId", salespersonUserId);
d.put("status", "OPEN");
d.put("source", "STAFF");
d.put("interestIds", interestIds);
when(rest.getForEntity(eq(FIND), any(ParameterizedTypeReference.class), eq(EL))).thenReturn(ResponseEntity.ok(d));
}
@@ -369,7 +370,7 @@ class AdminEventLeadServiceTest {
when(rest.getForEntity(eq(EVENT), any(ParameterizedTypeReference.class), eq(1L))).thenReturn(ResponseEntity.ok().build());
assertCoded(() -> service.capture("1", capture(null, "Aisyah", "0123456789", null)), HttpStatus.NOT_FOUND, "EVENT_NOT_FOUND", null);
assertCoded(() -> service.list("not-a-number", null, null, null, null, null, 0, 20, null), HttpStatus.NOT_FOUND, "EVENT_NOT_FOUND", null);
assertCoded(() -> service.list("not-a-number", null, null, null, null, null, null, 0, 20, null), HttpStatus.NOT_FOUND, "EVENT_NOT_FOUND", null);
}
// --- salesperson from the team ---
@@ -485,7 +486,7 @@ class AdminEventLeadServiceTest {
when(rest.postForEntity(eq(SEARCH), any(ParameterizedTypeReference.class), any()))
.thenReturn(ResponseEntity.ok(Map.of("content", List.of(row), "totalElements", 1, "totalPages", 1, "number", 0, "size", 20)));
Map<String, Object> out = service.list(String.valueOf(EV), 22L, "HOT", "OPEN", 3L, "EXISTING", 0, 20, null);
Map<String, Object> out = service.list(String.valueOf(EV), 22L, "HOT", "OPEN", 3L, "EXISTING", null, 0, 20, null);
assertThat(sent(SEARCH)).containsEntry("companyId", COMPANY).containsEntry("eventUuid", EV).containsEntry("salespersonUserId", 22L)
.containsEntry("temperature", "HOT").containsEntry("status", "OPEN").containsEntry("interestId", 3L)
@@ -516,6 +517,37 @@ class AdminEventLeadServiceTest {
assertCoded(() -> service.get(String.valueOf(EV), String.valueOf(EL)), HttpStatus.NOT_FOUND, "EVENT_LEAD_NOT_FOUND", null);
}
@Test
void listingSendsAttendedFilterAndRowsShowAttendedAndSource() {
Map<String, Object> yes = new LinkedHashMap<>();
yes.put("eventLeadUuid", EL);
yes.put("eventUuid", EV);
yes.put("name", "Aisyah");
yes.put("attendedAt", "2027-01-20T09:30:00");
yes.put("source", "QR");
Map<String, Object> no = new LinkedHashMap<>(yes);
no.put("attendedAt", null);
no.put("source", "INVITE");
when(rest.postForEntity(eq(SEARCH), any(ParameterizedTypeReference.class), any()))
.thenReturn(ResponseEntity.ok(Map.of("content", List.of(yes, no), "totalElements", 2, "totalPages", 1, "number", 0, "size", 20)));
Map<String, Object> out = service.list(String.valueOf(EV), null, null, null, null, null, true, 0, 20, null);
assertThat(sent(SEARCH)).containsEntry("attended", true);
List<Map<String, Object>> rows = (List<Map<String, Object>>) out.get("content");
assertThat(rows.get(0)).containsEntry("attended", true).containsEntry("source", "QR");
assertThat(rows.get(1)).containsEntry("attended", false).containsEntry("source", "INVITE");
}
@Test
void getShowsAttendedAndSource() {
stubStored(EV, 21L, List.of(4L));
Map<String, Object> out = service.get(String.valueOf(EV), String.valueOf(EL));
assertThat(out).containsEntry("attended", false).containsEntry("source", "STAFF");
}
@Test
void getShowsSalespersonAndInterestsByName() {
stubStored(EV, 21L, List.of(4L));