Skip to content

Commit 99f7cf1

Browse files
author
Al Manning
committed
simple folder moves
1 parent 98b0966 commit 99f7cf1

File tree

3 files changed

+85
-6
lines changed

3 files changed

+85
-6
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ export const buildSpaceChanges = (
308308

309309
const pathList = fileMetadata.fileName.split("/");
310310

311-
const pageParent =
311+
let pageParent =
312312
pathList.length > 1
313313
? pathList.slice(0, pathList.length - 1).join("/")
314314
: parent?.parent;
@@ -378,8 +378,11 @@ export const buildSpaceChanges = (
378378

379379
return existingSiteParent;
380380
};
381+
381382
const existingParent: SitePage | null = checkCreateParents();
382-
console.log("existingSiteParent", existingParent);
383+
console.log("existingParent", existingParent);
384+
385+
pageParent = existingParent ? existingParent.id : pageParent;
383386

384387
if (existingPage) {
385388
let useOriginalTitle = false;
@@ -395,7 +398,7 @@ export const buildSpaceChanges = (
395398
useOriginalTitle ? fileMetadata.originalTitle : fileMetadata.title,
396399
fileMetadata.contentBody,
397400
fileMetadata.fileName,
398-
existingParent ? existingParent.id : pageParent
401+
pageParent
399402
),
400403
];
401404
} else {

src/publish/confluence/confluence.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,9 @@ async function publish(
619619

620620
trace("changelist", changeList);
621621

622+
console.log("existingSite", existingSite);
623+
console.log("changeList", changeList);
624+
622625
changeList = updateLinks(
623626
metadataByFilename,
624627
changeList,

tests/unit/confluence.test.ts

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,7 @@ const runSpaceUpdatesWithNestedMoves = () => {
22812281
contentChangeType: ContentChangeType.create,
22822282
ancestors: [
22832283
{
2284-
id: "fake-parent",
2284+
id: "fake-parent-id",
22852285
},
22862286
],
22872287
body: {
@@ -2310,6 +2310,79 @@ const runSpaceUpdatesWithNestedMoves = () => {
23102310
assertEquals(expected, actual);
23112311
});
23122312

2313+
unitTest(suiteLabel("from_root_to_existing_parent"), async () => {
2314+
const fileMetadataList: SiteFileMetadata[] = [
2315+
fakeNestedFile,
2316+
fakeNestedFile2,
2317+
];
2318+
const existingSite = [
2319+
{
2320+
id: "fake-title-id",
2321+
title: "fake-title",
2322+
metadata: { fileName: "fake-file-name.xml" },
2323+
ancestors: [{ id: "fake-grand-parent-id" }],
2324+
},
2325+
{
2326+
id: "fake-title2-id",
2327+
title: "fake-title",
2328+
metadata: { fileName: "fake-parent/fake-file-name2.xml" },
2329+
ancestors: [{ id: "fake-grand-parent-id" }, { id: "fake-parent-id" }],
2330+
},
2331+
{
2332+
title: "Fake Parent",
2333+
id: "fake-parent-id",
2334+
metadata: { editor: "v2", fileName: "fake-parent" },
2335+
ancestors: [{ id: "fake-grand-parent-id" }],
2336+
},
2337+
];
2338+
2339+
const expected: ConfluenceSpaceChange[] = [
2340+
{ contentChangeType: ContentChangeType.delete, id: "fake-title-id" },
2341+
{
2342+
contentChangeType: ContentChangeType.create,
2343+
ancestors: [
2344+
{
2345+
id: "fake-parent-id",
2346+
},
2347+
],
2348+
body: {
2349+
storage: {
2350+
representation: "storage",
2351+
value: "fake-value",
2352+
},
2353+
},
2354+
fileName: "fake-parent/fake-file-name.xml",
2355+
space: {
2356+
key: "fake-space-key",
2357+
id: "fake-space-id",
2358+
homepage: buildFakeContent(),
2359+
},
2360+
status: "current",
2361+
title: "fake-title",
2362+
type: "page",
2363+
},
2364+
{
2365+
contentChangeType: ContentChangeType.update,
2366+
id: "fake-title2-id",
2367+
version: null,
2368+
title: "fake-title2",
2369+
type: "page",
2370+
status: "current",
2371+
ancestors: [{ id: "fake-parent-id" }],
2372+
body: { storage: { value: "fake-value", representation: "storage" } },
2373+
fileName: "fake-parent/fake-file-name2.xml",
2374+
},
2375+
];
2376+
const actual: ConfluenceSpaceChange[] = buildSpaceChanges(
2377+
fileMetadataList,
2378+
FAKE_PARENT,
2379+
fakeSpace,
2380+
existingSite
2381+
);
2382+
console.log("actual", actual);
2383+
assertEquals(expected, actual);
2384+
});
2385+
23132386
// TODO Delete orphaned parents
23142387
// unitTest(suiteLabel("parent_to_root_del_parent"), async () => {
23152388
// const fileMetadataList: SiteFileMetadata[] = [fakeRootFile];
@@ -2878,6 +2951,6 @@ if (runAllTests) {
28782951
runUpdateImagePathsForContentBody();
28792952
} else {
28802953
// runSpaceCreatesWithNesting();
2881-
// runSpaceUpdatesWithNestedMoves();
2882-
runSpaceUpdatesWithNesting();
2954+
runSpaceUpdatesWithNestedMoves();
2955+
// runSpaceUpdatesWithNesting();
28832956
}

0 commit comments

Comments
 (0)