fix: issues found in the invitations live check
- guest list failed when no guest was linked yet (Map.of().get(null)) - counter errors arrive as ProblemDetail: read the reason code from detail; drop the counter error advice the core handler always overrode - emails published with a null sender failed the NOT NULL column 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
aed9473aba
commit
fbbc5d0980
10 files changed
+115
-87
No files matched your search
-66
@@ -1,66 +0,0 @@
|
||||
package com.solvway.services.counter.controller;
|
||||
|
||||
import com.solvway.services.counter.model.Event;
|
||||
import com.solvway.services.counter.service.EventCheckInService;
|
||||
import com.solvway.services.counter.service.EventGuestService;
|
||||
import com.solvway.services.counter.service.EventHeadcountService;
|
||||
import com.solvway.services.counter.service.EventService;
|
||||
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.modelmapper.ModelMapper;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/** mobile-api reads the JSON `code` of counter 4xx bodies, so the reason must reach the body. */
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ApiErrorAdviceTest {
|
||||
@Mock private EventGuestService guestService;
|
||||
@Mock private EventCheckInService checkInService;
|
||||
@Mock private EventService eventService;
|
||||
@Mock private ModelMapper modelMapper;
|
||||
@Mock private EventHeadcountService headcountService;
|
||||
|
||||
private MockMvc mvc() {
|
||||
return MockMvcBuilders.standaloneSetup(new EventGuestController(guestService),
|
||||
new EventCheckInController(checkInService), new EventController(eventService, modelMapper, headcountService))
|
||||
.setControllerAdvice(new ApiErrorAdvice()).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void guestRegisterEventFullIs409WithCode() throws Exception {
|
||||
when(guestService.register(any())).thenThrow(new ResponseStatusException(HttpStatus.CONFLICT, "EVENT_FULL"));
|
||||
mvc().perform(post("/counter/eventGuest/register").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"companyId\":42,\"guestToken\":\"t\"}"))
|
||||
.andExpect(status().isConflict())
|
||||
.andExpect(jsonPath("$.code").value("EVENT_FULL"))
|
||||
.andExpect(jsonPath("$.message").value("EVENT_FULL"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkinCompanyRequiredIs400WithCode() throws Exception {
|
||||
when(checkInService.ensureToken(any())).thenThrow(new ResponseStatusException(HttpStatus.BAD_REQUEST, "COMPANY_REQUIRED"));
|
||||
mvc().perform(post("/counter/checkin/ensureToken").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"eventUuid\":1}"))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(jsonPath("$.code").value("COMPANY_REQUIRED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventSaveCapBelowGuestsIs409WithCode() throws Exception {
|
||||
when(eventService.save(any(Event.class))).thenThrow(new ResponseStatusException(HttpStatus.CONFLICT, "CAP_BELOW_GUESTS"));
|
||||
mvc().perform(post("/counter/event/save").contentType(MediaType.APPLICATION_JSON).content("{}"))
|
||||
.andExpect(status().isConflict())
|
||||
.andExpect(jsonPath("$.code").value("CAP_BELOW_GUESTS"));
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.solvway.services.counter.service;
|
||||
|
||||
import com.solvway.services.counter.model.Event;
|
||||
import com.solvway.services.counter.model.EventGuest;
|
||||
import com.solvway.services.counter.repo.EventGuestRepository;
|
||||
import com.solvway.services.counter.repo.EventLeadRepository;
|
||||
import com.solvway.services.counter.repo.EventRepository;
|
||||
import com.solvway.services.counter.repo.EventSalespersonRepository;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Found live: a guest list where nobody has registered yet must list, not fail. */
|
||||
class EventGuestListUnlinkedTest {
|
||||
|
||||
@Test
|
||||
void listsGuestsWhenNoneIsLinkedYet() {
|
||||
EventRepository events = mock(EventRepository.class);
|
||||
EventGuestRepository guests = mock(EventGuestRepository.class);
|
||||
EventGuestService service = new EventGuestService(events, guests, mock(EventLeadRepository.class),
|
||||
mock(EventSalespersonRepository.class), mock(RegistrationService.class));
|
||||
Event event = new Event();
|
||||
event.setCompanyId(42L);
|
||||
when(events.findByUuid(1000L)).thenReturn(Optional.of(event));
|
||||
EventGuest g = new EventGuest();
|
||||
g.setId(1L);
|
||||
g.setCompanyId(42L);
|
||||
g.setEventUuid(1000L);
|
||||
g.setName("Tan Mei Ling");
|
||||
g.setToken("t1");
|
||||
when(guests.findByEventUuidOrderByNameAsc(1000L)).thenReturn(List.of(g));
|
||||
|
||||
List<EventGuestService.GuestRow> rows = service.list(new EventGuestService.ListRequest(42L, 1000L));
|
||||
|
||||
assertThat(rows).hasSize(1);
|
||||
assertThat(rows.get(0).attended()).isFalse();
|
||||
assertThat(rows.get(0).eventLeadUuid()).isNull();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user