fix(education): align integrated entitlement fixtures

This commit is contained in:
2026-07-31 13:32:59 +08:00
parent 83d5e9dfae
commit 3cfe205dfa
2 changed files with 18 additions and 6 deletions

View File

@@ -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());

View File

@@ -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\"}");