Przeglądaj źródła

fix: update test to match new BindController signatures

BindController.acceptBind() and .unbind() no longer take familyId
parameter - it's resolved internally via MembershipService.
Add @MockBean MembershipService and update call sites.
iwt 3 miesięcy temu
rodzic
commit
9d75791edb

+ 14 - 5
cfc-backend/src/test/java/com/etotem/cfc/integration/PlannerBindInviteFlowTest.java

@@ -7,6 +7,7 @@ import com.etotem.cfc.dto.BindGuideDTO;
 import com.etotem.cfc.entity.GuideFamily;
 import com.etotem.cfc.service.BindInviteService;
 import com.etotem.cfc.service.GuideFamilyService;
+import com.etotem.cfc.service.MembershipService;
 import com.etotem.cfc.service.TeacherMessageService;
 import com.etotem.cfc.mapper.GuideFamilyMapper;
 import org.junit.jupiter.api.*;
@@ -63,6 +64,9 @@ public class PlannerBindInviteFlowTest {
     @MockBean
     private GuideFamilyMapper guideFamilyMapper;
 
+    @MockBean
+    private MembershipService membershipService;
+
     // ========== 测试数据 ==========
 
     private static final Long GUIDE_USER_ID = 4001L;
@@ -183,10 +187,11 @@ public class PlannerBindInviteFlowTest {
 
         when(guideFamilyService.confirmBind(eq(GUIDE_USER_ID), eq(FAMILY_ID), eq("学业规划"), eq(29900)))
                 .thenReturn(true);
+        when(membershipService.getUserFamilyId(PARENT_USER_ID)).thenReturn(FAMILY_ID);
 
         // === When:家长点击"确认绑定" ===
         Result<Boolean> result = bindController.acceptBind(
-                PARENT_USER_ID, FAMILY_ID, bindDTO);
+                PARENT_USER_ID, bindDTO);
 
         // === Then:Milestone-3 - 绑定成功 ===
         assertEquals(200, result.getCode());
@@ -209,10 +214,11 @@ public class PlannerBindInviteFlowTest {
 
         when(guideFamilyService.confirmBind(eq(GUIDE_USER_ID), eq(FAMILY_ID), anyString(), anyInt()))
                 .thenThrow(new RuntimeException("该规划师已在服务中,无需重复绑定"));
+        when(membershipService.getUserFamilyId(PARENT_USER_ID)).thenReturn(FAMILY_ID);
 
         // === When:家长尝试再次绑定 ===
         Result<Boolean> result = bindController.acceptBind(
-                PARENT_USER_ID, FAMILY_ID, bindDTO);
+                PARENT_USER_ID, bindDTO);
 
         // === Then:返回错误提示 ===
         assertEquals(400, result.getCode());
@@ -236,9 +242,10 @@ public class PlannerBindInviteFlowTest {
         );
 
         when(guideFamilyService.getGuidesByFamily(FAMILY_ID)).thenReturn(mockBindings);
+        when(membershipService.getUserFamilyId(PARENT_USER_ID)).thenReturn(FAMILY_ID);
 
         // === When:家长请求规划师列表 ===
-        Result<List<Map<String, Object>>> result = bindController.getBoundGuides(FAMILY_ID);
+        Result<List<Map<String, Object>>> result = bindController.getBoundGuides(PARENT_USER_ID);
 
         // === Then:Milestone-4 - 返回已绑定规划师列表 ===
         assertEquals(200, result.getCode());
@@ -264,10 +271,11 @@ public class PlannerBindInviteFlowTest {
         GuideFamily unbindGuide = createGuideFamily(BINDING_ID, GUIDE_USER_ID, "学业规划", 29900, "unbound");
         when(guideFamilyService.unbindAndGet(eq(BINDING_ID), eq(FAMILY_ID))).thenReturn(unbindGuide);
         doNothing().when(teacherMessageService).sendMessage(eq(FAMILY_ID), eq(PARENT_USER_ID), eq(GUIDE_USER_ID), anyString());
+        when(membershipService.getUserFamilyId(PARENT_USER_ID)).thenReturn(FAMILY_ID);
 
         // === When:家长确认解除绑定 ===
         Result<Boolean> result = bindController.unbind(
-                PARENT_USER_ID, FAMILY_ID, unbindRequest);
+                PARENT_USER_ID, unbindRequest);
 
         // === Then:Milestone-5 - 解绑成功并通知规划师 ===
         assertEquals(200, result.getCode());
@@ -346,8 +354,9 @@ public class PlannerBindInviteFlowTest {
 
         when(guideFamilyService.confirmBind(eq(GUIDE_USER_ID), eq(FAMILY_ID), eq("学业规划"), eq(29900)))
                 .thenReturn(true);
+        when(membershipService.getUserFamilyId(PARENT_USER_ID)).thenReturn(FAMILY_ID);
 
-        Result<Boolean> step3 = bindController.acceptBind(PARENT_USER_ID, FAMILY_ID, bindDTO);
+        Result<Boolean> step3 = bindController.acceptBind(PARENT_USER_ID, bindDTO);
         assertEquals(200, step3.getCode());
         assertTrue(step3.getData());
     }