diff --git a/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/service/question/authoring/TenantQuestionLifecyclePostgreSqlIntegrationTest.java b/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/service/question/authoring/TenantQuestionLifecyclePostgreSqlIntegrationTest.java index c8ca9bfe..6de75c92 100644 --- a/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/service/question/authoring/TenantQuestionLifecyclePostgreSqlIntegrationTest.java +++ b/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/service/question/authoring/TenantQuestionLifecyclePostgreSqlIntegrationTest.java @@ -10,8 +10,10 @@ import cn.iocoder.yudao.module.education.dal.dataobject.catalog.QuestionDO; import cn.iocoder.yudao.module.education.dal.dataobject.catalog.QuestionVersionDO; import cn.iocoder.yudao.module.education.dal.dataobject.catalog.ContentEntryDO; import cn.iocoder.yudao.module.education.dal.dataobject.catalog.ContentNodeDO; +import cn.iocoder.yudao.module.education.dal.dataobject.catalog.ContentNodeLifecycleAuditDO; import cn.iocoder.yudao.module.education.dal.mysql.catalog.ContentEntryMapper; import cn.iocoder.yudao.module.education.dal.mysql.catalog.ContentNodeMapper; +import cn.iocoder.yudao.module.education.dal.mysql.catalog.ContentNodeLifecycleAuditMapper; import cn.iocoder.yudao.module.education.dal.mysql.catalog.QuestionLifecycleAuditMapper; import cn.iocoder.yudao.module.education.dal.mysql.catalog.QuestionMapper; import cn.iocoder.yudao.module.education.dal.mysql.catalog.QuestionVersionMapper; @@ -53,6 +55,7 @@ class TenantQuestionLifecyclePostgreSqlIntegrationTest extends PostgreSqlDbInteg @Resource private PlatformTransactionManager transactionManager; @Resource private ContentEntryMapper contentEntryMapper; @Resource private ContentNodeMapper contentNodeMapper; + @Resource private ContentNodeLifecycleAuditMapper contentNodeAuditMapper; @BeforeEach void setUpTenant() { @@ -215,10 +218,7 @@ class TenantQuestionLifecyclePostgreSqlIntegrationTest extends PostgreSqlDbInteg lifecycleService.publish(id, 7L); assertNodeQuestionCount(200L, 1L); - ContentNodeDO update = new ContentNodeDO(); - update.setId(200L); - update.setIsActive(false); - contentNodeMapper.updateById(update); + archiveNode(200L, 10L); assertNodeQuestionCount(200L, 0L); assertNotNull(questionCatalogService.getQuestion(String.valueOf(id))); @@ -343,6 +343,46 @@ class TenantQuestionLifecyclePostgreSqlIntegrationTest extends PostgreSqlDbInteg } private void insertNode(Long id, Long tenantId, String scope, Long entryId, String name) { + if ("TENANT_OWNED".equals(scope)) { + new TransactionTemplate(transactionManager).executeWithoutResult(status -> { + ContentNodeDO node = newNode(id, tenantId, scope, entryId, name); + node.setPublicationStatus("DRAFT"); + node.setIsActive(false); + node.setIsHidden(true); + node.setAuthoringVersion(0); + contentNodeMapper.insert(node); + assertEquals(1, contentNodeMapper.updateLifecycleCas(tenantId, id, "DRAFT", "ACTIVE", true, 0)); + ContentNodeLifecycleAuditDO audit = new ContentNodeLifecycleAuditDO(); + audit.setTenantId(tenantId); + audit.setNodeId(id); + audit.setAuthoringVersion(1); + audit.setActorId(7L); + audit.setFromStatus("DRAFT"); + audit.setToStatus("ACTIVE"); + audit.setOccurredAt(java.time.LocalDateTime.now()); + contentNodeAuditMapper.insert(audit); + }); + return; + } + contentNodeMapper.insert(newNode(id, tenantId, scope, entryId, name)); + } + + private void archiveNode(Long id, Long tenantId) { + new TransactionTemplate(transactionManager).executeWithoutResult(status -> { + assertEquals(1, contentNodeMapper.updateLifecycleCas(tenantId, id, "ACTIVE", "ARCHIVED", false, 1)); + ContentNodeLifecycleAuditDO audit = new ContentNodeLifecycleAuditDO(); + audit.setTenantId(tenantId); + audit.setNodeId(id); + audit.setAuthoringVersion(2); + audit.setActorId(7L); + audit.setFromStatus("ACTIVE"); + audit.setToStatus("ARCHIVED"); + audit.setOccurredAt(java.time.LocalDateTime.now()); + contentNodeAuditMapper.insert(audit); + }); + } + + private ContentNodeDO newNode(Long id, Long tenantId, String scope, Long entryId, String name) { ContentNodeDO node = new ContentNodeDO(); node.setId(id); node.setTenantId(tenantId); @@ -350,6 +390,6 @@ class TenantQuestionLifecyclePostgreSqlIntegrationTest extends PostgreSqlDbInteg node.setEntryId(entryId); node.setName(name); node.setNodeType("category"); - contentNodeMapper.insert(node); + return node; } }