当天数据导入

This commit is contained in:
2026-04-25 14:13:27 +08:00
parent 4d9e6f1ef8
commit 217422f422
16 changed files with 907 additions and 5 deletions

View File

@@ -0,0 +1,46 @@
package com.rj.controller;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("test")
class QweiUserControllerIntegrationTest {
@Autowired
private MockMvc mockMvc;
@Test
void syncCustomerShouldFetchFromQiWeiAndPrintToConsole() throws Exception {
String tenantId = System.getProperty("tenantId", "TENANT_ID_CST_2026");
var requestBuilder = post("/api/qweiUser/syncCustomer")
.param("tenantId", tenantId);
MvcResult mvcResult = mockMvc.perform(requestBuilder).andReturn();
int statusCode = mvcResult.getResponse().getStatus();
String responseBody = mvcResult.getResponse().getContentAsString();
System.out.println("qwei customer sync status: " + statusCode);
System.out.println("qwei customer sync response: " + responseBody);
assertTrue(responseBody.contains("\"success\""), "响应缺少success字段: " + responseBody);
if (statusCode == HttpStatus.OK.value()) {
assertTrue(responseBody.contains("\"success\":true"), "同步失败: " + responseBody);
return;
}
assertTrue(statusCode == HttpStatus.BAD_REQUEST.value(), "非预期状态码: " + statusCode + ", body=" + responseBody);
assertTrue(responseBody.contains("48002") || responseBody.contains("api forbidden"),
"当前失败不是企微权限问题,请排查: " + responseBody);
}
}

View File

@@ -0,0 +1,81 @@
package com.rj.controller;
import com.rj.service.IQweiUserService;
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")
class QweiUserControllerTest {
@Autowired
private WebApplicationContext webApplicationContext;
@MockitoBean
private IQweiUserService qweiUserService;
private MockMvc mockMvc;
@BeforeEach
void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test
void syncCustomerShouldReturnOkWhenServiceSuccess() throws Exception {
Map<String, Object> serviceResult = new HashMap<>();
serviceResult.put("success", true);
serviceResult.put("message", "同步企微客户成功");
serviceResult.put("inserted", 2);
serviceResult.put("updated", 3);
serviceResult.put("total", 5);
when(qweiUserService.syncCustomerFromQiWei("TENANT_TEST")).thenReturn(serviceResult);
mockMvc.perform(post("/api/qweiUser/syncCustomer")
.param("tenantId", "TENANT_TEST")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.success").value(true))
.andExpect(jsonPath("$.inserted").value(2))
.andExpect(jsonPath("$.updated").value(3))
.andExpect(jsonPath("$.total").value(5));
verify(qweiUserService, times(1)).syncCustomerFromQiWei("TENANT_TEST");
}
@Test
void syncCustomerShouldReturnBadRequestWhenServiceFailed() throws Exception {
Map<String, Object> serviceResult = new HashMap<>();
serviceResult.put("success", false);
serviceResult.put("message", "同步企微客户异常:测试错误");
when(qweiUserService.syncCustomerFromQiWei("TENANT_TEST")).thenReturn(serviceResult);
mockMvc.perform(post("/api/qweiUser/syncCustomer")
.param("tenantId", "TENANT_TEST")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.success").value(false));
verify(qweiUserService, times(1)).syncCustomerFromQiWei("TENANT_TEST");
}
}