Skip to content

Commit

Permalink
Merge branch 'dev' into next
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/cli-plugin-deploy-pulumi/package.json
#	yarn.lock
  • Loading branch information
Pavel910 committed Jul 24, 2024
2 parents cfe49a4 + deb698c commit 464cab0
Show file tree
Hide file tree
Showing 87 changed files with 8,297 additions and 1,736 deletions.
2 changes: 2 additions & 0 deletions .adiorc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module.exports = {
"fs",
"http",
"https",
"inspector",
"node:fs",
"os",
"path",
"readline",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@octokit/rest": "^20.0.2",
"@types/fs-extra": "^8.0.1",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.11",
"@types/node": "^18.0.0",
"@types/prettier": "^2.7.3",
Expand Down Expand Up @@ -63,7 +63,7 @@
"eslint-plugin-standard": "^5.0.0",
"execa": "^5.1.1",
"folder-hash": "^4.0.0",
"fs-extra": "^7.0.0",
"fs-extra": "^11.2.0",
"get-stream": "^3.0.0",
"get-yarn-workspaces": "^1.0.2",
"git-cz": "^1.7.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-form-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@webiny/cli": "0.0.0",
"@webiny/project-utils": "0.0.0",
"csvtojson": "^2.0.10",
"fs-extra": "^9.1.0",
"fs-extra": "^11.2.0",
"jest": "^29.7.0",
"jest-dynalite": "^3.2.0",
"rimraf": "^5.0.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import { createLongTextStorageTransformPlugin } from "~/dynamoDb/storage/longTex
import { createRichTextStorageTransformPlugin } from "~/dynamoDb/storage/richText";
import { createDefaultStorageTransform } from "@webiny/api-headless-cms/storage/default";
import { createObjectStorageTransform } from "@webiny/api-headless-cms/storage/object";
import { createDynamicZoneStorageTransform } from "@webiny/api-headless-cms/graphqlFields/dynamicZone/dynamicZoneStorage";

export const createStoragePluginsContainer = () => {
return new PluginsContainer([
createDefaultStorageTransform(),
createObjectStorageTransform(),
createDateStorageTransformPlugin(),
createLongTextStorageTransformPlugin(),
createRichTextStorageTransformPlugin(),
createDynamicZoneStorageTransform()
createRichTextStorageTransformPlugin()
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import { createLongTextStorageTransformPlugin } from "~/dynamoDb/storage/longTex
import { createRichTextStorageTransformPlugin } from "~/dynamoDb/storage/richText";
import { createDefaultStorageTransform } from "@webiny/api-headless-cms/storage/default";
import { createObjectStorageTransform } from "@webiny/api-headless-cms/storage/object";
import { createDynamicZoneStorageTransform } from "@webiny/api-headless-cms/graphqlFields/dynamicZone/dynamicZoneStorage";

export const createStoragePluginsContainer = () => {
return new PluginsContainer([
createDefaultStorageTransform(),
createObjectStorageTransform(),
createDateStorageTransformPlugin(),
createLongTextStorageTransformPlugin(),
createRichTextStorageTransformPlugin(),
createDynamicZoneStorageTransform()
createRichTextStorageTransformPlugin()
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ describe("content model test", () => {
});
});

test("error when assigning titleFieldId on non existing field", async () => {
test("when assigning `titleFieldId` to a non-existing field, fall back to the first applicable field", async () => {
const { createContentModelMutation, updateContentModelMutation } =
useGraphQLHandler(manageHandlerOpts);
const [createResponse] = await createContentModelMutation({
Expand Down Expand Up @@ -649,15 +649,10 @@ describe("content model test", () => {
expect(response).toMatchObject({
data: {
updateContentModel: {
data: null,
error: {
code: "VALIDATION_ERROR",
message: `Field selected for the title field does not exist in the model.`,
data: {
fieldId: "nonExistingTitleFieldId",
fields: expect.any(Array)
}
}
data: {
titleFieldId: "field1"
},
error: null
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { usePageManageHandler } from "../testHelpers/usePageManageHandler";
import { usePageReadHandler } from "../testHelpers/usePageReadHandler";
import { useAuthorManageHandler } from "~tests/testHelpers/useAuthorManageHandler";
import { CmsModel } from "~tests/types";
import { ContextPlugin } from "@webiny/api";
import { CmsContext, CmsEntry } from "~/types";

const singularPageApiName = pageModel.singularApiName;

Expand Down Expand Up @@ -266,11 +268,45 @@ const setupAuthor = async ({ manager }: SetupAuthorParams) => {
return authorPublishResponse.data.publishAuthor.data;
};

type Values = {
content: Array<{ _templateId: string }>;
};

describe("dynamicZone field", () => {
const manageOpts = { path: "manage/en-US" };
const previewOpts = { path: "preview/en-US" };

const manage = usePageManageHandler(manageOpts);
const eventEntryContent: {
beforeCreate: CmsEntry<Values> | undefined;
afterCreate: CmsEntry<Values> | undefined;
beforeUpdate: CmsEntry<Values> | undefined;
afterUpdate: CmsEntry<Values> | undefined;
} = {
beforeCreate: undefined,
afterCreate: undefined,
beforeUpdate: undefined,
afterUpdate: undefined
};

const lifecycleEvents = new ContextPlugin<CmsContext>(async (context: CmsContext) => {
if (!context.cms) {
throw new Error("Missing cms on context.");
}
context.cms.onEntryBeforeCreate.subscribe(async params => {
eventEntryContent.beforeCreate = structuredClone(params.entry) as CmsEntry<Values>;
});
context.cms.onEntryAfterCreate.subscribe(async params => {
eventEntryContent.afterCreate = structuredClone(params.entry) as CmsEntry<Values>;
});
context.cms.onEntryBeforeUpdate.subscribe(async params => {
eventEntryContent.beforeUpdate = structuredClone(params.entry) as CmsEntry<Values>;
});
context.cms.onEntryAfterUpdate.subscribe(async params => {
eventEntryContent.afterUpdate = structuredClone(params.entry) as CmsEntry<Values>;
});
});

const manage = usePageManageHandler({ ...manageOpts, bottomPlugins: [lifecycleEvents] });

const authorManager = useAuthorManageHandler({
...manageOpts
Expand Down Expand Up @@ -443,5 +479,12 @@ describe("dynamicZone field", () => {
}
}
});

const tplIsConverted = <T>(tpl: T) => "_templateId" in tpl;

expect(eventEntryContent.beforeCreate?.values.content.every(tplIsConverted)).toEqual(true);
expect(eventEntryContent.afterCreate?.values.content.every(tplIsConverted)).toEqual(true);
expect(eventEntryContent.beforeUpdate?.values.content.every(tplIsConverted)).toEqual(true);
expect(eventEntryContent.afterUpdate?.values.content.every(tplIsConverted)).toEqual(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,13 @@ describe("multiple values in field", () => {
}
});

expect(response).toEqual({
expect(response).toMatchObject({
data: {
updateContentModel: {
data: null,
error: {
code: "ENTRY_TITLE_FIELD_TYPE",
message:
"Fields that accept multiple values cannot be used as the entry title.",
data: {
storageId: expect.stringMatching("text@"),
fieldId: "availableSizes",
type: "text"
}
}
data: {
titleFieldId: "title"
},
error: null
}
}
});
Expand Down
124 changes: 10 additions & 114 deletions packages/api-headless-cms/__tests__/contentAPI/predefinedValues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("predefined values", () => {

const setupBugModel = async (
contentModelGroup: CmsGroup,
overrides: Record<string, any> = {}
overrides: (model: CmsModel) => Partial<CmsModel> = () => ({})
): Promise<CmsModel> => {
const model = models.find(m => m.modelId === "bug");
if (!model) {
Expand All @@ -53,15 +53,15 @@ describe("predefined values", () => {
data: {
fields: model.fields,
layout: model.layout,
...overrides
...(overrides ? overrides(model) : {})
}
});
return update.data.updateContentModel.data;
};

test("should create an entry with predefined values selected", async () => {
const contentModelGroup = await setupContentModelGroup();
await setupBugModel(contentModelGroup, {});
await setupBugModel(contentModelGroup);

const { createBug } = useBugManageHandler({
...manageOpts
Expand Down Expand Up @@ -111,7 +111,7 @@ describe("predefined values", () => {

test("should fail creating an entry with wrong predefined text value selected", async () => {
const contentModelGroup = await setupContentModelGroup();
await setupBugModel(contentModelGroup, {});
await setupBugModel(contentModelGroup);

const { createBug } = useBugManageHandler({
...manageOpts
Expand Down Expand Up @@ -150,7 +150,7 @@ describe("predefined values", () => {

test("should fail creating an entry with wrong predefined number value selected", async () => {
const contentModelGroup = await setupContentModelGroup();
await setupBugModel(contentModelGroup, {});
await setupBugModel(contentModelGroup);

const { createBug } = useBugManageHandler({
...manageOpts
Expand Down Expand Up @@ -189,7 +189,7 @@ describe("predefined values", () => {

test("should fail creating an entry with wrong predefined number and text values selected", async () => {
const contentModelGroup = await setupContentModelGroup();
await setupBugModel(contentModelGroup, {});
await setupBugModel(contentModelGroup);

const { createBug } = useBugManageHandler({
...manageOpts
Expand Down Expand Up @@ -233,115 +233,11 @@ describe("predefined values", () => {
});
});

test("title should be a selected predefined text value label", async () => {
const contentModelGroup = await setupContentModelGroup();
await setupBugModel(contentModelGroup, {
titleFieldId: "bugType"
});

const { createBug } = useBugManageHandler({
...manageOpts
});

const [response] = await createBug({
data: {
name: "A hard debuggable bug",
bugType: "critical",
bugValue: 2,
bugFixed: 3
}
});

expect(response).toEqual({
data: {
createBug: {
data: {
id: expect.any(String),
createdOn: expect.stringMatching(/^20/),
modifiedOn: null,
savedOn: expect.stringMatching(/^20/),
createdBy: {
id: "id-12345678",
displayName: "John Doe",
type: "admin"
},
lastPublishedOn: null,
firstPublishedOn: null,
meta: {
locked: false,
modelId: "bug",
status: "draft",
title: "Critical bug!",
version: 1
},
name: "A hard debuggable bug",
bugType: "critical",
bugValue: 2,
bugFixed: 3
},
error: null
}
}
});
});

test("title should be a selected predefined number value label", async () => {
const contentModelGroup = await setupContentModelGroup();
await setupBugModel(contentModelGroup, {
titleFieldId: "bugValue"
});

const { createBug } = useBugManageHandler({
...manageOpts
});

const [response] = await createBug({
data: {
name: "A hard debuggable bug",
bugType: "critical",
bugValue: 3,
bugFixed: 3
}
});

expect(response).toEqual({
data: {
createBug: {
data: {
id: expect.any(String),
createdOn: expect.stringMatching(/^20/),
modifiedOn: null,
savedOn: expect.stringMatching(/^20/),
createdBy: {
id: "id-12345678",
displayName: "John Doe",
type: "admin"
},
lastPublishedOn: null,
firstPublishedOn: null,
meta: {
locked: false,
modelId: "bug",
status: "draft",
title: "High bug value",
version: 1
},
name: "A hard debuggable bug",
bugType: "critical",
bugValue: 3,
bugFixed: 3
},
error: null
}
}
});
});

it("should be able to create an entry with default bug type value", async () => {
const contentModelGroup = await setupContentModelGroup();
const bugModel = await setupBugModel(contentModelGroup, {
const bugModel = await setupBugModel(contentModelGroup, () => ({
titleFieldId: "bugValue"
});
}));

const { createBug } = useBugManageHandler({
...manageOpts
Expand Down Expand Up @@ -377,7 +273,7 @@ describe("predefined values", () => {
locked: false,
modelId: "bug",
status: "draft",
title: "High bug value",
title: "A hard debuggable bug - none",
version: 1
},
name: "A hard debuggable bug - none",
Expand Down Expand Up @@ -456,7 +352,7 @@ describe("predefined values", () => {
locked: false,
modelId: "bug",
status: "draft",
title: "High bug value",
title: "A hard debuggable bug - undefined",
version: 1
},
name: "A hard debuggable bug - undefined",
Expand Down
Loading

0 comments on commit 464cab0

Please sign in to comment.