test(education): activate entitlement fixtures transactionally

This commit is contained in:
2026-07-31 13:35:25 +08:00
parent 3cfe205dfa
commit 68815b1fda

View File

@@ -10,7 +10,8 @@ import cn.iocoder.yudao.module.education.test.PostgreSqlDbIntegrationTest;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.jdbc.core.JdbcTemplate; import javax.sql.DataSource;
import java.sql.Connection;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import static cn.iocoder.yudao.module.education.enums.ErrorCodeConstants.ENTITLEMENT_IDEMPOTENCY_CONFLICT; import static cn.iocoder.yudao.module.education.enums.ErrorCodeConstants.ENTITLEMENT_IDEMPOTENCY_CONFLICT;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
@@ -24,7 +25,7 @@ class EducationEntitlementPostgreSqlIntegrationTest extends PostgreSqlDbIntegrat
@Resource EducationEntitlementMapper entitlementMapper; @Resource EducationEntitlementMapper entitlementMapper;
@Resource EducationEntitlementEventMapper eventMapper; @Resource EducationEntitlementEventMapper eventMapper;
@Resource EducationResourceProductBindingMapper bindingMapper; @Resource EducationResourceProductBindingMapper bindingMapper;
@Resource JdbcTemplate jdbcTemplate; @Resource DataSource dataSource;
@BeforeEach void setUp() { @BeforeEach void setUp() {
TenantContextHolder.setTenantId(10L); TenantContextHolder.setTenantId(10L);
@@ -33,18 +34,22 @@ class EducationEntitlementPostgreSqlIntegrationTest extends PostgreSqlDbIntegrat
ContentNodeDO node = new ContentNodeDO(); node.setId(101L); node.setTenantId(10L); node.setScope("TENANT_OWNED"); 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.setEntryId(100L); node.setName("Paid node"); node.setNodeType("category"); node.setDepth(0); node.setIsLeaf(true);
node.setIsSelectable(true); node.setIsHidden(true); node.setIsActive(false); node.setPublicationStatus("DRAFT"); 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(""" try (Connection connection = dataSource.getConnection(); var statement = connection.createStatement()) {
DO $activate$ statement.execute("""
BEGIN DO $activate$
UPDATE education_content_node BEGIN
SET publication_status='ACTIVE', is_active=true, is_hidden=false, authoring_version=1 UPDATE education_content_node
WHERE id=101 AND tenant_id=10; SET publication_status='ACTIVE', is_active=true, is_hidden=false, authoring_version=1
INSERT INTO education_content_node_lifecycle_audit WHERE id=101 AND tenant_id=10;
(tenant_id,node_id,authoring_version,actor_id,from_status,to_status) INSERT INTO education_content_node_lifecycle_audit
VALUES (10,101,1,7,'DRAFT','ACTIVE'); (tenant_id,node_id,authoring_version,actor_id,from_status,to_status)
END VALUES (10,101,1,7,'DRAFT','ACTIVE');
$activate$; END
"""); $activate$;
""");
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
QuestionCollectionDO collection = new QuestionCollectionDO(); collection.setId(102L); collection.setTenantId(10L); collection.setScope("TENANT_OWNED"); 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.setEntryId(100L); collection.setNodeId(101L); collection.setName("Paid collection"); collection.setCollectionType("MANUAL");
collection.setQuestionCount(0); collection.setAccessMode("PAID"); collection.setAccessRules("{\"label\":\"descriptive only\"}"); collection.setQuestionCount(0); collection.setAccessMode("PAID"); collection.setAccessRules("{\"label\":\"descriptive only\"}");