feat: counter guest, invite registration and check-in 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
d039cbc1e1
commit
c700e12865
16 files changed
+1335
-6
No files matched your search
+66
@@ -0,0 +1,66 @@
|
||||
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"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user