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 org.junit.jupiter.api.*;
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 static cn.iocoder.yudao.module.education.enums.ErrorCodeConstants.ENTITLEMENT_IDEMPOTENCY_CONFLICT;
import static org.junit.jupiter.api.Assertions.*;
@@ -24,7 +25,7 @@ class EducationEntitlementPostgreSqlIntegrationTest extends PostgreSqlDbIntegrat
@Resource EducationEntitlementMapper entitlementMapper;
@Resource EducationEntitlementEventMapper eventMapper;
@Resource EducationResourceProductBindingMapper bindingMapper;
@Resource JdbcTemplate jdbcTemplate;
@Resource DataSource dataSource;
@BeforeEach void setUp() {
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");
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);
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$;
""");
try (Connection connection = dataSource.getConnection(); var statement = connection.createStatement()) {
statement.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$;
""");
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
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\"}");