Skip to content

Commit d3d8ec6

Browse files
author
Al Manning
committed
fix bug
1 parent dd98848 commit d3d8ec6

File tree

2 files changed

+94
-5
lines changed

2 files changed

+94
-5
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
ContentAncestor,
1919
ContentBody,
2020
ContentBodyRepresentation,
21+
ContentChange,
2122
ContentChangeType,
2223
ContentCreate,
2324
ContentDelete,
@@ -338,7 +339,6 @@ export const buildSpaceChanges = (
338339

339340
let existingSiteParent = null;
340341

341-
//TODO update with deno paths after tests are in place
342342
const parentsList = pathList.slice(0, pathList.length - 1);
343343

344344
parentsList.forEach((parentFileName, index) => {
@@ -438,18 +438,41 @@ export const buildSpaceChanges = (
438438
existingSite
439439
);
440440

441-
// TODO prompt as a sanity check and limiter to prevent any major run-away deletes
442441
const deleteChanges: ContentDelete[] = pagesToDelete.map(
443442
(toDelete: SitePage) => {
444443
return { contentChangeType: ContentChangeType.delete, id: toDelete.id };
445444
}
446445
);
447446

448-
const spaceChanges: ConfluenceSpaceChange[] = fileMetadataList.reduce(
447+
let spaceChanges: ConfluenceSpaceChange[] = fileMetadataList.reduce(
449448
spaceChangesCallback,
450449
deleteChanges
451450
);
452451

452+
//TODO filter out parent deletes of newly created pages
453+
454+
const activeAncestorIds = spaceChanges.reduce(
455+
(accumulator: any, change: any) => {
456+
if (change?.ancestors?.length) {
457+
const idList = change.ancestors.map(
458+
(ancestor: ContentAncestor) => ancestor?.id ?? ""
459+
);
460+
461+
return [...accumulator, ...idList];
462+
}
463+
464+
return accumulator;
465+
},
466+
[]
467+
);
468+
469+
spaceChanges = spaceChanges.filter((change: ConfluenceSpaceChange) => {
470+
if (isContentDelete(change) && activeAncestorIds.includes(change.id)) {
471+
return false;
472+
}
473+
return true;
474+
});
475+
453476
return spaceChanges;
454477
};
455478

tests/unit/confluence.test.ts

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,72 @@ const runSpaceCreatesWithNesting = () => {
14041404
assertEquals(expected, actual);
14051405
});
14061406

1407+
test(suiteLabel("one_nested_file_add_back_empty_parent"), async () => {
1408+
const fileMetadataList: SiteFileMetadata[] = [fakeNestedFile];
1409+
// {
1410+
// contentChangeType: ContentChangeType.create,
1411+
// ancestors: [
1412+
// {
1413+
// id: "8781825",
1414+
// },
1415+
// ],
1416+
// body: {
1417+
// storage: {
1418+
// representation: "storage",
1419+
// value: "",
1420+
// },
1421+
// },
1422+
// fileName: "fake-parent",
1423+
// space: {
1424+
// key: "fake-space-key",
1425+
// id: "fake-space-id",
1426+
// homepage: buildFakeContent(),
1427+
// },
1428+
// status: "current",
1429+
// title: "Fake-parent",
1430+
// type: "page",
1431+
// },
1432+
const existingSite: SitePage[] = [
1433+
{
1434+
id: "fake-parent-id",
1435+
title: "Fake-parent",
1436+
metadata: { fileName: "fake-parent" },
1437+
},
1438+
];
1439+
const expected: ConfluenceSpaceChange[] = [
1440+
{
1441+
contentChangeType: ContentChangeType.create,
1442+
ancestors: [
1443+
{
1444+
id: "fake-parent-id",
1445+
},
1446+
],
1447+
body: {
1448+
storage: {
1449+
representation: "storage",
1450+
value: "fake-value",
1451+
},
1452+
},
1453+
fileName: "fake-parent/fake-file-name",
1454+
space: {
1455+
key: "fake-space-key",
1456+
id: "fake-space-id",
1457+
homepage: buildFakeContent(),
1458+
},
1459+
status: "current",
1460+
title: "fake-title",
1461+
type: "page",
1462+
},
1463+
];
1464+
const actual: ConfluenceSpaceChange[] = buildSpaceChanges(
1465+
fileMetadataList,
1466+
FAKE_PARENT,
1467+
fakeSpace,
1468+
existingSite
1469+
);
1470+
assertEquals(expected, actual);
1471+
});
1472+
14071473
test(suiteLabel("one_multi_nested_file"), async () => {
14081474
const fileMetadataList: SiteFileMetadata[] = [fakeMultiNestedFile];
14091475
const expected: ConfluenceSpaceChange[] = [
@@ -2390,7 +2456,7 @@ const runSpaceUpdatesWithNesting = () => {
23902456
assertEquals(expected, actual);
23912457
});
23922458

2393-
otest(suiteLabel("one_multi-nested_file_update_win"), async () => {
2459+
test(suiteLabel("one_multi-nested_file_update_win"), async () => {
23942460
const fileMetadataList: SiteFileMetadata[] = [fakeMultiNestedFileWin];
23952461

23962462
const existingSite = [
@@ -3758,5 +3824,5 @@ if (RUN_ALL_TESTS) {
37583824
runUpdateImagePathsForContentBody();
37593825
runCapFirstLetter();
37603826
} else {
3761-
runSpaceUpdatesWithNesting();
3827+
runSpaceCreatesWithNesting();
37623828
}

0 commit comments

Comments
 (0)