test(wiki): isolate profile/metadata E2E tests from the shared file DB

This commit is contained in:
matevip 2026-05-31 07:55:44 +08:00
parent 16a7aadbcd
commit 7a79fe93d0
3 changed files with 36 additions and 16 deletions

View File

@ -33,12 +33,16 @@ class WikiPageTypeProfileServiceE2ETest {
@Autowired
private WikiPageTypeProfileService service;
// Persistent file-DB isolation: fresh kb ids per test.
private static final java.util.concurrent.atomic.AtomicLong SEQ =
new java.util.concurrent.atomic.AtomicLong(System.nanoTime());
private static final String EPISODE_JSON =
"{\"version\":1,\"pageTypes\":{\"episode\":{\"label\":\"Episode\"}}}";
@Test
void saveThenResolve_roundTrips() {
long kb = 5001L;
long kb = SEQ.incrementAndGet();
service.saveProfile(kb, "liquidity", EPISODE_JSON);
WikiPageTypeProfileEntity row = service.findEnabledRow(kb);
@ -50,7 +54,7 @@ class WikiPageTypeProfileServiceE2ETest {
@Test
void saveTwice_upsertsInPlaceAndBumpsVersion() {
long kb = 5002L;
long kb = SEQ.incrementAndGet();
service.saveProfile(kb, "v1", EPISODE_JSON);
// Saving again must update the single enabled row, not insert a second
// (which would violate the one-enabled-per-KB generated-column UNIQUE).
@ -64,7 +68,7 @@ class WikiPageTypeProfileServiceE2ETest {
@Test
void resetToDefault_removesRowAndFallsBack() {
long kb = 5003L;
long kb = SEQ.incrementAndGet();
service.saveProfile(kb, "custom", EPISODE_JSON);
assertNotNull(service.findEnabledRow(kb));
@ -79,7 +83,7 @@ class WikiPageTypeProfileServiceE2ETest {
@Test
void invalidConfig_isRejectedOnSave() {
try {
service.saveProfile(5004L, "bad", "{ not json");
service.saveProfile(SEQ.incrementAndGet(), "bad", "{ not json");
org.junit.jupiter.api.Assertions.fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
// ok

View File

@ -32,6 +32,15 @@ class WikiPageTypeProfileMapperE2ETest {
@Autowired
private WikiPageTypeProfileMapper mapper;
// The test H2 is a persistent file DB shared across runs, so each test
// uses fresh kb ids to stay isolated from earlier runs' rows.
private static final java.util.concurrent.atomic.AtomicLong SEQ =
new java.util.concurrent.atomic.AtomicLong(System.nanoTime());
private long uniqueKb() {
return SEQ.incrementAndGet();
}
private WikiPageTypeProfileEntity profile(long kbId, String name, int enabled) {
WikiPageTypeProfileEntity p = new WikiPageTypeProfileEntity();
p.setKbId(kbId);
@ -46,40 +55,43 @@ class WikiPageTypeProfileMapperE2ETest {
@Test
void insertsAndReadsBack() {
WikiPageTypeProfileEntity p = profile(9001L, "default", 1);
long kb = uniqueKb();
WikiPageTypeProfileEntity p = profile(kb, "default", 1);
mapper.insert(p);
assertNotNull(p.getId());
WikiPageTypeProfileEntity loaded = mapper.selectById(p.getId());
assertEquals("default", loaded.getName());
assertEquals(9001L, loaded.getKbId());
assertEquals(kb, loaded.getKbId());
}
@Test
void secondEnabledProfileForSameKb_isRejected() {
mapper.insert(profile(9002L, "default", 1));
long kb = uniqueKb();
mapper.insert(profile(kb, "default", 1));
// A different name but also enabled for the same KB must violate the
// generated-column UNIQUE (one enabled profile per KB).
assertThrows(Exception.class, () -> mapper.insert(profile(9002L, "regulation", 1)));
assertThrows(Exception.class, () -> mapper.insert(profile(kb, "regulation", 1)));
}
@Test
void multipleDisabledProfilesForSameKb_coexist() {
mapper.insert(profile(9003L, "default", 1));
long kb = uniqueKb();
mapper.insert(profile(kb, "default", 1));
// enabled=0 rows yield NULL in the generated column and are exempt from
// the unique check, so several may coexist.
mapper.insert(profile(9003L, "draft-a", 0));
mapper.insert(profile(9003L, "draft-b", 0));
mapper.insert(profile(kb, "draft-a", 0));
mapper.insert(profile(kb, "draft-b", 0));
long count = mapper.selectCount(
com.baomidou.mybatisplus.core.toolkit.Wrappers
.<WikiPageTypeProfileEntity>lambdaQuery()
.eq(WikiPageTypeProfileEntity::getKbId, 9003L));
.eq(WikiPageTypeProfileEntity::getKbId, kb));
assertEquals(3, count);
}
@Test
void enabledProfilesInDifferentKbs_coexist() {
mapper.insert(profile(9101L, "default", 1));
mapper.insert(profile(9102L, "default", 1));
mapper.insert(profile(uniqueKb(), "default", 1));
mapper.insert(profile(uniqueKb(), "default", 1));
assertTrue(true); // no exception thrown different KBs are independent
}
}

View File

@ -28,9 +28,13 @@ class WikiPageMetadataE2ETest {
@Autowired
private WikiPageService pageService;
// Persistent file-DB isolation: fresh kb ids per test.
private static final java.util.concurrent.atomic.AtomicLong SEQ =
new java.util.concurrent.atomic.AtomicLong(System.nanoTime());
@Test
void applyMetadata_persistsColumns_withoutTouchingContent() {
long kb = 6001L;
long kb = SEQ.incrementAndGet();
WikiPageEntity page = pageService.createPage(kb, "episode-x", "Episode X",
"## Body\n\noriginal content", "summary", "[1]", "episode");
assertNotNull(page.getId());
@ -49,7 +53,7 @@ class WikiPageMetadataE2ETest {
@Test
void applyMetadata_warningStatusAndJson() {
long kb = 6002L;
long kb = SEQ.incrementAndGet();
WikiPageEntity page = pageService.createPage(kb, "episode-y", "Episode Y",
"body", "summary", "[1]", "episode");