From 3cfe205dfa4804a881c3fcf5f8d07ab7d2f0562d Mon Sep 17 00:00:00 2001 From: wangziqi Date: Fri, 31 Jul 2026 13:32:59 +0800 Subject: [PATCH] fix(education): align integrated entitlement fixtures --- .../practice/PracticeSessionServiceImpl.java | 8 +++----- ...tionEntitlementPostgreSqlIntegrationTest.java | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/yudao-module-education/src/main/java/cn/iocoder/yudao/module/education/service/practice/PracticeSessionServiceImpl.java b/yudao-module-education/src/main/java/cn/iocoder/yudao/module/education/service/practice/PracticeSessionServiceImpl.java index 4b4be91e..d6030e58 100644 --- a/yudao-module-education/src/main/java/cn/iocoder/yudao/module/education/service/practice/PracticeSessionServiceImpl.java +++ b/yudao-module-education/src/main/java/cn/iocoder/yudao/module/education/service/practice/PracticeSessionServiceImpl.java @@ -75,17 +75,15 @@ public class PracticeSessionServiceImpl implements PracticeSessionService { && reqVO.getNodeId() != null && !reqVO.getNodeId().isBlank()) { throw exception(INVALID_PRACTICE_CONFIG, "题集与目录节点不能同时指定"); } - if (reqVO.getCollectionId() != null && !reqVO.getCollectionId().isBlank()) { + if (entitlementService != null && reqVO.getCollectionId() != null && !reqVO.getCollectionId().isBlank()) { Long collectionId; try { collectionId = Long.valueOf(reqVO.getCollectionId()); } catch (NumberFormatException ex) { throw exception(INVALID_PRACTICE_CONFIG, "题集标识无效"); } - if (entitlementService != null) { - entitlementService.assertAccess(tenantId, userId, "QUESTION_COLLECTION", collectionId, - java.time.LocalDateTime.now()); - } + entitlementService.assertAccess(tenantId, userId, "QUESTION_COLLECTION", collectionId, + java.time.LocalDateTime.now()); } // 1. Idempotent check: same tenant + clientSessionId exists → verify ownership before returning PracticeSessionDO existing = sessionMapper.selectByTenantAndClientSessionId(tenantId, reqVO.getClientSessionId()); diff --git a/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/service/commercialization/EducationEntitlementPostgreSqlIntegrationTest.java b/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/service/commercialization/EducationEntitlementPostgreSqlIntegrationTest.java index 858ca0e5..3b041e46 100644 --- a/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/service/commercialization/EducationEntitlementPostgreSqlIntegrationTest.java +++ b/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/service/commercialization/EducationEntitlementPostgreSqlIntegrationTest.java @@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.education.test.PostgreSqlDbIntegrationTest; import jakarta.annotation.Resource; import org.junit.jupiter.api.*; import org.springframework.context.annotation.Import; +import org.springframework.jdbc.core.JdbcTemplate; import java.time.LocalDateTime; import static cn.iocoder.yudao.module.education.enums.ErrorCodeConstants.ENTITLEMENT_IDEMPOTENCY_CONFLICT; import static org.junit.jupiter.api.Assertions.*; @@ -23,6 +24,7 @@ class EducationEntitlementPostgreSqlIntegrationTest extends PostgreSqlDbIntegrat @Resource EducationEntitlementMapper entitlementMapper; @Resource EducationEntitlementEventMapper eventMapper; @Resource EducationResourceProductBindingMapper bindingMapper; + @Resource JdbcTemplate jdbcTemplate; @BeforeEach void setUp() { TenantContextHolder.setTenantId(10L); @@ -30,7 +32,19 @@ class EducationEntitlementPostgreSqlIntegrationTest extends PostgreSqlDbIntegrat entry.setEntryKey("paid"); entry.setName("Paid"); entry.setEntryType("question"); entryMapper.insert(entry); ContentNodeDO node = new ContentNodeDO(); node.setId(101L); node.setTenantId(10L); node.setScope("TENANT_OWNED"); node.setEntryId(100L); node.setName("Paid node"); node.setNodeType("category"); node.setDepth(0); node.setIsLeaf(true); - node.setIsSelectable(true); node.setIsHidden(false); node.setIsActive(true); node.setPublicationStatus("ACTIVE"); node.setAuthoringVersion(0); nodeMapper.insert(node); + node.setIsSelectable(true); node.setIsHidden(true); node.setIsActive(false); node.setPublicationStatus("DRAFT"); node.setAuthoringVersion(0); nodeMapper.insert(node); + jdbcTemplate.execute(""" + DO $activate$ + BEGIN + UPDATE education_content_node + SET publication_status='ACTIVE', is_active=true, is_hidden=false, authoring_version=1 + WHERE id=101 AND tenant_id=10; + INSERT INTO education_content_node_lifecycle_audit + (tenant_id,node_id,authoring_version,actor_id,from_status,to_status) + VALUES (10,101,1,7,'DRAFT','ACTIVE'); + END + $activate$; + """); QuestionCollectionDO collection = new QuestionCollectionDO(); collection.setId(102L); collection.setTenantId(10L); collection.setScope("TENANT_OWNED"); collection.setEntryId(100L); collection.setNodeId(101L); collection.setName("Paid collection"); collection.setCollectionType("MANUAL"); collection.setQuestionCount(0); collection.setAccessMode("PAID"); collection.setAccessRules("{\"label\":\"descriptive only\"}");