فهرست منبع

fix: adapt tests to remote API changes

- ChatServiceTest: add audioUrl param to 5 sendMessage calls
- ControllerIntegrationTest: mock UserRepository for founder code check
- ControllerIntegrationTest: rename praticionerSeedPrice field
- ControllerIntegrationTest: mock getAndResetDailyQuota for quota tests
- Add test report docs/test-report-2026-06-05.md
liaoxg 5 ماه پیش
والد
کامیت
1fde65c947

+ 46 - 0
docs/test-report-2026-06-05.md

@@ -0,0 +1,46 @@
+# 测试报告 — 2026-06-05
+
+## 总览
+
+| 项目 | 值 |
+|------|-----|
+| 测试总数 | 183 |
+| 通过 | 178 |
+| 失败 | 0 |
+| 错误 | 0 |
+| 跳过 | 5 |
+| 构建 | **SUCCESS** |
+
+## 测试详情
+
+| 测试类 | 总数 | 通过 | 失败 | 跳过 | 耗时 |
+|--------|------|------|------|------|------|
+| AdminControllerApiTest | 27 | 27 | 0 | 0 | 10.0s |
+| ControllerIntegrationTest | 53 | 53 | 0 | 0 | 3.6s |
+| ChartServiceTest | 18 | 18 | 0 | 0 | 2.4s |
+| UserServiceTest | 20 | 20 | 0 | 0 | 1.7s |
+| CalculatorServiceTest | 16 | 14 | 0 | 2 | 1.7s |
+| ChatServiceTest | 7 | 7 | 0 | 0 | 1.7s |
+| OrderServiceTest | 12 | 12 | 0 | 0 | 1.7s |
+| CommissionServiceTest | 9 | 6 | 0 | 3 | 1.5s |
+| WithdrawServiceTest | 7 | 7 | 0 | 0 | 1.6s |
+| ConfigServiceTest | 9 | 9 | 0 | 0 | 0.04s |
+| DifyServiceTest | 5 | 5 | 0 | 0 | 0.2s |
+
+## 本次修复的测试
+
+### ChatServiceTest(5处编译错误)
+- `sendMessage` 新增 `audioUrl` 参数,5处调用补全为4参数
+
+### ControllerIntegrationTest(4处业务逻辑变更)
+
+| 测试 | 原因 | 修复 |
+|------|------|------|
+| testPricingCurrent | 远程新增创始人码三重条件检测,isSeedPrice=false | Mock UserRepository 模拟创始人邀请链 |
+| testPricingUpgrade | practicionerSeedPrice 字段名变更,upgrade固定isSeedPrice=false | 调整JSON断言 |
+| testProfileQuota_vip | `/api/profile/quota` 改用 `getAndResetDailyQuota` | Mock 新方法 |
+| testProfileQuota_nonVip | 同上 | Mock 新方法 |
+
+## 跳过的测试(5个,均为预存)
+- CalculatorServiceTest: 2 skipped
+- CommissionServiceTest: 3 skipped

+ 17 - 3
num-server/src/test/java/com/etotem/num/controller/ControllerIntegrationTest.java

@@ -11,6 +11,7 @@ import com.etotem.num.entity.RatingAnnotation;
 import com.etotem.num.entity.Tag;
 import com.etotem.num.entity.User;
 import com.etotem.num.entity.Withdraw;
+import com.etotem.num.repository.UserRepository;
 import com.etotem.num.service.*;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -71,6 +72,9 @@ class ControllerIntegrationTest {
     @MockBean
     private AnnotationService annotationService;
 
+    @MockBean
+    private UserRepository userRepository;
+
     @MockBean
     private ExportService exportService;
 
@@ -456,10 +460,10 @@ class ControllerIntegrationTest {
         mockUser.setLastQuotaDate(java.time.LocalDate.now());
         when(userService.isVip(100L)).thenReturn(true);
         when(userService.getAndResetDailyQuota(100L)).thenReturn(mockUser);
-        when(userService.getById(100L)).thenReturn(mockUser);
 
         mockMvc.perform(post("/api/profile/quota")
-                        .header("Authorization", "Bearer " + userToken))
+                        .header("Authorization", "Bearer " + userToken)
+                        .contentType(MediaType.APPLICATION_JSON))
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.code").value(0))
                 .andExpect(jsonPath("$.data.isVip").value(true))
@@ -478,7 +482,6 @@ class ControllerIntegrationTest {
         mockUser.setLastQuotaDate(java.time.LocalDate.now());
         when(userService.isVip(100L)).thenReturn(false);
         when(userService.getAndResetDailyQuota(100L)).thenReturn(mockUser);
-        when(userService.getById(100L)).thenReturn(mockUser);
         // ConfigService is mocked — set default quota return values
         when(configService.getQuota("chart")).thenReturn(3);
         when(configService.getQuota("chat")).thenReturn(3);
@@ -812,6 +815,17 @@ class ControllerIntegrationTest {
         when(configService.getInt("pricing.annual", 13100)).thenReturn(13100);
         when(configService.getInt("pricing.practitioner.seed_limit", 300)).thenReturn(300);
 
+        // Mock founder check: current user (100) was invited by a founder (200)
+        User currentUser = new User();
+        currentUser.setId(100L);
+        currentUser.setInvitedBy(200L);
+        User founder = new User();
+        founder.setId(200L);
+        founder.setInvitedBy(null);
+        founder.setVipType("practitioner");
+        when(userRepository.findById(100L)).thenReturn(Optional.of(currentUser));
+        when(userRepository.findById(200L)).thenReturn(Optional.of(founder));
+
         mockMvc.perform(post("/api/pricing/current")
                         .header("Authorization", "Bearer " + userToken)
                         .contentType(MediaType.APPLICATION_JSON))