feat(notifications): staff notification store in services-system
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
1 parent
26b285cc0a
commit
d5384c6ac0
10 files changed
+411
-47
No files matched your search
+73
@@ -0,0 +1,73 @@
|
||||
package com.solvway.services.system.controller;
|
||||
|
||||
import com.solvway.services.system.service.NotificationService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
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 java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
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.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
// add-lead-notifications: the store's internal endpoints, with explicit methods and real error statuses.
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class NotificationControllerTest {
|
||||
|
||||
@Mock private NotificationService service;
|
||||
@InjectMocks private NotificationController controller;
|
||||
private MockMvc mvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mvc = MockMvcBuilders.standaloneSetup(controller).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendStoresTheRows() throws Exception {
|
||||
when(service.send(anyList())).thenReturn(1);
|
||||
mvc.perform(post("/notification/send").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("[{\"receiver\":\"11\",\"companyId\":2,\"title\":\"T\",\"message\":\"{}\",\"type\":\"LEAD_ASSIGNED\",\"link\":\"/event-leads/9\"}]"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.count").value(1));
|
||||
verify(service).send(List.of(new NotificationService.Send("11", 2L, "T", "{}", "LEAD_ASSIGNED", "/event-leads/9", null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void inboxCountAndMarks() throws Exception {
|
||||
when(service.inbox("11", 0, 20)).thenReturn(Map.of("items", List.of(), "total", 0L));
|
||||
when(service.unreadCount("11")).thenReturn(3L);
|
||||
when(service.markAllRead("11")).thenReturn(2);
|
||||
mvc.perform(get("/notification/inbox/11/0/20")).andExpect(status().isOk()).andExpect(jsonPath("$.total").value(0));
|
||||
mvc.perform(get("/notification/unreadCount/11")).andExpect(status().isOk()).andExpect(jsonPath("$.count").value(3));
|
||||
mvc.perform(post("/notification/markRead/11/5")).andExpect(status().isOk());
|
||||
verify(service).markRead("11", 5L);
|
||||
mvc.perform(post("/notification/markAllRead/11")).andExpect(status().isOk()).andExpect(jsonPath("$.count").value(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aForeignRowIs404() throws Exception {
|
||||
doThrow(new ResponseStatusException(HttpStatus.NOT_FOUND)).when(service).markRead("12", 5L);
|
||||
mvc.perform(post("/notification/markRead/12/5")).andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theOldUncheckedEndpointsAreGone() throws Exception {
|
||||
mvc.perform(post("/notification/save").contentType(MediaType.APPLICATION_JSON).content("{}")).andExpect(status().isNotFound());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user