Skip to content

Commit dffb9ef

Browse files
committed
Merge remote-tracking branch 'origin/dev' into next
2 parents c2b3cdf + f5e8c70 commit dffb9ef

File tree

39 files changed

+601
-160
lines changed

39 files changed

+601
-160
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { useCategoryManageHandler } from "~tests/testHelpers/useCategoryManageHandler";
2+
import { setupGroupAndModels } from "~tests/testHelpers/setup";
3+
import { createCategoryManageMethods } from "~tests/contentAPI/helpers/category.manage";
4+
import { createCategoryPreviewMethods } from "~tests/contentAPI/helpers/category.preview";
5+
import { useCategoryPreviewHandler } from "~tests/testHelpers/useCategoryPreviewHandler";
6+
7+
describe("Content Entry - preview - get By ID", () => {
8+
const manager = useCategoryManageHandler({
9+
path: "manage/en-US"
10+
});
11+
const previewer = useCategoryPreviewHandler({
12+
path: "preview/en-US"
13+
});
14+
15+
const { createCategoryFrom, createCategory, publishCategory } =
16+
createCategoryManageMethods(manager);
17+
18+
const { getCategoryById } = createCategoryPreviewMethods(previewer);
19+
20+
beforeEach(async () => {
21+
await setupGroupAndModels({
22+
manager,
23+
models: ["category"]
24+
});
25+
});
26+
27+
it("should get an entry by id", async () => {
28+
const fruitsV1 = await createCategory({
29+
title: "Fruits",
30+
slug: "fruits"
31+
});
32+
33+
const fruitsV2 = await createCategoryFrom(fruitsV1);
34+
35+
const fruitsV2PreviewUnpublished = await getCategoryById(fruitsV2.id);
36+
const fruitsV1PreviewUnpublished = await getCategoryById(fruitsV1.id);
37+
38+
expect(fruitsV2PreviewUnpublished).toMatchObject({
39+
id: fruitsV2.id,
40+
entryId: fruitsV2.entryId,
41+
title: fruitsV2.title,
42+
slug: fruitsV2.slug
43+
});
44+
expect(fruitsV1PreviewUnpublished).toMatchObject({
45+
id: fruitsV1.id,
46+
entryId: fruitsV1.entryId,
47+
title: fruitsV1.title,
48+
slug: fruitsV1.slug
49+
});
50+
51+
const publishedFruitsV2 = await publishCategory(fruitsV2.id);
52+
53+
expect(publishedFruitsV2).toMatchObject({
54+
id: fruitsV2.id,
55+
entryId: fruitsV2.entryId,
56+
title: fruitsV2.title,
57+
slug: fruitsV2.slug,
58+
meta: {
59+
status: "published"
60+
}
61+
});
62+
63+
const fruitsV2PreviewPublished = await getCategoryById(fruitsV2.id);
64+
expect(fruitsV2PreviewPublished).toMatchObject({
65+
id: fruitsV2.id,
66+
entryId: fruitsV2.entryId,
67+
title: fruitsV2.title,
68+
slug: fruitsV2.slug
69+
});
70+
});
71+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { useCategoryManageHandler } from "~tests/testHelpers/useCategoryManageHandler";
2+
import { useCategoryReadHandler } from "~tests/testHelpers/useCategoryReadHandler";
3+
import { setupGroupAndModels } from "~tests/testHelpers/setup";
4+
import { createCategoryManageMethods } from "~tests/contentAPI/helpers/category.manage";
5+
import { createCategoryReadMethods } from "~tests/contentAPI/helpers/category.read";
6+
7+
describe("Content Entry - read - get By ID", () => {
8+
const manager = useCategoryManageHandler({
9+
path: "manage/en-US"
10+
});
11+
const reader = useCategoryReadHandler({
12+
path: "read/en-US"
13+
});
14+
15+
const { createCategoryFrom, createCategory, publishCategory } =
16+
createCategoryManageMethods(manager);
17+
18+
const { getCategoryById } = createCategoryReadMethods(reader);
19+
20+
beforeEach(async () => {
21+
await setupGroupAndModels({
22+
manager,
23+
models: ["category"]
24+
});
25+
});
26+
27+
it("should get an entry by id", async () => {
28+
const fruitsV1 = await createCategory({
29+
title: "Fruits",
30+
slug: "fruits"
31+
});
32+
33+
const fruitsV2 = await createCategoryFrom(fruitsV1);
34+
35+
const fruitsV2ReadUnpublished = await getCategoryById(fruitsV2.id);
36+
const fruitsV1ReadUnpublished = await getCategoryById(fruitsV1.id);
37+
38+
expect(fruitsV2ReadUnpublished).toEqual(null);
39+
expect(fruitsV1ReadUnpublished).toEqual(null);
40+
41+
const publishedFruitsV2 = await publishCategory(fruitsV2.id);
42+
43+
expect(publishedFruitsV2).toMatchObject({
44+
id: fruitsV2.id,
45+
entryId: fruitsV2.entryId,
46+
title: fruitsV2.title,
47+
slug: fruitsV2.slug,
48+
meta: {
49+
status: "published"
50+
}
51+
});
52+
53+
const fruitsV2ReadPublished = await getCategoryById(fruitsV2.id);
54+
expect(fruitsV2ReadPublished).toMatchObject({
55+
id: fruitsV2.id,
56+
entryId: fruitsV2.entryId,
57+
title: fruitsV2.title,
58+
slug: fruitsV2.slug
59+
});
60+
});
61+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { useCategoryManageHandler } from "~tests/testHelpers/useCategoryManageHandler";
2+
3+
export interface CategoryParams {
4+
title: string;
5+
slug: string;
6+
}
7+
8+
export interface CategoryManage {
9+
id: string;
10+
entryId: string;
11+
title: string;
12+
slug: string;
13+
wbyAco_location: {
14+
folderId: string;
15+
};
16+
}
17+
18+
export const createCategoryManageMethods = (
19+
manager: ReturnType<typeof useCategoryManageHandler>
20+
) => {
21+
const getCategory = async (revision: string): Promise<CategoryManage> => {
22+
return await manager
23+
.getCategory({
24+
revision
25+
})
26+
.then(result => {
27+
const [data] = result;
28+
return data.data.getCategory.data;
29+
});
30+
};
31+
32+
const createCategory = async (data: CategoryParams): Promise<CategoryManage> => {
33+
return await manager
34+
.createCategory({
35+
data
36+
})
37+
.then(result => {
38+
const [data] = result;
39+
return data.data.createCategory.data;
40+
});
41+
};
42+
43+
const createCategoryFrom = async (category: CategoryManage): Promise<CategoryManage> => {
44+
return await manager
45+
.createCategoryFrom({
46+
revision: category.id
47+
})
48+
.then(result => {
49+
const [data] = result;
50+
return data.data.createCategoryFrom.data;
51+
});
52+
};
53+
54+
const publishCategory = async (revision: string): Promise<CategoryManage> => {
55+
return await manager
56+
.publishCategory({
57+
revision
58+
})
59+
.then(result => {
60+
const [data] = result;
61+
return data.data.publishCategory.data;
62+
});
63+
};
64+
65+
return {
66+
publishCategory,
67+
getCategory,
68+
createCategory,
69+
createCategoryFrom
70+
};
71+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { useCategoryPreviewHandler } from "~tests/testHelpers/useCategoryPreviewHandler";
2+
3+
export interface CategoryPreview {
4+
id: string;
5+
entryId: string;
6+
title: string;
7+
slug: string;
8+
}
9+
10+
export const createCategoryPreviewMethods = (
11+
reader: ReturnType<typeof useCategoryPreviewHandler>
12+
) => {
13+
const getCategoryById = async (id: string): Promise<CategoryPreview> => {
14+
return await reader.getCategoryById(id).then(result => {
15+
const [data] = result;
16+
return data.data.getCategory.data;
17+
});
18+
};
19+
20+
return {
21+
listCategories: reader.listCategories,
22+
getCategoryById
23+
};
24+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { useCategoryReadHandler } from "~tests/testHelpers/useCategoryReadHandler";
2+
3+
export interface CategoryRead {
4+
id: string;
5+
entryId: string;
6+
title: string;
7+
slug: string;
8+
}
9+
10+
export const createCategoryReadMethods = (reader: ReturnType<typeof useCategoryReadHandler>) => {
11+
const getCategoryById = async (id: string): Promise<CategoryRead> => {
12+
return await reader.getCategoryById(id).then(result => {
13+
const [data] = result;
14+
return data.data.getCategory.data;
15+
});
16+
};
17+
18+
return {
19+
listCategories: reader.listCategories,
20+
getCategoryById
21+
};
22+
};

packages/api-headless-cms/__tests__/contentAPI/richTextField.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ describe("richTextField", () => {
246246

247247
const category = await createCategory();
248248

249-
const { createProduct, updateProduct } = useProductManageHandler({
249+
const { createProduct, updateProduct, getProduct } = useProductManageHandler({
250250
...manageOpts
251251
});
252252

@@ -322,6 +322,24 @@ describe("richTextField", () => {
322322
}
323323
}
324324
});
325+
326+
const product = createProductResponse.data.createProduct.data;
327+
328+
const [getAfterCreateResult] = await getProduct({
329+
revision: product.id
330+
});
331+
332+
expect(getAfterCreateResult).toMatchObject({
333+
data: {
334+
getProduct: {
335+
data: {
336+
id: product.id,
337+
...productData
338+
},
339+
error: null
340+
}
341+
}
342+
});
325343
/**
326344
* We now update the rich text field with some value.
327345
*/
@@ -347,5 +365,22 @@ describe("richTextField", () => {
347365
}
348366
}
349367
});
368+
369+
const [getAfterUpdateResult] = await getProduct({
370+
revision: product.id
371+
});
372+
373+
expect(getAfterUpdateResult).toMatchObject({
374+
data: {
375+
getProduct: {
376+
data: {
377+
id: product.id,
378+
...productData,
379+
richText: richTextMock
380+
},
381+
error: null
382+
}
383+
}
384+
});
350385
});
351386
});

packages/api-headless-cms/__tests__/contentAPI/snapshots/category.read.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ export default /* GraphQL */ `
292292
getCategoryApiNameWhichIsABitDifferentThanModelId(
293293
where: CategoryApiNameWhichIsABitDifferentThanModelIdGetWhereInput!
294294
): CategoryApiNameWhichIsABitDifferentThanModelIdResponse
295+
getCategoryApiNameWhichIsABitDifferentThanModelIdById(
296+
id: ID!
297+
): CategoryApiNameWhichIsABitDifferentThanModelIdResponse
295298
296299
listCategoriesApiModel(
297300
where: CategoryApiNameWhichIsABitDifferentThanModelIdListWhereInput

packages/api-headless-cms/__tests__/contentAPI/snapshots/page.read.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ export default /* GraphQL */ `
498498
499499
extend type Query {
500500
getPageModelApiName(where: PageModelApiNameGetWhereInput!): PageModelApiNameResponse
501+
getPageModelApiNameById(id: ID!): PageModelApiNameResponse
501502
502503
listPagesModelApiName(
503504
where: PageModelApiNameListWhereInput

packages/api-headless-cms/__tests__/contentAPI/snapshots/product.read.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ export default /* GraphQL */ `
457457
458458
extend type Query {
459459
getProductApiSingular(where: ProductApiSingularGetWhereInput!): ProductApiSingularResponse
460+
getProductApiSingularById(id: ID!): ProductApiSingularResponse
460461
461462
listProductPluralApiName(
462463
where: ProductApiSingularListWhereInput

packages/api-headless-cms/__tests__/contentAPI/snapshots/review.read.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ export default /* GraphQL */ `
300300
301301
extend type Query {
302302
getReviewApiModel(where: ReviewApiModelGetWhereInput!): ReviewApiModelResponse
303+
getReviewApiModelById(id: ID!): ReviewApiModelResponse
303304
304305
listReviewsApiModel(
305306
where: ReviewApiModelListWhereInput

0 commit comments

Comments
 (0)