Skip to content

Commit

Permalink
feat(app-headless-cms): add support for nested dynamic zones and ref …
Browse files Browse the repository at this point in the history
…fields (#3471)
  • Loading branch information
Pavel910 committed Aug 31, 2023
1 parent c8a3e1f commit ec04ae7
Show file tree
Hide file tree
Showing 39 changed files with 1,019 additions and 495 deletions.
12 changes: 4 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,20 @@ const getPackageNameFromPath = value => {
return path.dirname(packageJson).split("/").pop();
};

const jestExecutable = process.argv.findIndex(arg => arg.endsWith("jest.js"));
const jestConfig = process.argv.findIndex(arg => arg.endsWith("jest.config.js"));
// This parameter is used by Webstorm, when running a particular test file.
const runByPath = process.argv.findIndex(arg => arg === "--runTestsByPath");
const isIntellij = process.argv.some(param => param.endsWith("jest-intellij-reporter.js"));

let packageName = "";
if (jestConfig > -1) {
packageName = getPackageNameFromPath(process.argv[jestConfig + 1]);
} else if (runByPath > -1) {
// Find the package this test file belongs to.
packageName = getPackageNameFromPath(process.argv[runByPath + 1]);
} else if (jestExecutable > -1) {
const target = process.argv[jestExecutable + 1];
if (target.includes("/")) {
packageName = getPackageNameFromPath(target);
} else {
packageName = target;
}
} else if (isIntellij) {
const target = process.argv.find(param => param.includes("/packages/"));
packageName = getPackageNameFromPath(target);
}

if (packageName.includes("packages")) {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"eslint-plugin-promise": "^5.2.0",
"eslint-plugin-react": "^7.27.1",
"eslint-plugin-standard": "^5.0.0",
"eslint-plugin-webiny-i18n": "link:./eslint/webiny-i18n",
"execa": "^1.0.0",
"flatten": "^1.0.2",
"folder-hash": "^4.0.0",
Expand Down
152 changes: 140 additions & 12 deletions packages/api-headless-cms/__tests__/contentAPI/dynamicZoneField.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,39 @@ const contentEntryQueryData = {
{
__typename: `${singularPageApiName}_Content_Objecting`,
nestedObject: {
__typename: `${singularPageApiName}_Content_Objecting_NestedObject`,
objectNestedObject: [
{
nestedObjectNestedTitle: "Objective nested title #1"
nestedObjectNestedTitle: "Content Objecting nested title #1"
},
{
nestedObjectNestedTitle: "Objective nested title #2"
nestedObjectNestedTitle: "Content Objecting nested title #2"
}
],
objectTitle: "Objective title #1"
},
dynamicZone: {
__typename: `${singularPageApiName}_Content_Objecting_DynamicZone_SuperNestedObject`,
authors: [
{
modelId: "author",
id: "john-doe#0001"
}
]
}
},
{
__typename: `${singularPageApiName}_Content_Author`,
author: {
modelId: "author",
id: "john-doe#0001"
},
authors: [
{
modelId: "author",
id: "john-doe#0001"
}
]
}
],
header: {
Expand Down Expand Up @@ -77,14 +100,24 @@ const contentEntryQueryData = {
},
__typename: `${singularPageApiName}_Reference_Author`
},
references: [
references1: {
authors: [
{
id: "john-doe#0001",
modelId: "author",
__typename: "RefField"
}
],
__typename: `${singularPageApiName}_References1_Authors`
},
references2: [
{
author: {
id: "john-doe#0001",
modelId: "author",
__typename: "RefField"
},
__typename: `${singularPageApiName}_References_Author`
__typename: `${singularPageApiName}_References2_Author`
}
]
};
Expand All @@ -106,14 +139,38 @@ const contentEntryMutationData = {
objectTitle: "Objective title #1",
objectNestedObject: [
{
nestedObjectNestedTitle: "Objective nested title #1"
nestedObjectNestedTitle: "Content Objecting nested title #1"
},
{
nestedObjectNestedTitle: "Objective nested title #2"
nestedObjectNestedTitle: "Content Objecting nested title #2"
}
]
},
dynamicZone: {
SuperNestedObject: {
authors: [
{
modelId: "author",
id: "john-doe#0001"
}
]
}
}
}
},
{
Author: {
author: {
modelId: "author",
id: "john-doe#0001"
},
authors: [
{
modelId: "author",
id: "john-doe#0001"
}
]
}
}
],
header: {
Expand Down Expand Up @@ -160,7 +217,17 @@ const contentEntryMutationData = {
}
}
},
references: [
references1: {
Authors: {
authors: [
{
id: "john-doe#0001",
modelId: "author"
}
]
}
},
references2: [
{
Author: {
author: {
Expand Down Expand Up @@ -224,6 +291,24 @@ describe("dynamicZone field", () => {
}
}
});

const [updatePageResponse] = await manage.updatePage({
revision: createPageResponse.data.createPage.data.id,
data: contentEntryMutationData
});

expect(updatePageResponse).toEqual({
data: {
updatePage: {
data: {
id: expect.any(String),
...contentEntryQueryData
},
error: null
}
}
});

const page = createPageResponse.data.createPage.data;

const [manageList] = await manage.listPages();
Expand Down Expand Up @@ -281,21 +366,64 @@ describe("dynamicZone field", () => {
data: {
id: page.id,
...contentEntryQueryData,
content: [
...contentEntryQueryData.content.slice(0, 3),
{
...contentEntryQueryData.content[3],
dynamicZone: {
authors: [
{
entryId: "john-doe",
fullName: "John Doe",
id: "john-doe#0001",
modelId: "author"
}
]
}
},
{
__typename: contentEntryQueryData.content[4].__typename,
author: {
entryId: "john-doe",
fullName: "John Doe",
id: "john-doe#0001",
modelId: "author"
},
authors: [
{
entryId: "john-doe",
fullName: "John Doe",
id: "john-doe#0001",
modelId: "author"
}
]
}
],
reference: {
author: {
entryId: "john-doe",
fullName: "John Doe",
id: contentEntryQueryData.reference.author.id,
modelId: contentEntryQueryData.reference.author.modelId
id: "john-doe#0001",
modelId: "author"
}
},
references: [
references1: {
authors: [
{
entryId: "john-doe",
fullName: "John Doe",
id: "john-doe#0001",
modelId: "author"
}
]
},
references2: [
{
author: {
entryId: "john-doe",
fullName: "John Doe",
id: contentEntryQueryData.references[0].author.id,
modelId: contentEntryQueryData.references[0].author.modelId
id: "john-doe#0001",
modelId: "author"
}
}
]
Expand Down

0 comments on commit ec04ae7

Please sign in to comment.