feat: admin guest, invite email, check-in and attendance endpoints
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
4e938bb6a9
commit
87dfc48632
19 files changed
+1361
-7
No files matched your search
+116
@@ -0,0 +1,116 @@
|
||||
package com.solvway.mobile.api.controller.admin;
|
||||
|
||||
import com.solvway.core.annotation.AppAuth;
|
||||
import com.solvway.mobile.api.dto.admin.AdminGuestSendRequest;
|
||||
import com.solvway.mobile.api.dto.admin.AdminGuestsRequest;
|
||||
import com.solvway.mobile.api.service.AdminEventGuestService;
|
||||
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.ArgumentCaptor;
|
||||
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 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.delete;
|
||||
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.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AdminEventGuestControllerTest {
|
||||
|
||||
@Mock private AdminEventGuestService guests;
|
||||
@InjectMocks private AdminEventGuestController controller;
|
||||
private MockMvc mvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mvc = MockMvcBuilders.standaloneSetup(controller).build();
|
||||
}
|
||||
|
||||
private static List<Method> handlers() {
|
||||
return Arrays.stream(AdminEventGuestController.class.getDeclaredMethods())
|
||||
.filter(m -> Modifier.isPublic(m.getModifiers()) && !m.isSynthetic()).toList();
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsAreGuardedByBoEventsAndWritesByBoEventGuests() {
|
||||
assertThat(handlers()).hasSize(6);
|
||||
for (Method m : handlers()) {
|
||||
assertThat(m.isAnnotationPresent(AppAuth.class)).as(m.getName() + " @AppAuth").isTrue();
|
||||
String expected = Arrays.asList("list", "checkin", "attendance").contains(m.getName()) ? "BO_EVENTS" : "BO_EVENT_GUESTS";
|
||||
AdminModule module = m.getAnnotation(AdminModule.class);
|
||||
assertThat(Arrays.asList(module.value())).as(m.getName()).containsExactly(expected);
|
||||
// writes are a sub-module: they need BO_EVENTS too, like the other event sub-modules
|
||||
assertThat(Arrays.asList(module.also())).as(m.getName() + " also").isEqualTo(expected.equals("BO_EVENTS") ? List.of() : List.of("BO_EVENTS"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void everyGuestWriteIsAuditedAgainstTheEventUuid() {
|
||||
for (Method m : handlers()) {
|
||||
if (Arrays.asList("list", "checkin", "attendance").contains(m.getName())) continue;
|
||||
Audited a = m.getAnnotation(Audited.class);
|
||||
assertThat(a).as(m.getName() + " @Audited").isNotNull();
|
||||
assertThat(a.targetVariable()).as(m.getName()).isEqualTo("uuid");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_checkin_attendance() throws Exception {
|
||||
when(guests.list("77")).thenReturn(List.of(Map.of("id", 1)));
|
||||
when(guests.checkin("77")).thenReturn(Map.of("token", "abc"));
|
||||
when(guests.attendance("77")).thenReturn(Map.of("invited", 3));
|
||||
mvc.perform(get("/api/admin/events/77/guests")).andExpect(status().isOk()).andExpect(content().json("[{\"id\":1}]"));
|
||||
mvc.perform(get("/api/admin/events/77/checkin")).andExpect(status().isOk()).andExpect(content().json("{\"token\":\"abc\"}"));
|
||||
mvc.perform(get("/api/admin/events/77/attendance")).andExpect(status().isOk()).andExpect(content().json("{\"invited\":3}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void add_bindsBodyAndPreviewFlag() throws Exception {
|
||||
when(guests.add(eq("77"), any(), eq(true))).thenReturn(Map.of("added", List.of(), "rejected", List.of()));
|
||||
String body = "{\"guests\":[{\"name\":\"Amy\",\"mobile\":\"0123456789\",\"email\":\"a@b.co\",\"companyName\":\"Acme\",\"salespersonUserId\":4,\"extra\":1}]}";
|
||||
mvc.perform(post("/api/admin/events/77/guests").param("preview", "true").contentType(MediaType.APPLICATION_JSON).content(body))
|
||||
.andExpect(status().isOk());
|
||||
ArgumentCaptor<AdminGuestsRequest> c = ArgumentCaptor.forClass(AdminGuestsRequest.class);
|
||||
verify(guests).add(eq("77"), c.capture(), eq(true));
|
||||
assertThat(c.getValue().guests()).containsExactly(new AdminGuestsRequest.Guest("Amy", "0123456789", "a@b.co", "Acme", 4L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void add_previewDefaultsToFalse() throws Exception {
|
||||
when(guests.add(eq("77"), any(), eq(false))).thenReturn(Map.of());
|
||||
mvc.perform(post("/api/admin/events/77/guests").contentType(MediaType.APPLICATION_JSON).content("{\"guests\":[]}")).andExpect(status().isOk());
|
||||
verify(guests).add(eq("77"), any(), eq(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void remove_returnsNoContent_andSend_bindsBody() throws Exception {
|
||||
mvc.perform(delete("/api/admin/events/77/guests/9")).andExpect(status().isNoContent());
|
||||
verify(guests).remove("77", "9");
|
||||
when(guests.send(eq("77"), any())).thenReturn(Map.of("sent", 2, "skippedNoEmail", 1));
|
||||
mvc.perform(post("/api/admin/events/77/guests/send").contentType(MediaType.APPLICATION_JSON).content("{\"allUnsent\":true}"))
|
||||
.andExpect(status().isOk()).andExpect(content().json("{\"sent\":2,\"skippedNoEmail\":1}"));
|
||||
ArgumentCaptor<AdminGuestSendRequest> c = ArgumentCaptor.forClass(AdminGuestSendRequest.class);
|
||||
verify(guests).send(eq("77"), c.capture());
|
||||
assertThat(c.getValue().allUnsent()).isTrue();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user