企微同步,需要有租户ID
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package com.rj.controller;
|
||||
|
||||
import com.rj.service.IQweiDepartmentService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
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;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureWebMvc
|
||||
@ActiveProfiles("test")
|
||||
public class QweiDepartmentControllerTest {
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext webApplicationContext;
|
||||
|
||||
@MockitoBean
|
||||
private IQweiDepartmentService qweiDepartmentService;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void syncEndpointShouldReturnOkWhenServiceSuccess() throws Exception {
|
||||
Map<String, Object> serviceResult = new HashMap<>();
|
||||
serviceResult.put("success", true);
|
||||
serviceResult.put("message", "同步成功");
|
||||
serviceResult.put("inserted", 3);
|
||||
serviceResult.put("updated", 5);
|
||||
serviceResult.put("total", 8);
|
||||
when(qweiDepartmentService.syncFromQiWei()).thenReturn(serviceResult);
|
||||
|
||||
mockMvc.perform(post("/api/qweiDepartment/sync")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.success").value(true))
|
||||
.andExpect(jsonPath("$.inserted").value(3))
|
||||
.andExpect(jsonPath("$.updated").value(5))
|
||||
.andExpect(jsonPath("$.total").value(8));
|
||||
|
||||
verify(qweiDepartmentService, times(1)).syncFromQiWei();
|
||||
}
|
||||
|
||||
@Test
|
||||
void syncEndpointShouldReturnBadRequestWhenServiceFailed() throws Exception {
|
||||
Map<String, Object> serviceResult = new HashMap<>();
|
||||
serviceResult.put("success", false);
|
||||
serviceResult.put("message", "同步异常:测试错误");
|
||||
when(qweiDepartmentService.syncFromQiWei()).thenReturn(serviceResult);
|
||||
|
||||
mockMvc.perform(post("/api/qweiDepartment/sync")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(jsonPath("$.success").value(false));
|
||||
|
||||
verify(qweiDepartmentService, times(1)).syncFromQiWei();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.rj.qiwei;
|
||||
|
||||
import com.rj.service.IQweiDepartmentService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("test")
|
||||
public class QweiDepartmentSyncIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private IQweiDepartmentService qweiDepartmentService;
|
||||
|
||||
@Test
|
||||
void syncDepartmentsToDb() {
|
||||
Map<String, Object> result = qweiDepartmentService.syncFromQiWei();
|
||||
Object success = result.get("success");
|
||||
assertTrue(Boolean.TRUE.equals(success), "同步失败: " + result);
|
||||
System.out.println("qwei department sync result: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
28
src/test/java/com/rj/qiwei/QweiUserSyncIntegrationTest.java
Normal file
28
src/test/java/com/rj/qiwei/QweiUserSyncIntegrationTest.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.rj.qiwei;
|
||||
|
||||
import com.rj.service.IQweiUserService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("test")
|
||||
public class QweiUserSyncIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private IQweiUserService qweiUserService;
|
||||
|
||||
@Test
|
||||
void syncUsersToDb() {
|
||||
Map<String, Object> result = qweiUserService.syncFromQiWei();
|
||||
Object success = result.get("success");
|
||||
assertTrue(Boolean.TRUE.equals(success), "同步失败: " + result);
|
||||
System.out.println("qwei user sync result: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user