feat(mobile-api): xlsx export of the lead and event lead listings
Same columns and filters as the screen, all pages, refused above 20,000 rows. Mobiles are text and dates are dates. Each export is logged with user, listing and row count only. Adds poi-ooxml 4.1.0, as in services-system. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
963735d524
commit
eab4053c06
11 files changed
+729
-21
No files matched your search
+78
@@ -0,0 +1,78 @@
|
||||
package com.solvway.mobile.api.controller.admin;
|
||||
|
||||
import com.solvway.core.annotation.AppAuth;
|
||||
import com.solvway.mobile.api.service.AdminEventLeadService;
|
||||
import com.solvway.mobile.api.service.AdminLeadService;
|
||||
import com.solvway.mobile.api.useraccess.AdminModule;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
class AdminLeadExportControllerTest {
|
||||
private static final String XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||
|
||||
private static Method export(Class<?> c) {
|
||||
return Arrays.stream(c.getDeclaredMethods()).filter(m -> m.getName().equals("export")).findFirst().orElseThrow();
|
||||
}
|
||||
|
||||
@Test
|
||||
void leadExportNeedsExportAndBoLeads() {
|
||||
Method m = export(AdminLeadController.class);
|
||||
assertThat(m.isAnnotationPresent(AppAuth.class)).isTrue();
|
||||
assertThat(m.getAnnotation(AdminModule.class).value()).containsExactly("BO_LEADS_EXPORT");
|
||||
assertThat(m.getAnnotation(AdminModule.class).also()).containsExactly("BO_LEADS");
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventLeadExportNeedsExportAndBoEventLeads() {
|
||||
Method m = export(AdminEventLeadExportController.class);
|
||||
assertThat(m.isAnnotationPresent(AppAuth.class)).isTrue();
|
||||
assertThat(m.getAnnotation(AdminModule.class).value()).containsExactly("BO_LEADS_EXPORT");
|
||||
assertThat(m.getAnnotation(AdminModule.class).also()).containsExactly("BO_EVENT_LEADS");
|
||||
}
|
||||
|
||||
@Test
|
||||
void leadExportReturnsTheFileWithHeaders() throws Exception {
|
||||
AdminLeadService leads = mock(AdminLeadService.class);
|
||||
when(leads.export("ai")).thenReturn(new byte[]{1, 2, 3});
|
||||
MockMvc mvc = MockMvcBuilders.standaloneSetup(new AdminLeadController(leads)).build();
|
||||
mvc.perform(get("/api/admin/leads/export").param("q", "ai")).andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Type", XLSX))
|
||||
.andExpect(header().string("Content-Disposition", org.hamcrest.Matchers.matchesPattern("attachment; filename=\"leads-\\d{8}-\\d{4}\\.xlsx\"")))
|
||||
.andExpect(content().bytes(new byte[]{1, 2, 3}));
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventLeadExportPassesFiltersAndNamesTheFile() throws Exception {
|
||||
AdminEventLeadService svc = mock(AdminEventLeadService.class);
|
||||
when(svc.export("77", 22L, "HOT", "OPEN", 3L, "NEW")).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())
|
||||
.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}));
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventLeadExportFilenameKeepsOnlyTheUuidDigits() throws Exception {
|
||||
// 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())).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\"")));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user