Skip to content

Commit

Permalink
fix(api-headless-cms): add missing fields dynamic zone sdl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric committed Nov 21, 2024
1 parent 0eb806e commit ebb5268
Show file tree
Hide file tree
Showing 4 changed files with 343 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export default /* GraphQL */ `
type PageModelApiName_Content_Hero {
title: String
date: Date
time: Time
dateTimeWithTimezone: DateTimeZ
dateTimeWithoutTimezone: DateTime
}
type PageModelApiName_Content_SimpleText {
Expand All @@ -90,6 +94,10 @@ export default /* GraphQL */ `
type PageModelApiName_Content_Objecting_NestedObject_ObjectNestedObject {
nestedObjectNestedTitle: String
date: Date
time: Time
dateTimeWithTimezone: DateTimeZ
dateTimeWithoutTimezone: DateTime
}
input PageModelApiName_Content_Objecting_NestedObject_ObjectNestedObjectWhereInput {
Expand All @@ -101,6 +109,42 @@ export default /* GraphQL */ `
nestedObjectNestedTitle_not_contains: String
nestedObjectNestedTitle_startsWith: String
nestedObjectNestedTitle_not_startsWith: String
date: Date
date_not: Date
date_in: [Date]
date_not_in: [Date]
date_lt: Date
date_lte: Date
date_gt: Date
date_gte: Date
time: Time
time_not: Time
time_in: [Time]
time_not_in: [Time]
time_lt: Time
time_lte: Time
time_gt: Time
time_gte: Time
dateTimeWithTimezone: DateTimeZ
dateTimeWithTimezone_not: DateTimeZ
dateTimeWithTimezone_in: [DateTimeZ]
dateTimeWithTimezone_not_in: [DateTimeZ]
dateTimeWithTimezone_lt: DateTimeZ
dateTimeWithTimezone_lte: DateTimeZ
dateTimeWithTimezone_gt: DateTimeZ
dateTimeWithTimezone_gte: DateTimeZ
dateTimeWithoutTimezone: DateTime
dateTimeWithoutTimezone_not: DateTime
dateTimeWithoutTimezone_in: [DateTime]
dateTimeWithoutTimezone_not_in: [DateTime]
dateTimeWithoutTimezone_lt: DateTime
dateTimeWithoutTimezone_lte: DateTime
dateTimeWithoutTimezone_gt: DateTime
dateTimeWithoutTimezone_gte: DateTime
}
type PageModelApiName_Content_Objecting_NestedObject {
Expand Down Expand Up @@ -183,6 +227,10 @@ export default /* GraphQL */ `
type PageModelApiName_Objective_Objecting_NestedObject_ObjectNestedObject {
nestedObjectNestedTitle: String
date: Date
time: Time
dateTimeWithTimezone: DateTimeZ
dateTimeWithoutTimezone: DateTime
}
input PageModelApiName_Objective_Objecting_NestedObject_ObjectNestedObjectWhereInput {
Expand All @@ -194,6 +242,42 @@ export default /* GraphQL */ `
nestedObjectNestedTitle_not_contains: String
nestedObjectNestedTitle_startsWith: String
nestedObjectNestedTitle_not_startsWith: String
date: Date
date_not: Date
date_in: [Date]
date_not_in: [Date]
date_lt: Date
date_lte: Date
date_gt: Date
date_gte: Date
time: Time
time_not: Time
time_in: [Time]
time_not_in: [Time]
time_lt: Time
time_lte: Time
time_gt: Time
time_gte: Time
dateTimeWithTimezone: DateTimeZ
dateTimeWithTimezone_not: DateTimeZ
dateTimeWithTimezone_in: [DateTimeZ]
dateTimeWithTimezone_not_in: [DateTimeZ]
dateTimeWithTimezone_lt: DateTimeZ
dateTimeWithTimezone_lte: DateTimeZ
dateTimeWithTimezone_gt: DateTimeZ
dateTimeWithTimezone_gte: DateTimeZ
dateTimeWithoutTimezone: DateTime
dateTimeWithoutTimezone_not: DateTime
dateTimeWithoutTimezone_in: [DateTime]
dateTimeWithoutTimezone_not_in: [DateTime]
dateTimeWithoutTimezone_lt: DateTime
dateTimeWithoutTimezone_lte: DateTime
dateTimeWithoutTimezone_gt: DateTime
dateTimeWithoutTimezone_gte: DateTime
}
type PageModelApiName_Objective_Objecting_NestedObject {
Expand Down Expand Up @@ -263,6 +347,10 @@ export default /* GraphQL */ `
input PageModelApiName_Content_HeroInput {
title: String
date: Date
time: Time
dateTimeWithTimezone: DateTimeZ
dateTimeWithoutTimezone: DateTime
}
input PageModelApiName_Content_SimpleTextInput {
Expand All @@ -271,6 +359,10 @@ export default /* GraphQL */ `
input PageModelApiName_Content_Objecting_NestedObject_ObjectNestedObjectInput {
nestedObjectNestedTitle: String
date: Date
time: Time
dateTimeWithTimezone: DateTimeZ
dateTimeWithoutTimezone: DateTime
}
input PageModelApiName_Content_Objecting_NestedObjectInput {
Expand Down Expand Up @@ -319,6 +411,10 @@ export default /* GraphQL */ `
input PageModelApiName_Objective_Objecting_NestedObject_ObjectNestedObjectInput {
nestedObjectNestedTitle: String
date: Date
time: Time
dateTimeWithTimezone: DateTimeZ
dateTimeWithoutTimezone: DateTime
}
input PageModelApiName_Objective_Objecting_NestedObjectInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export default /* GraphQL */ `
type PageModelApiName_Content_Hero {
title: String
date: Date
time: Time
dateTimeWithTimezone: DateTimeZ
dateTimeWithoutTimezone: DateTime
}
type PageModelApiName_Content_SimpleText {
Expand All @@ -68,6 +72,10 @@ export default /* GraphQL */ `
type PageModelApiName_Content_Objecting_NestedObject_ObjectNestedObject {
nestedObjectNestedTitle: String
date: Date
time: Time
dateTimeWithTimezone: DateTimeZ
dateTimeWithoutTimezone: DateTime
}
input PageModelApiName_Content_Objecting_NestedObject_ObjectNestedObjectWhereInput {
Expand All @@ -79,6 +87,42 @@ export default /* GraphQL */ `
nestedObjectNestedTitle_not_contains: String
nestedObjectNestedTitle_startsWith: String
nestedObjectNestedTitle_not_startsWith: String
date: Date
date_not: Date
date_in: [Date]
date_not_in: [Date]
date_lt: Date
date_lte: Date
date_gt: Date
date_gte: Date
time: Time
time_not: Time
time_in: [Time]
time_not_in: [Time]
time_lt: Time
time_lte: Time
time_gt: Time
time_gte: Time
dateTimeWithTimezone: DateTimeZ
dateTimeWithTimezone_not: DateTimeZ
dateTimeWithTimezone_in: [DateTimeZ]
dateTimeWithTimezone_not_in: [DateTimeZ]
dateTimeWithTimezone_lt: DateTimeZ
dateTimeWithTimezone_lte: DateTimeZ
dateTimeWithTimezone_gt: DateTimeZ
dateTimeWithTimezone_gte: DateTimeZ
dateTimeWithoutTimezone: DateTime
dateTimeWithoutTimezone_not: DateTime
dateTimeWithoutTimezone_in: [DateTime]
dateTimeWithoutTimezone_not_in: [DateTime]
dateTimeWithoutTimezone_lt: DateTime
dateTimeWithoutTimezone_lte: DateTime
dateTimeWithoutTimezone_gt: DateTime
dateTimeWithoutTimezone_gte: DateTime
}
type PageModelApiName_Content_Objecting_NestedObject {
Expand Down Expand Up @@ -133,6 +177,10 @@ export default /* GraphQL */ `
type PageModelApiName_Objective_Objecting_NestedObject_ObjectNestedObject {
nestedObjectNestedTitle: String
date: Date
time: Time
dateTimeWithTimezone: DateTimeZ
dateTimeWithoutTimezone: DateTime
}
input PageModelApiName_Objective_Objecting_NestedObject_ObjectNestedObjectWhereInput {
Expand All @@ -144,6 +192,42 @@ export default /* GraphQL */ `
nestedObjectNestedTitle_not_contains: String
nestedObjectNestedTitle_startsWith: String
nestedObjectNestedTitle_not_startsWith: String
date: Date
date_not: Date
date_in: [Date]
date_not_in: [Date]
date_lt: Date
date_lte: Date
date_gt: Date
date_gte: Date
time: Time
time_not: Time
time_in: [Time]
time_not_in: [Time]
time_lt: Time
time_lte: Time
time_gt: Time
time_gte: Time
dateTimeWithTimezone: DateTimeZ
dateTimeWithTimezone_not: DateTimeZ
dateTimeWithTimezone_in: [DateTimeZ]
dateTimeWithTimezone_not_in: [DateTimeZ]
dateTimeWithTimezone_lt: DateTimeZ
dateTimeWithTimezone_lte: DateTimeZ
dateTimeWithTimezone_gt: DateTimeZ
dateTimeWithTimezone_gte: DateTimeZ
dateTimeWithoutTimezone: DateTime
dateTimeWithoutTimezone_not: DateTime
dateTimeWithoutTimezone_in: [DateTime]
dateTimeWithoutTimezone_not_in: [DateTime]
dateTimeWithoutTimezone_lt: DateTime
dateTimeWithoutTimezone_lte: DateTime
dateTimeWithoutTimezone_gt: DateTime
dateTimeWithoutTimezone_gte: DateTime
}
type PageModelApiName_Objective_Objecting_NestedObject {
Expand Down
96 changes: 92 additions & 4 deletions packages/api-headless-cms/__tests__/plugins/storage/dynamicZone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PluginsContainer } from "@webiny/plugins";

const field = pageModel.fields.find(f => f.id === "peeeyhtc") as CmsModelDynamicZoneField;

const inputValue = [
const initialValue = [
{
text: "Simple Text #1",
_templateId: "81qiz2v453wx9uque0gox"
Expand Down Expand Up @@ -76,7 +76,76 @@ const inputValue = [
_templateId: "qi81z2v453wx9uque0gox"
}
];
const expectedValue = [
const expectedInitialValue = [
{
text: "Simple Text #1",
_templateId: "81qiz2v453wx9uque0gox"
},
{
title: "Hero Title #1",
date: new Date("2024-11-05"),
time: "11:05:59",
dateTimeWithoutTimezone: new Date("2024-11-05T11:05:59.000Z"),
dateTimeWithTimezone: "2024-11-05T11:05:59.000+01:00",
_templateId: "cv2zf965v324ivdc7e1vt"
},
{
title: "Hero Title #2",
date: new Date("2024-11-05"),
time: "11:05:59",
dateTimeWithoutTimezone: new Date("2024-11-06T11:05:59.000Z"),
dateTimeWithTimezone: "2024-11-06T11:05:59.000+01:00",
_templateId: "cv2zf965v324ivdc7e1vt"
},
{
nestedObject: {
objectTitle: "Objective title #1",
objectNestedObject: [
{
nestedObjectNestedTitle: "Content Objecting nested title #1",
date: new Date("2024-11-05"),
time: "11:05:59",
dateTimeWithoutTimezone: new Date("2024-11-05T11:05:59.000Z"),
dateTimeWithTimezone: "2024-11-05T11:05:59.000+01:00"
},
{
nestedObjectNestedTitle: "Content Objecting nested title #2",
date: new Date("2024-11-05"),
time: "11:05:59",
dateTimeWithoutTimezone: new Date("2024-11-06T11:05:59.000Z"),
dateTimeWithTimezone: "2024-11-06T11:05:59.000+01:00"
}
]
},
dynamicZone: {
authors: [
{
id: "john-doe#0001",
entryId: "john-doe",
modelId: "author"
}
],
_templateId: "0emukbsvmzpozx2lzk883"
},
_templateId: "9ht43gurhegkbdfsaafyads"
},
{
author: {
id: "john-doe#0001",
entryId: "john-doe",
modelId: "author"
},
authors: [
{
id: "john-doe#0001",
entryId: "john-doe",
modelId: "author"
}
],
_templateId: "qi81z2v453wx9uque0gox"
}
];
const expectedToStorageValue = [
{
text: "Simple Text #1",
_templateId: "81qiz2v453wx9uque0gox"
Expand Down Expand Up @@ -156,12 +225,31 @@ describe("dynamic zone storage transform", () => {
it("should properly transform data to storage", async () => {
const result = await plugin.toStorage({
field,
value: inputValue,
value: initialValue,
getStoragePlugin,
model: pageModel as CmsModel,
plugins
});

expect(result).toEqual(expectedValue);
expect(result).toEqual(expectedToStorageValue);
});

it("should transform data from storage", async () => {
const input = await plugin.toStorage({
field,
value: initialValue,
getStoragePlugin,
model: pageModel as CmsModel,
plugins
});

const result = await plugin.fromStorage({
field,
value: input,
getStoragePlugin,
model: pageModel as CmsModel,
plugins
});
expect(result).toEqual(expectedInitialValue);
});
});
Loading

0 comments on commit ebb5268

Please sign in to comment.