Skip to content

Commit

Permalink
feat(app-headless-cms): export groups and models (#3473)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric committed Oct 23, 2023
1 parent 0d7a3a8 commit 381f2a1
Show file tree
Hide file tree
Showing 70 changed files with 4,320 additions and 293 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ schema.graphql
!.yarn/versions
.pnp.*
lerna.json
.stormTests

# TODO remove after moving traffic splitting config to WPC
gateway.*.json
4 changes: 3 additions & 1 deletion packages/api-aco/__tests__/apps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe("aco apps", () => {
name: expect.any(String),
isPrivate: true
}),
isPlugin: true,
isPrivate: true,
tags: ["type:model"],
webinyVersion: "0.0.0"
Expand Down Expand Up @@ -130,6 +131,7 @@ describe("aco apps", () => {
name: expect.any(String),
isPrivate: true
}),
isPlugin: true,
isPrivate: true,
tags: ["type:model"],
webinyVersion: "0.0.0"
Expand Down Expand Up @@ -210,7 +212,7 @@ describe("aco apps", () => {
isPrivate: true,
titleFieldId: "id"
}
})
} as any)
);
} catch (ex) {
error = ex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe("Content entries", () => {
data: {
createFruitFrom: {
data: {
id: (secondBanana.id || "").replace("0002", "0003"),
id: expect.stringMatching(/0003$/),
entryId: banana.entryId,
meta: {
version: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe("content model test", () => {

expect(getTypeFields(ReadQuery)).toEqual(["getContentModel", "listContentModels"]);
expect(getTypeFields(ManageQuery)).toEqual([
"exportCmsStructure",
"exportStructure",
"getContentModel",
"listContentModels",
"searchContentEntries",
Expand All @@ -101,6 +101,8 @@ describe("content model test", () => {
]);
expect(getTypeFields(ReadMutation)).toEqual([]);
expect(getTypeFields(ManageMutation)).toEqual([
"validateImportStructure",
"importStructure",
"createContentModel",
"createContentModelFrom",
"updateContentModel",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { useGraphQLHandler } from "~tests/testHelpers/useGraphQLHandler";
import { createContentModelGroup } from "./mocks/contentModelGroup";
import { createCmsGroup } from "~/plugins";
import { CmsGroup } from "~tests/types";
import models from "./mocks/contentModels";
import { CmsModel, CmsModelField } from "~/types";
Expand All @@ -25,15 +23,26 @@ const groups: Omit<CmsGroup, "id">[] = [
}
];

const fixFieldsNullTexts = (fields: CmsModelField[]): CmsModelField[] => {
const fixFields = (fields: CmsModelField[]): CmsModelField[] => {
return fields.map(field => {
const result = {
...field,
helpText: field.helpText || null,
placeholderText: field.placeholderText || null
};
if (result.settings?.fields) {
result.settings.fields = fixFieldsNullTexts(result.settings.fields);
result.settings.fields = fixFields(result.settings.fields);
}
if (result.predefinedValues) {
result.predefinedValues = {
...result.predefinedValues,
values: (result.predefinedValues.values || []).map(value => {
return {
...value,
selected: value.selected || false
};
})
};
}
return result;
});
Expand All @@ -51,14 +60,13 @@ describe("export cms structure", () => {
return results;
};

it("should export only database groups and models", async () => {
it("should export all groups and models", async () => {
const {
exportCmsStructureQuery,
exportStructureQuery,
createContentModelGroupMutation,
createContentModelMutation
} = useGraphQLHandler({
path: "manage/en-US",
plugins: [createCmsGroup(createContentModelGroup())]
path: "manage/en-US"
});

const createdGroups = await insertGroups(createContentModelGroupMutation);
Expand Down Expand Up @@ -90,19 +98,17 @@ describe("export cms structure", () => {

expect(createdModels.length).toBe(models.length);

const [result] = await exportCmsStructureQuery({
code: false
});
const [result] = await exportStructureQuery();

expect(result).toEqual({
data: {
exportCmsStructure: {
exportStructure: {
data: expect.any(String),
error: null
}
}
});
const json = JSON.parse(result.data.exportCmsStructure.data) as JsonResult;
const json = JSON.parse(result.data.exportStructure.data) as JsonResult;
expect(json.groups.length).toBe(groups.length);
expect(json.models.length).toBe(models.length);
expect(json).toMatchObject({
Expand All @@ -125,12 +131,8 @@ describe("export cms structure", () => {
description: model.description,
titleFieldId: model.titleFieldId,
icon: model.icon,
group: {
id: group.id,
slug: group.slug,
name: group.name
},
fields: fixFieldsNullTexts(model.fields),
group: group.id,
fields: fixFields(model.fields),
layout: model.layout
});
expect(jsonModel.imageFieldId).toEqual(model.imageFieldId || undefined);
Expand Down

0 comments on commit 381f2a1

Please sign in to comment.