Skip to content

Commit 6acfb51

Browse files
author
Al Manning
committed
more tests
1 parent 3bb1a30 commit 6acfb51

File tree

3 files changed

+65
-16
lines changed

3 files changed

+65
-16
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -651,14 +651,11 @@ export const convertForSecondPass = (
651651
const qmdFileName = change?.fileName?.replace(".xml", ".qmd") ?? "";
652652
const updateId = fileMetadataTable[qmdFileName]?.id;
653653

654-
console.log("change.fileName", change.fileName);
655-
console.log("change.ancestors", change.ancestors);
656-
console.log("fileMetadataTable", fileMetadataTable);
657654
if (updateId) {
658655
const convertedUpdate = buildContentUpdate(
659656
updateId,
660657
change.title,
661-
change.body, //TODO convert links
658+
change.body,
662659
change.fileName ?? "",
663660
"",
664661
ContentStatusEnum.current,
@@ -676,7 +673,15 @@ export const convertForSecondPass = (
676673
};
677674

678675
const changesAsUpdates = spaceChanges.reduce(toUpdatesReducer, []);
679-
return changesAsUpdates;
676+
677+
const updateLinkResults = updateLinks(
678+
fileMetadataTable,
679+
changesAsUpdates,
680+
server,
681+
parent
682+
);
683+
684+
return updateLinkResults.pass1Changes;
680685
};
681686

682687
export const updateImagePaths = (body: ContentBody): ContentBody => {

src/publish/confluence/confluence.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,6 @@ async function publish(
622622
trace("fileMetadata", fileMetadata);
623623

624624
let metadataByFilename = buildFileToMetaTable(existingSite);
625-
console.log("metadataByFilename", metadataByFilename);
626625

627626
trace("metadataByFilename", metadataByFilename);
628627

@@ -642,7 +641,7 @@ async function publish(
642641

643642
changeList = pass1Changes;
644643

645-
trace("changelist", changeList);
644+
trace("changelist Pass 1", changeList);
646645

647646
let pathsToId: Record<string, string> = {}; // build from existing site
648647

@@ -710,24 +709,20 @@ async function publish(
710709

711710
if (pass2Changes.length) {
712711
//PASS #2 to update links to newly created pages
713-
console.log("do pass 2 link updates");
712+
713+
trace("changelist Pass 2", pass2Changes);
714714

715715
// reload the existing site
716716
existingSite = await fetchExistingSite(parentId);
717717
metadataByFilename = buildFileToMetaTable(existingSite);
718718

719-
console.log("metadataByFilename", metadataByFilename);
720-
console.log("pass2Changes", pass2Changes);
721-
722719
const linkUpdateChanges: ConfluenceSpaceChange[] = convertForSecondPass(
723720
metadataByFilename,
724721
pass2Changes,
725722
server,
726723
parent
727724
);
728725

729-
console.log("linkUpdateChanges", linkUpdateChanges);
730-
731726
for (let currentChange of linkUpdateChanges) {
732727
await doChange(currentChange);
733728
}

tests/unit/confluence.test.ts

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ import {
5959
Space,
6060
} from "../../src/publish/confluence/api/types.ts";
6161

62-
const RUN_ALL_TESTS = false;
63-
const FOCUS_TEST = true;
62+
const RUN_ALL_TESTS = true;
63+
const FOCUS_TEST = false;
6464

6565
const xtest = (
6666
name: string,
@@ -3639,6 +3639,23 @@ const runConvertForSecondPass = () => {
36393639
fileName: "release-planning.xml",
36403640
};
36413641

3642+
const CREATE_LINKS_ONE: ContentCreate = {
3643+
contentChangeType: ContentChangeType.create,
3644+
title: "Release Planning",
3645+
type: "page",
3646+
status: "current",
3647+
ancestors: [{ id: "19759105" }],
3648+
space: fakeSpace,
3649+
body: {
3650+
storage: {
3651+
value:
3652+
"<a href='no-replace.qmd'/>no</a> content content <a href='team.qmd'>team</a> content content <a href='zqmdzz.qmd'>team</a>",
3653+
representation: "storage",
3654+
},
3655+
},
3656+
fileName: "release-planning.xml",
3657+
};
3658+
36423659
const UPDATE_LINKS_ONE_NESTED_DOT_SLASH: ContentUpdate = {
36433660
contentChangeType: ContentChangeType.update,
36443661
id: "43778049",
@@ -3755,11 +3772,43 @@ const runConvertForSecondPass = () => {
37553772
check(expected, changes, fileMetadataTable);
37563773
});
37573774

3758-
otest(suiteLabel("one_create_noLink_convert_to_update"), async () => {
3775+
test(suiteLabel("one_create_noLink_convert_to_update"), async () => {
37593776
const changes: ConfluenceSpaceChange[] = [CREATE_NO_LINKS];
37603777
const expected: ConfluenceSpaceChange[] = [UPDATE_NO_LINKS];
37613778
check(expected, changes, fileMetadataTable);
37623779
});
3780+
3781+
test(suiteLabel("one_update_link"), async () => {
3782+
const changes: ConfluenceSpaceChange[] = [UPDATE_LINKS_ONE];
3783+
const rootURL = "fake-server/wiki/spaces/QUARTOCONF/pages";
3784+
const expectedUpdate: ContentUpdate = {
3785+
...UPDATE_LINKS_ONE,
3786+
body: {
3787+
storage: {
3788+
value: `<a href=\'no-replace.qmd\'/>no</a> content content <a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/19857455/Team\'>team</a> content content <a href=\'zqmdzz.qmd\'>team</a>`,
3789+
representation: "storage",
3790+
},
3791+
},
3792+
};
3793+
const expected: ConfluenceSpaceChange[] = [expectedUpdate];
3794+
check(expected, changes, fileMetadataTable, "fake-server", FAKE_PARENT);
3795+
});
3796+
3797+
otest(suiteLabel("one_update_link_from_create"), async () => {
3798+
const changes: ConfluenceSpaceChange[] = [CREATE_LINKS_ONE];
3799+
const rootURL = "fake-server/wiki/spaces/QUARTOCONF/pages";
3800+
const expectedUpdate: ContentUpdate = {
3801+
...UPDATE_LINKS_ONE,
3802+
body: {
3803+
storage: {
3804+
value: `<a href=\'no-replace.qmd\'/>no</a> content content <a href=\'fake-server/wiki/spaces/QUARTOCONF/pages/19857455/Team\'>team</a> content content <a href=\'zqmdzz.qmd\'>team</a>`,
3805+
representation: "storage",
3806+
},
3807+
},
3808+
};
3809+
const expected: ConfluenceSpaceChange[] = [expectedUpdate];
3810+
check(expected, changes, fileMetadataTable, "fake-server", FAKE_PARENT);
3811+
});
37633812
};
37643813

37653814
const runFindAttachments = () => {

0 commit comments

Comments
 (0)