Skip to content

Commit 4661c31

Browse files
committed
test: Get changelog page id using its parent
1 parent 7c48692 commit 4661c31

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

.github/CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ The tests require the following environment variables to be set, which can be de
8383
CONFLUENCE_URL=https://your-confluence-url.net
8484
CONFLUENCE_PAT=******
8585
CONFLUENCE_README_PAGE_ID=page-id-of-the-readme-page
86-
CONFLUENCE_CHANGELOG_PAGE_ID=page-id-of-the-changelog-page
8786
```
8887

8988
## Branching model

test/e2e/specs/check-sync.spec.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,41 @@ import {
66
getChangelogPageBody,
77
getChangelogPageTitle,
88
getReadmePageTitle,
9+
getReadmePageChildren,
910
} from "../support/confluence";
1011

1112
describe("check sync", () => {
1213
describe("readme page", () => {
1314
it("should have right title", async () => {
14-
const changelogPageTitle = await getReadmePageTitle();
15+
const pageTitle = await getReadmePageTitle();
1516

16-
expect(changelogPageTitle).toEqual(
17+
expect(pageTitle).toEqual(
1718
expect.stringContaining("[Cross] Markdown Confluence Sync"),
1819
);
1920
});
21+
22+
it("should have one child", async () => {
23+
const pageChildren = await getReadmePageChildren();
24+
25+
expect(pageChildren?.length).toBe(1);
26+
});
2027
});
2128

2229
describe("release page", () => {
2330
it("should have right title", async () => {
24-
const changelogPageTitle = await getChangelogPageTitle();
31+
const pageTitle = await getChangelogPageTitle();
2532

26-
expect(changelogPageTitle).toEqual(
33+
expect(pageTitle).toEqual(
2734
expect.stringContaining("[Cross] [Markdown Confluence Sync] Releases"),
2835
);
2936
});
3037

3138
it("should include the latest release", async () => {
3239
const version = await getLatestVersion();
3340

34-
const changelogPage = await getChangelogPageBody();
41+
const pageContent = await getChangelogPageBody();
3542

36-
expect(changelogPage).toEqual(expect.stringContaining(version));
43+
expect(pageContent).toEqual(expect.stringContaining(version));
3744
});
3845
});
3946
});

test/e2e/support/confluence.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ConfluenceClient } from "confluence.js";
22

3-
const CHANGELOG_PAGE_ID = process.env.CONFLUENCE_CHANGELOG_PAGE_ID as string;
43
const README_PAGE_ID = process.env.CONFLUENCE_ROOT_PAGE_ID as string;
54

65
/**
@@ -17,26 +16,48 @@ function createConfluenceClient() {
1716
});
1817
}
1918

20-
async function getChangelogPageContent(id: string) {
19+
async function getPageContent(id: string) {
2120
const client = createConfluenceClient();
2221
const content = await client.content.getContentById({
2322
id,
24-
expand: ["body.view"],
23+
expand: ["body.view", "children.page"],
2524
});
2625
return content;
2726
}
2827

28+
async function getReadmePageContent() {
29+
return getPageContent(README_PAGE_ID);
30+
}
31+
32+
export async function getReadmePageChildren() {
33+
const content = await getReadmePageContent();
34+
return content.children?.page?.results;
35+
}
36+
37+
async function getChangelogPageContent() {
38+
const readmeChildren = await getReadmePageChildren();
39+
const changelogId = readmeChildren ? readmeChildren[0]?.id : undefined;
40+
41+
if (!changelogId) {
42+
throw new Error("Readme page does not have any children");
43+
}
44+
45+
const changelogContent = await getPageContent(changelogId);
46+
47+
return changelogContent;
48+
}
49+
2950
export async function getChangelogPageBody() {
30-
const content = await getChangelogPageContent(CHANGELOG_PAGE_ID);
51+
const content = await getChangelogPageContent();
3152
return content.body?.view?.value;
3253
}
3354

3455
export async function getChangelogPageTitle() {
35-
const content = await getChangelogPageContent(CHANGELOG_PAGE_ID);
56+
const content = await getChangelogPageContent();
3657
return content.title;
3758
}
3859

3960
export async function getReadmePageTitle() {
40-
const content = await getChangelogPageContent(README_PAGE_ID);
61+
const content = await getReadmePageContent();
4162
return content.title;
4263
}

0 commit comments

Comments
 (0)