@platecms/delta-client 0.13.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/package.json +5 -3
  2. package/src/__generated__/gql.ts +93 -3
  3. package/src/__generated__/graphql.ts +679 -82
  4. package/src/api/fetchContentExperiences.spec.ts +82 -0
  5. package/src/api/fetchContentExperiences.ts +42 -0
  6. package/src/api/fetchContentItems.spec.ts +62 -0
  7. package/src/api/fetchContentItems.ts +42 -0
  8. package/src/api/fetchPathParts.spec.ts +62 -0
  9. package/src/api/fetchPathParts.ts +42 -0
  10. package/src/api/fetchTags.spec.ts +61 -0
  11. package/src/api/fetchTags.ts +38 -0
  12. package/src/api/index.ts +4 -1
  13. package/src/api/types.ts +35 -0
  14. package/src/apollo/index.ts +1 -1
  15. package/src/app/utils/paginated-response.type.ts +19 -0
  16. package/src/factories/BaseFactory.ts +19 -0
  17. package/src/factories/ChannelFactory.ts +19 -0
  18. package/src/factories/ContentExperienceFactory.ts +54 -0
  19. package/src/factories/PathPartFactory.ts +26 -0
  20. package/src/factories/TagFactory.ts +30 -0
  21. package/src/graphql/content-experiences/content-experiences.query.gql +82 -0
  22. package/src/graphql/content-items/content-items.query.gql +47 -0
  23. package/src/graphql/fragments/asset.fragment.gql +10 -0
  24. package/src/graphql/fragments/asset.fragments.gql +10 -0
  25. package/src/graphql/fragments/building-block-field-fullfillment.fragments.gql +45 -0
  26. package/src/graphql/fragments/building-block-field.fragments.gql +8 -0
  27. package/src/graphql/fragments/building-block.fragments.gql +11 -0
  28. package/src/graphql/fragments/content-experience.fragments.gql +8 -0
  29. package/src/graphql/fragments/content-field.fragments.gql +7 -0
  30. package/src/graphql/fragments/content-item.fragments.gql +11 -0
  31. package/src/graphql/fragments/content-type.fragments.gql +11 -0
  32. package/src/graphql/fragments/content-values.fragments.gql +33 -0
  33. package/src/graphql/fragments/experience-component.fragments.gql +13 -0
  34. package/src/graphql/fragments/grid-placement.fragments.gql +7 -0
  35. package/src/graphql/fragments/path-part.fragments.gql +8 -0
  36. package/src/graphql/fragments/tag.fragment.gql +17 -0
  37. package/src/graphql/path-parts/path-parts.query.gql +52 -0
  38. package/src/graphql/tags/tag.query.gql +15 -3
  39. package/src/index.ts +1 -1
  40. package/src/slate/index.ts +21 -3
  41. package/src/utils/index.ts +8 -0
@@ -0,0 +1,82 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+ import { afterEach, describe, expect, it, vi } from "vitest";
3
+ import axios, { AxiosResponse } from "axios";
4
+
5
+ import { fetchContentExperiences } from "./fetchContentExperiences";
6
+ import { PaginatedResponse } from "../app/utils/paginated-response.type";
7
+ import { ContentExperiencesQuery } from "../__generated__/graphql";
8
+ import { API_VERSION, apiBaseUrl } from "../utils";
9
+
10
+ afterEach(() => {
11
+ vi.restoreAllMocks();
12
+ });
13
+
14
+ describe("fetchContentExperiences", () => {
15
+ it("calls the list endpoint with params and returns the response", async () => {
16
+ const mockResponse = {
17
+ data: {
18
+ links: { first: null, previous: null, self: "", next: null, last: null },
19
+ meta: { page: { total: 1, maxSize: 10 } },
20
+ data: [],
21
+ },
22
+ status: 200,
23
+ headers: {},
24
+ config: {},
25
+ statusText: "OK",
26
+ } as unknown as AxiosResponse<PaginatedResponse<ContentExperiencesQuery>>;
27
+
28
+ const get = vi.fn().mockResolvedValue(mockResponse);
29
+ const createSpy = vi.spyOn(axios, "create").mockReturnValue({ get } as unknown as ReturnType<typeof axios.create>);
30
+
31
+ const result = await fetchContentExperiences({
32
+ mode: "dev",
33
+ token: "token-123",
34
+ first: 10,
35
+ title: "home",
36
+ tags: "tag:foo",
37
+ });
38
+
39
+ const expectedBaseUrl = new URL(`/content-delivery-api/${API_VERSION}/content-experiences`, apiBaseUrl("dev"));
40
+ expect(createSpy).toHaveBeenCalledWith({
41
+ baseURL: expectedBaseUrl.toString(),
42
+ headers: { Authorization: "Bearer token-123" },
43
+ });
44
+
45
+ expect(get).toHaveBeenCalledWith("", {
46
+ params: expect.objectContaining({ first: 10, title: "home", tags: "tag:foo" }),
47
+ });
48
+
49
+ expect(result).toBe(mockResponse);
50
+ });
51
+
52
+ it("calls the path endpoint when options.path is provided", async () => {
53
+ const mockResponse = {
54
+ data: {},
55
+ } as unknown as AxiosResponse<PaginatedResponse<ContentExperiencesQuery>>;
56
+ const get = vi.fn().mockResolvedValue(mockResponse);
57
+ const createSpy = vi.spyOn(axios, "create").mockReturnValue({ get } as unknown as ReturnType<typeof axios.create>);
58
+
59
+ await fetchContentExperiences({
60
+ mode: "acc",
61
+ version: "v0",
62
+ token: "t-acc",
63
+ path: "/home",
64
+ });
65
+
66
+ expect(createSpy).toHaveBeenCalledWith({
67
+ baseURL: "https://api.delta-acc.getplate.rocks/content-delivery-api/v0/content-experiences/path/home",
68
+ headers: { Authorization: "Bearer t-acc" },
69
+ });
70
+ });
71
+
72
+ it("returns an Error when the request fails", async () => {
73
+ const error = new Error("boom");
74
+ const get = vi.fn().mockRejectedValue(error);
75
+ vi.spyOn(axios, "create").mockReturnValue({ get } as unknown as ReturnType<typeof axios.create>);
76
+
77
+ const result = await fetchContentExperiences({ mode: "dev", token: "t" });
78
+ expect(result).toBeInstanceOf(Error);
79
+ expect((result as Error).message).toBe("boom");
80
+ });
81
+ });
82
+ /* eslint-enable @typescript-eslint/naming-convention */
@@ -0,0 +1,42 @@
1
+ import axios, { AxiosInstance, AxiosResponse } from "axios";
2
+ import { ContentExperiencesQuery } from "../__generated__/graphql";
3
+ import { PaginatedResponse } from "../app/utils/paginated-response.type";
4
+ import { API_VERSION, apiBaseUrl } from "../utils";
5
+ import { ContentExperiencesApiOptions } from "./types";
6
+
7
+ function getClient(token: string, endpoint: string): AxiosInstance {
8
+ return axios.create({
9
+ // eslint-disable-next-line @typescript-eslint/naming-convention
10
+ baseURL: endpoint,
11
+ headers: {
12
+ // eslint-disable-next-line @typescript-eslint/naming-convention
13
+ Authorization: `Bearer ${token}`,
14
+ },
15
+ });
16
+ }
17
+
18
+ export async function fetchContentExperiences(
19
+ options: ContentExperiencesApiOptions,
20
+ ): Promise<AxiosResponse<PaginatedResponse<ContentExperiencesQuery>> | Error> {
21
+ const endpointUrl = new URL(
22
+ `/content-delivery-api/${options.version ?? API_VERSION}/content-experiences${options.path != null ? `/path${options.path}` : ""}`,
23
+ apiBaseUrl(options.mode),
24
+ );
25
+ const client = getClient(options.token, endpointUrl.toString());
26
+ return client
27
+ .get("", {
28
+ params: {
29
+ first: options.first,
30
+ last: options.last,
31
+ before: options.before,
32
+ after: options.after,
33
+ title: options.title,
34
+ tags: options.tags,
35
+ },
36
+ })
37
+ .then((res) => res as AxiosResponse<PaginatedResponse<ContentExperiencesQuery>>)
38
+ .catch((err: unknown) => {
39
+ const error = err as Error;
40
+ return error;
41
+ });
42
+ }
@@ -0,0 +1,62 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+ import { afterEach, describe, expect, it, vi } from "vitest";
3
+ import axios, { AxiosResponse } from "axios";
4
+
5
+ import { fetchContentItems } from "./fetchContentItems";
6
+ import { PaginatedResponse } from "../app/utils/paginated-response.type";
7
+ import { ContentItemsQuery } from "../__generated__/graphql";
8
+ import { API_VERSION, apiBaseUrl } from "../utils";
9
+
10
+ afterEach(() => {
11
+ vi.restoreAllMocks();
12
+ });
13
+
14
+ describe("fetchContentItems", () => {
15
+ it("calls the list endpoint with params and returns the response", async () => {
16
+ const mockResponse = {
17
+ data: {
18
+ links: { first: null, previous: null, self: "", next: null, last: null },
19
+ meta: { page: { total: 1, maxSize: 10 } },
20
+ data: [],
21
+ },
22
+ status: 200,
23
+ headers: {},
24
+ config: {},
25
+ statusText: "OK",
26
+ } as unknown as AxiosResponse<PaginatedResponse<ContentItemsQuery>>;
27
+
28
+ const get = vi.fn().mockResolvedValue(mockResponse);
29
+ const createSpy = vi.spyOn(axios, "create").mockReturnValue({ get } as unknown as ReturnType<typeof axios.create>);
30
+
31
+ const result = await fetchContentItems({
32
+ mode: "dev",
33
+ token: "token-123",
34
+ first: 10,
35
+ tags: "tag:foo",
36
+ contentTypePrn: "contentTypePrn-123",
37
+ });
38
+
39
+ const expectedBaseUrl = new URL(`/content-delivery-api/${API_VERSION}/content-items`, apiBaseUrl("dev"));
40
+ expect(createSpy).toHaveBeenCalledWith({
41
+ baseURL: expectedBaseUrl.toString(),
42
+ headers: { Authorization: "Bearer token-123" },
43
+ });
44
+
45
+ expect(get).toHaveBeenCalledWith("", {
46
+ params: expect.objectContaining({ first: 10, tags: "tag:foo", contentTypePrn: "contentTypePrn-123" }),
47
+ });
48
+
49
+ expect(result).toBe(mockResponse);
50
+ });
51
+
52
+ it("returns an Error when the request fails", async () => {
53
+ const error = new Error("boom");
54
+ const get = vi.fn().mockRejectedValue(error);
55
+ vi.spyOn(axios, "create").mockReturnValue({ get } as unknown as ReturnType<typeof axios.create>);
56
+
57
+ const result = await fetchContentItems({ mode: "dev", token: "t" });
58
+ expect(result).toBeInstanceOf(Error);
59
+ expect((result as Error).message).toBe("boom");
60
+ });
61
+ });
62
+ /* eslint-enable @typescript-eslint/naming-convention */
@@ -0,0 +1,42 @@
1
+ import axios, { AxiosInstance, AxiosResponse } from "axios";
2
+ import { ContentItemsQuery } from "../__generated__/graphql";
3
+ import { PaginatedResponse } from "../app/utils/paginated-response.type";
4
+ import { API_VERSION, apiBaseUrl } from "../utils";
5
+ import { ContentItemsApiOptions } from "./types";
6
+
7
+ function getClient(token: string, endpoint: string): AxiosInstance {
8
+ return axios.create({
9
+ // eslint-disable-next-line @typescript-eslint/naming-convention
10
+ baseURL: endpoint,
11
+ headers: {
12
+ // eslint-disable-next-line @typescript-eslint/naming-convention
13
+ Authorization: `Bearer ${token}`,
14
+ },
15
+ });
16
+ }
17
+
18
+ export async function fetchContentItems(
19
+ options: ContentItemsApiOptions,
20
+ ): Promise<AxiosResponse<PaginatedResponse<ContentItemsQuery>> | Error> {
21
+ const endpointUrl = new URL(
22
+ `/content-delivery-api/${options.version ?? API_VERSION}/content-items`,
23
+ apiBaseUrl(options.mode),
24
+ );
25
+ const client = getClient(options.token, endpointUrl.toString());
26
+ return client
27
+ .get("", {
28
+ params: {
29
+ first: options.first,
30
+ last: options.last,
31
+ before: options.before,
32
+ after: options.after,
33
+ tags: options.tags,
34
+ contentTypePrn: options.contentTypePrn,
35
+ },
36
+ })
37
+ .then((res) => res as AxiosResponse<PaginatedResponse<ContentItemsQuery>>)
38
+ .catch((err: unknown) => {
39
+ const error = err as Error;
40
+ return error;
41
+ });
42
+ }
@@ -0,0 +1,62 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+ import { afterEach, describe, expect, it, vi } from "vitest";
3
+ import axios, { AxiosResponse } from "axios";
4
+
5
+ import { fetchPathParts } from "./fetchPathParts";
6
+ import { PaginatedResponse } from "../app/utils/paginated-response.type";
7
+ import { PathPartsQuery } from "../__generated__/graphql";
8
+ import { API_VERSION, apiBaseUrl } from "../utils";
9
+
10
+ afterEach(() => {
11
+ vi.restoreAllMocks();
12
+ });
13
+
14
+ describe("fetchPathParts", () => {
15
+ it("calls the list endpoint with params and returns the response", async () => {
16
+ const mockResponse = {
17
+ data: {
18
+ links: { first: null, previous: null, self: "", next: null, last: null },
19
+ meta: { page: { total: 1, maxSize: 10 } },
20
+ data: [],
21
+ },
22
+ status: 200,
23
+ headers: {},
24
+ config: {},
25
+ statusText: "OK",
26
+ } as unknown as AxiosResponse<PaginatedResponse<PathPartsQuery>>;
27
+
28
+ const get = vi.fn().mockResolvedValue(mockResponse);
29
+ const createSpy = vi.spyOn(axios, "create").mockReturnValue({ get } as unknown as ReturnType<typeof axios.create>);
30
+
31
+ const result = await fetchPathParts({
32
+ mode: "dev",
33
+ token: "token-123",
34
+ first: 10,
35
+ parent: "parent-123",
36
+ hasContentExperience: true,
37
+ });
38
+
39
+ const expectedBaseUrl = new URL(`/content-delivery-api/${API_VERSION}/path-parts`, apiBaseUrl("dev"));
40
+ expect(createSpy).toHaveBeenCalledWith({
41
+ baseURL: expectedBaseUrl.toString(),
42
+ headers: { Authorization: "Bearer token-123" },
43
+ });
44
+
45
+ expect(get).toHaveBeenCalledWith("", {
46
+ params: expect.objectContaining({ first: 10, parent: "parent-123", hasContentExperience: true }),
47
+ });
48
+
49
+ expect(result).toBe(mockResponse);
50
+ });
51
+
52
+ it("returns an Error when the request fails", async () => {
53
+ const error = new Error("boom");
54
+ const get = vi.fn().mockRejectedValue(error);
55
+ vi.spyOn(axios, "create").mockReturnValue({ get } as unknown as ReturnType<typeof axios.create>);
56
+
57
+ const result = await fetchPathParts({ mode: "dev", token: "t" });
58
+ expect(result).toBeInstanceOf(Error);
59
+ expect((result as Error).message).toBe("boom");
60
+ });
61
+ });
62
+ /* eslint-enable @typescript-eslint/naming-convention */
@@ -0,0 +1,42 @@
1
+ import axios, { AxiosInstance, AxiosResponse } from "axios";
2
+ import { PaginatedResponse } from "../app/utils/paginated-response.type";
3
+ import { PathPartsQuery } from "../schema";
4
+ import { API_VERSION, apiBaseUrl } from "../utils";
5
+ import { PathPartsApiOptions } from "./types";
6
+
7
+ function getClient(token: string, endpoint: string): AxiosInstance {
8
+ return axios.create({
9
+ // eslint-disable-next-line @typescript-eslint/naming-convention
10
+ baseURL: endpoint,
11
+ headers: {
12
+ // eslint-disable-next-line @typescript-eslint/naming-convention
13
+ Authorization: `Bearer ${token}`,
14
+ },
15
+ });
16
+ }
17
+
18
+ export async function fetchPathParts(
19
+ options: PathPartsApiOptions,
20
+ ): Promise<AxiosResponse<PaginatedResponse<PathPartsQuery>> | Error> {
21
+ const endpointUrl = new URL(
22
+ `/content-delivery-api/${options.version ?? API_VERSION}/path-parts`,
23
+ apiBaseUrl(options.mode),
24
+ );
25
+ const client = getClient(options.token, endpointUrl.toString());
26
+ return client
27
+ .get("", {
28
+ params: {
29
+ first: options.first,
30
+ after: options.after,
31
+ last: options.last,
32
+ before: options.before,
33
+ hasContentExperience: options.hasContentExperience,
34
+ parent: options.parent,
35
+ },
36
+ })
37
+ .then((res) => res as AxiosResponse<PaginatedResponse<PathPartsQuery>>)
38
+ .catch((err: unknown) => {
39
+ const error = err as Error;
40
+ return error;
41
+ });
42
+ }
@@ -0,0 +1,61 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+ import { afterEach, describe, expect, it, vi } from "vitest";
3
+ import axios, { AxiosResponse } from "axios";
4
+
5
+ import { fetchTags } from "./fetchTags";
6
+ import { PaginatedResponse } from "../app/utils/paginated-response.type";
7
+ import { TagsQuery } from "../__generated__/graphql";
8
+ import { API_VERSION, apiBaseUrl } from "../utils";
9
+
10
+ afterEach(() => {
11
+ vi.restoreAllMocks();
12
+ });
13
+
14
+ describe("fetchTags", () => {
15
+ it("calls the list endpoint with params and returns the response", async () => {
16
+ const mockResponse = {
17
+ data: {
18
+ links: { first: null, previous: null, self: "", next: null, last: null },
19
+ meta: { page: { total: 1, maxSize: 10 } },
20
+ data: [],
21
+ },
22
+ status: 200,
23
+ headers: {},
24
+ config: {},
25
+ statusText: "OK",
26
+ } as unknown as AxiosResponse<PaginatedResponse<TagsQuery>>;
27
+
28
+ const get = vi.fn().mockResolvedValue(mockResponse);
29
+ const createSpy = vi.spyOn(axios, "create").mockReturnValue({ get } as unknown as ReturnType<typeof axios.create>);
30
+
31
+ const result = await fetchTags({
32
+ mode: "dev",
33
+ token: "token-123",
34
+ first: 10,
35
+ name: "name-123",
36
+ });
37
+
38
+ const expectedBaseUrl = new URL(`/content-delivery-api/${API_VERSION}/tags`, apiBaseUrl("dev"));
39
+ expect(createSpy).toHaveBeenCalledWith({
40
+ baseURL: expectedBaseUrl.toString(),
41
+ headers: { Authorization: "Bearer token-123" },
42
+ });
43
+
44
+ expect(get).toHaveBeenCalledWith("", {
45
+ params: expect.objectContaining({ first: 10, name: "name-123" }),
46
+ });
47
+
48
+ expect(result).toBe(mockResponse);
49
+ });
50
+
51
+ it("returns an Error when the request fails", async () => {
52
+ const error = new Error("boom");
53
+ const get = vi.fn().mockRejectedValue(error);
54
+ vi.spyOn(axios, "create").mockReturnValue({ get } as unknown as ReturnType<typeof axios.create>);
55
+
56
+ const result = await fetchTags({ mode: "dev", token: "t" });
57
+ expect(result).toBeInstanceOf(Error);
58
+ expect((result as Error).message).toBe("boom");
59
+ });
60
+ });
61
+ /* eslint-enable @typescript-eslint/naming-convention */
@@ -0,0 +1,38 @@
1
+ import axios, { AxiosInstance, AxiosResponse } from "axios";
2
+ import { PaginatedResponse } from "../app/utils/paginated-response.type";
3
+ import { TagsQuery } from "../__generated__/graphql";
4
+ import { API_VERSION, apiBaseUrl } from "../utils";
5
+ import { TagsApiOptions } from "./types";
6
+
7
+ function getClient(token: string, endpoint: string): AxiosInstance {
8
+ return axios.create({
9
+ // eslint-disable-next-line @typescript-eslint/naming-convention
10
+ baseURL: endpoint,
11
+ headers: {
12
+ // eslint-disable-next-line @typescript-eslint/naming-convention
13
+ Authorization: `Bearer ${token}`,
14
+ },
15
+ });
16
+ }
17
+
18
+ export async function fetchTags(options: TagsApiOptions): Promise<AxiosResponse<PaginatedResponse<TagsQuery>> | Error> {
19
+ const endpointUrl = new URL(`/content-delivery-api/${options.version ?? API_VERSION}/tags`, apiBaseUrl(options.mode));
20
+ const client = getClient(options.token, endpointUrl.toString());
21
+
22
+ return client
23
+ .get("", {
24
+ params: {
25
+ first: options.first,
26
+ after: options.after,
27
+ last: options.last,
28
+ before: options.before,
29
+ name: options.name,
30
+ parent: options.parent,
31
+ },
32
+ })
33
+ .then((res) => res)
34
+ .catch((err: unknown) => {
35
+ const error = err;
36
+ return error as Error;
37
+ });
38
+ }
package/src/api/index.ts CHANGED
@@ -1 +1,4 @@
1
- export default {};
1
+ export * from "./fetchContentExperiences";
2
+ export * from "./fetchContentItems";
3
+ export * from "./fetchPathParts";
4
+ export * from "./fetchTags";
@@ -0,0 +1,35 @@
1
+ export type Mode = "acc" | "dev" | "prod";
2
+
3
+ export interface DefaultApiOptions {
4
+ mode: Mode;
5
+ version?: string;
6
+ token: string;
7
+ }
8
+
9
+ export type PaginatedApiOptions = DefaultApiOptions & {
10
+ first?: number;
11
+ last?: number;
12
+ before?: string;
13
+ after?: string;
14
+ };
15
+
16
+ export type ContentItemsApiOptions = PaginatedApiOptions & {
17
+ tags?: string | null;
18
+ contentTypePrn?: string;
19
+ };
20
+
21
+ export type ContentExperiencesApiOptions = PaginatedApiOptions & {
22
+ title?: string;
23
+ tags?: string | null;
24
+ path?: string;
25
+ };
26
+
27
+ export type TagsApiOptions = PaginatedApiOptions & {
28
+ name?: string;
29
+ parent?: string;
30
+ };
31
+
32
+ export type PathPartsApiOptions = PaginatedApiOptions & {
33
+ parent?: string;
34
+ hasContentExperience?: boolean;
35
+ };
@@ -14,7 +14,7 @@ import { defu } from "defu";
14
14
  const placeholderOrganizationPrn = new PRN(
15
15
  "delta",
16
16
  "placeholder",
17
- ServiceAbbreviation.ORGANIZATIONS_CENTER,
17
+ ServiceAbbreviation.PLATFORM_SERVICE,
18
18
  "organization",
19
19
  "0",
20
20
  );
@@ -0,0 +1,19 @@
1
+ export interface PaginatedResponse<T> {
2
+ links: {
3
+ first?: string | null;
4
+ previous?: string | null;
5
+ self: string;
6
+ next?: string | null;
7
+ last?: string | null;
8
+ };
9
+ meta: {
10
+ page: {
11
+ total: number;
12
+ maxSize: number;
13
+ };
14
+ };
15
+ data: {
16
+ node: T;
17
+ cursor: string;
18
+ }[];
19
+ }
@@ -0,0 +1,19 @@
1
+ import { v4 as uuidv4 } from "uuid";
2
+ import { faker } from "@faker-js/faker";
3
+ import { PRN, ServiceAbbreviation } from "@platecms/delta-plate-resource-notation";
4
+
5
+ export abstract class BaseFactory<T> {
6
+ protected readonly prn: string;
7
+ protected readonly uuid: string;
8
+ protected readonly createdAt: string;
9
+ protected readonly updatedAt: string;
10
+
11
+ public constructor() {
12
+ this.uuid = uuidv4();
13
+ this.prn = new PRN("test", uuidv4(), ServiceAbbreviation.CONTENT_MANAGEMENT_SERVICE, "asset", this.uuid).toString();
14
+ this.createdAt = faker.date.past().toISOString();
15
+ this.updatedAt = faker.date.recent().toISOString();
16
+ }
17
+
18
+ public abstract create(input?: Partial<T>): T;
19
+ }
@@ -0,0 +1,19 @@
1
+ import { BaseFactory } from "./BaseFactory";
2
+ import { Channel } from "../__generated__/graphql";
3
+ import { faker } from "@faker-js/faker";
4
+
5
+ export class ChannelFactory extends BaseFactory<Channel> {
6
+ public create(input: Partial<Channel> | undefined): Channel {
7
+ return {
8
+ prn: this.prn,
9
+ _id: this.prn,
10
+ name: faker.lorem.word(),
11
+ domain: faker.internet.domainName(),
12
+ slug: faker.internet.domainWord(),
13
+ createdAt: this.createdAt,
14
+ updatedAt: this.updatedAt,
15
+ __typename: "Channel",
16
+ ...input,
17
+ } as unknown as Channel;
18
+ }
19
+ }
@@ -0,0 +1,54 @@
1
+ import { BaseFactory } from "./BaseFactory";
2
+ import { ContentExperience, Theme } from "../__generated__/graphql";
3
+ import { faker } from "@faker-js/faker";
4
+ import { PathPartFactory } from "./PathPartFactory";
5
+ import { ChannelFactory } from "./ChannelFactory";
6
+
7
+ export class ContentExperienceFactory extends BaseFactory<ContentExperience> {
8
+ public create(input: Partial<ContentExperience> | undefined): ContentExperience {
9
+ return {
10
+ prn: this.prn,
11
+ _id: this.prn,
12
+ title: faker.word.words(2),
13
+ preview: null,
14
+ experienceComponent: {
15
+ _id: this.prn,
16
+ prn: this.prn,
17
+ grid: null,
18
+ name: faker.word.words(2),
19
+ isDraft: false,
20
+ buildingBlock: {
21
+ buildingBlockFields: [],
22
+ },
23
+ stage: "development",
24
+ preview: null,
25
+ isGlobal: false,
26
+ buildingBlockFieldFulfillments: [],
27
+ __typename: "ExperienceComponent",
28
+ createdAt: this.createdAt,
29
+ updatedAt: this.updatedAt,
30
+ blueprintedBy: null,
31
+ },
32
+ slug: faker.lorem.slug(),
33
+ createdAt: this.createdAt,
34
+ updatedAt: this.updatedAt,
35
+ __typename: "ContentExperience",
36
+ pathPart: new PathPartFactory().create({
37
+ channel: new ChannelFactory().create({
38
+ theme: {
39
+ _id: this.prn,
40
+ prn: this.prn,
41
+ repositoryUrl: "https://github.com/plate-dev/plate",
42
+ name: faker.word.words(2),
43
+ createdAt: this.createdAt,
44
+ updatedAt: this.updatedAt,
45
+ __typename: "Theme",
46
+ buildingBlocks: [],
47
+ channels: [],
48
+ } as unknown as Theme,
49
+ }),
50
+ }),
51
+ ...input,
52
+ } as unknown as ContentExperience;
53
+ }
54
+ }
@@ -0,0 +1,26 @@
1
+ import { BaseFactory } from "./BaseFactory";
2
+ import { faker } from "@faker-js/faker";
3
+ import { PathPart } from "../__generated__/graphql";
4
+
5
+ export class PathPartFactory extends BaseFactory<PathPart> {
6
+ public create(input: Partial<PathPart> | undefined = {}): PathPart {
7
+ return {
8
+ prn: this.prn,
9
+ _id: this.prn,
10
+ path: faker.lorem.word(),
11
+ slug: faker.lorem.word(),
12
+ parent: null,
13
+ contentExperience: null,
14
+ hasContentExperience: false,
15
+ amountOfChildren: 0,
16
+ amountOfChildrenWithContentExperiences: 0,
17
+ amountOfDescendants: 0,
18
+ amountOfDescendantsWithContentExperiences: 0,
19
+ children: [],
20
+ createdAt: this.createdAt,
21
+ updatedAt: this.updatedAt,
22
+ __typename: "PathPart",
23
+ ...input,
24
+ } as unknown as PathPart;
25
+ }
26
+ }
@@ -0,0 +1,30 @@
1
+ import { BaseFactory } from "./BaseFactory";
2
+ import { Stage, Tag, TagVisibility } from "../../src/__generated__/graphql";
3
+ import { faker } from "@faker-js/faker";
4
+
5
+ export class TagFactory extends BaseFactory<Tag> {
6
+ public create(input?: Partial<Tag>): Tag & { amountOfChildren: number; amountOfUses: number } {
7
+ return {
8
+ prn: this.prn,
9
+ _id: this.prn,
10
+ name: faker.lorem.word(),
11
+ path: faker.lorem.word(),
12
+ nestingLevel: faker.number.int({ min: 0, max: 5 }),
13
+ forceVisibilityOnDescendants: faker.datatype.boolean(),
14
+ hasForcedVisibility: faker.datatype.boolean(),
15
+ visibility: faker.datatype.boolean() ? TagVisibility.Public : TagVisibility.Private,
16
+ stage: faker.datatype.boolean() ? Stage.Production : Stage.Development,
17
+ color: faker.color.rgb(),
18
+ parent: null,
19
+ amountOfContentExperiences: faker.number.int({ min: 0, max: 10 }),
20
+ amountOfContentItems: faker.number.int({ min: 0, max: 10 }),
21
+ amountOfChildren: faker.number.int({ min: 0, max: 10 }),
22
+ amountOfUses: faker.number.int({ min: 0, max: 100 }),
23
+ createdAt: this.createdAt,
24
+ updatedAt: this.updatedAt,
25
+ children: [],
26
+ __typename: "Tag",
27
+ ...input,
28
+ } as unknown as Tag & { amountOfChildren: number; amountOfUses: number };
29
+ }
30
+ }