Skip to content

Commit

Permalink
feat(api-serverless-cms): base tests (#4332)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric authored Oct 15, 2024
1 parent 2035c6f commit a11bb5b
Show file tree
Hide file tree
Showing 31 changed files with 1,362 additions and 24 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/pullRequests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ jobs:
--storage=ddb","storage":"ddb","id":"api-page-builder-import-export_ddb"},{"cmd":"packages/api-prerendering-service
--storage=ddb","storage":"ddb","id":"api-prerendering-service_ddb"},{"cmd":"packages/api-security
--storage=ddb","storage":"ddb","id":"api-security_ddb"},{"cmd":"packages/api-security-cognito
--storage=ddb","storage":"ddb","id":"api-security-cognito_ddb"},{"cmd":"packages/api-tenancy
--storage=ddb","storage":"ddb","id":"api-security-cognito_ddb"},{"cmd":"packages/api-serverless-cms
--storage=ddb","storage":"ddb","id":"api-serverless-cms_ddb"},{"cmd":"packages/api-tenancy
--storage=ddb","storage":"ddb","id":"api-tenancy_ddb"},{"cmd":"packages/api-tenant-manager
--storage=ddb","storage":"ddb","id":"api-tenant-manager_ddb"},{"cmd":"packages/tasks
--storage=ddb","storage":"ddb","id":"tasks_ddb"}]') }}
Expand Down Expand Up @@ -301,7 +302,8 @@ jobs:
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-mailer_ddb-es_ddb"},{"cmd":"packages/api-page-builder
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-page-builder_ddb-es_ddb"},{"cmd":"packages/api-page-builder-aco
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-page-builder-aco_ddb-es_ddb"},{"cmd":"packages/api-page-builder-so-ddb-es
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-page-builder-so-ddb-es_ddb-es_ddb"},{"cmd":"packages/migrations","storage":["ddb-es","ddb-os"],"id":"migrations"},{"cmd":"packages/tasks
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-page-builder-so-ddb-es_ddb-es_ddb"},{"cmd":"packages/api-serverless-cms
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-serverless-cms_ddb-es_ddb"},{"cmd":"packages/migrations","storage":["ddb-es","ddb-os"],"id":"migrations"},{"cmd":"packages/tasks
--storage=ddb-es,ddb","storage":"ddb-es","id":"tasks_ddb-es_ddb"}]')
}}
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -374,7 +376,8 @@ jobs:
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-mailer_ddb-os_ddb"},{"cmd":"packages/api-page-builder
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-page-builder_ddb-os_ddb"},{"cmd":"packages/api-page-builder-aco
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-page-builder-aco_ddb-os_ddb"},{"cmd":"packages/api-page-builder-so-ddb-es
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-page-builder-so-ddb-es_ddb-os_ddb"},{"cmd":"packages/migrations","storage":["ddb-es","ddb-os"],"id":"migrations"},{"cmd":"packages/tasks
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-page-builder-so-ddb-es_ddb-os_ddb"},{"cmd":"packages/api-serverless-cms
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-serverless-cms_ddb-os_ddb"},{"cmd":"packages/migrations","storage":["ddb-es","ddb-os"],"id":"migrations"},{"cmd":"packages/tasks
--storage=ddb-os,ddb","storage":"ddb-os","id":"tasks_ddb-os_ddb"}]')
}}
runs-on: ${{ matrix.os }}
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/pushDev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ jobs:
--storage=ddb","storage":"ddb","id":"api-page-builder-import-export_ddb"},{"cmd":"packages/api-prerendering-service
--storage=ddb","storage":"ddb","id":"api-prerendering-service_ddb"},{"cmd":"packages/api-security
--storage=ddb","storage":"ddb","id":"api-security_ddb"},{"cmd":"packages/api-security-cognito
--storage=ddb","storage":"ddb","id":"api-security-cognito_ddb"},{"cmd":"packages/api-tenancy
--storage=ddb","storage":"ddb","id":"api-security-cognito_ddb"},{"cmd":"packages/api-serverless-cms
--storage=ddb","storage":"ddb","id":"api-serverless-cms_ddb"},{"cmd":"packages/api-tenancy
--storage=ddb","storage":"ddb","id":"api-tenancy_ddb"},{"cmd":"packages/api-tenant-manager
--storage=ddb","storage":"ddb","id":"api-tenant-manager_ddb"},{"cmd":"packages/tasks
--storage=ddb","storage":"ddb","id":"tasks_ddb"}]') }}
Expand Down Expand Up @@ -267,7 +268,8 @@ jobs:
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-mailer_ddb-es_ddb"},{"cmd":"packages/api-page-builder
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-page-builder_ddb-es_ddb"},{"cmd":"packages/api-page-builder-aco
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-page-builder-aco_ddb-es_ddb"},{"cmd":"packages/api-page-builder-so-ddb-es
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-page-builder-so-ddb-es_ddb-es_ddb"},{"cmd":"packages/migrations","storage":["ddb-es","ddb-os"],"id":"migrations"},{"cmd":"packages/tasks
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-page-builder-so-ddb-es_ddb-es_ddb"},{"cmd":"packages/api-serverless-cms
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-serverless-cms_ddb-es_ddb"},{"cmd":"packages/migrations","storage":["ddb-es","ddb-os"],"id":"migrations"},{"cmd":"packages/tasks
--storage=ddb-es,ddb","storage":"ddb-es","id":"tasks_ddb-es_ddb"}]')
}}
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -339,7 +341,8 @@ jobs:
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-mailer_ddb-os_ddb"},{"cmd":"packages/api-page-builder
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-page-builder_ddb-os_ddb"},{"cmd":"packages/api-page-builder-aco
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-page-builder-aco_ddb-os_ddb"},{"cmd":"packages/api-page-builder-so-ddb-es
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-page-builder-so-ddb-es_ddb-os_ddb"},{"cmd":"packages/migrations","storage":["ddb-es","ddb-os"],"id":"migrations"},{"cmd":"packages/tasks
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-page-builder-so-ddb-es_ddb-os_ddb"},{"cmd":"packages/api-serverless-cms
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-serverless-cms_ddb-os_ddb"},{"cmd":"packages/migrations","storage":["ddb-es","ddb-os"],"id":"migrations"},{"cmd":"packages/tasks
--storage=ddb-os,ddb","storage":"ddb-os","id":"tasks_ddb-os_ddb"}]')
}}
runs-on: ${{ matrix.os }}
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/pushNext.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ jobs:
--storage=ddb","storage":"ddb","id":"api-page-builder-import-export_ddb"},{"cmd":"packages/api-prerendering-service
--storage=ddb","storage":"ddb","id":"api-prerendering-service_ddb"},{"cmd":"packages/api-security
--storage=ddb","storage":"ddb","id":"api-security_ddb"},{"cmd":"packages/api-security-cognito
--storage=ddb","storage":"ddb","id":"api-security-cognito_ddb"},{"cmd":"packages/api-tenancy
--storage=ddb","storage":"ddb","id":"api-security-cognito_ddb"},{"cmd":"packages/api-serverless-cms
--storage=ddb","storage":"ddb","id":"api-serverless-cms_ddb"},{"cmd":"packages/api-tenancy
--storage=ddb","storage":"ddb","id":"api-tenancy_ddb"},{"cmd":"packages/api-tenant-manager
--storage=ddb","storage":"ddb","id":"api-tenant-manager_ddb"},{"cmd":"packages/tasks
--storage=ddb","storage":"ddb","id":"tasks_ddb"}]') }}
Expand Down Expand Up @@ -267,7 +268,8 @@ jobs:
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-mailer_ddb-es_ddb"},{"cmd":"packages/api-page-builder
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-page-builder_ddb-es_ddb"},{"cmd":"packages/api-page-builder-aco
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-page-builder-aco_ddb-es_ddb"},{"cmd":"packages/api-page-builder-so-ddb-es
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-page-builder-so-ddb-es_ddb-es_ddb"},{"cmd":"packages/migrations","storage":["ddb-es","ddb-os"],"id":"migrations"},{"cmd":"packages/tasks
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-page-builder-so-ddb-es_ddb-es_ddb"},{"cmd":"packages/api-serverless-cms
--storage=ddb-es,ddb","storage":"ddb-es","id":"api-serverless-cms_ddb-es_ddb"},{"cmd":"packages/migrations","storage":["ddb-es","ddb-os"],"id":"migrations"},{"cmd":"packages/tasks
--storage=ddb-es,ddb","storage":"ddb-es","id":"tasks_ddb-es_ddb"}]')
}}
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -339,7 +341,8 @@ jobs:
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-mailer_ddb-os_ddb"},{"cmd":"packages/api-page-builder
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-page-builder_ddb-os_ddb"},{"cmd":"packages/api-page-builder-aco
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-page-builder-aco_ddb-os_ddb"},{"cmd":"packages/api-page-builder-so-ddb-es
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-page-builder-so-ddb-es_ddb-os_ddb"},{"cmd":"packages/migrations","storage":["ddb-es","ddb-os"],"id":"migrations"},{"cmd":"packages/tasks
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-page-builder-so-ddb-es_ddb-os_ddb"},{"cmd":"packages/api-serverless-cms
--storage=ddb-os,ddb","storage":"ddb-os","id":"api-serverless-cms_ddb-os_ddb"},{"cmd":"packages/migrations","storage":["ddb-es","ddb-os"],"id":"migrations"},{"cmd":"packages/tasks
--storage=ddb-os,ddb","storage":"ddb-os","id":"tasks_ddb-os_ddb"}]')
}}
runs-on: ${{ matrix.os }}
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/wac/utils/listPackagesWithJestTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ const CUSTOM_HANDLERS: Record<string, () => Array<PackageWithTests>> = {
storage: "ddb-os"
}
];
},
"api-serverless-cms": () => {
return [
{ cmd: "packages/api-serverless-cms --storage=ddb-es,ddb", storage: "ddb-es" },
{ cmd: "packages/api-serverless-cms --storage=ddb-os,ddb", storage: "ddb-os" },
{ cmd: "packages/api-serverless-cms --storage=ddb", storage: "ddb" }
];
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/api-headless-cms/__tests__/testHelpers/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface CreateHandlerCoreParams {
topPlugins?: Plugin | Plugin[] | Plugin[][] | PluginCollection;
plugins?: Plugin | Plugin[] | Plugin[][] | PluginCollection;
bottomPlugins?: Plugin | Plugin[] | Plugin[][] | PluginCollection;
path?: `manage/${string}-${string}}` | `read/${string}-${string}}` | string;
path?: `manage/${string}-${string}` | `read/${string}-${string}` | string;
}
export const createHandlerCore = (params: CreateHandlerCoreParams) => {
const tenant = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import debugPlugins from "@webiny/handler-graphql/debugPlugins";
import { CmsContext } from "~/types";
import { PluginCollection } from "@webiny/plugins/types";
import { Plugin } from "@webiny/plugins/types";
import { RoutePlugin } from "@webiny/handler";
import { handleRequest } from "./handleRequest";

Expand All @@ -20,7 +20,7 @@ const cmsRoutes = new RoutePlugin<CmsContext>(({ onPost, onOptions, context }) =

cmsRoutes.name = "headless-cms.graphql.route.default";

export const graphQLHandlerFactory = ({ debug }: GraphQLHandlerFactoryParams): PluginCollection => {
export const graphQLHandlerFactory = ({ debug }: GraphQLHandlerFactoryParams): Plugin[] => {
return [
...(debug ? debugPlugins() : []),
cmsRoutes,
Expand Down
5 changes: 3 additions & 2 deletions packages/api-headless-cms/src/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Plugin } from "@webiny/plugins/types";
import { createSystemSchemaPlugin } from "./system";
import { graphQLHandlerFactory, GraphQLHandlerFactoryParams } from "./graphQLHandlerFactory";
import { createBaseSchema } from "~/graphql/schema/baseSchema";

export type CreateGraphQLParams = GraphQLHandlerFactoryParams;
export const createGraphQL = (params: CreateGraphQLParams) => {
return [createBaseSchema(), createSystemSchemaPlugin(), graphQLHandlerFactory(params)];
export const createGraphQL = (params: CreateGraphQLParams): Plugin[] => {
return [createBaseSchema(), createSystemSchemaPlugin(), ...graphQLHandlerFactory(params)];
};
5 changes: 3 additions & 2 deletions packages/api-headless-cms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ import { createExportGraphQL } from "~/export";
import { createStorageTransform } from "~/storage";
import { createLexicalHTMLRenderer } from "./htmlRenderer/createLexicalHTMLRenderer";
import { createRevisionIdScalarPlugin } from "~/graphql/scalars/RevisionIdScalarPlugin";
import { Plugin } from "@webiny/plugins/types";

export * from "./utils/isHeadlessCmsReady";
export * from "./utils/createModelField";
export * from "./graphql/schema/resolvers/manage/normalizeGraphQlInput";

export type CreateHeadlessCmsGraphQLParams = CreateGraphQLParams;
export const createHeadlessCmsGraphQL = (params: CreateHeadlessCmsGraphQLParams = {}) => {
export const createHeadlessCmsGraphQL = (params: CreateHeadlessCmsGraphQLParams = {}): Plugin[] => {
return [
createRevisionIdScalarPlugin(),
...createRevisionIdScalarPlugin(),
/**
* PathParameter plugins are used to determine the type of the cms endpoint
*/
Expand Down
63 changes: 63 additions & 0 deletions packages/api-serverless-cms/__tests__/handlers/graphQlHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { createHandler } from "@webiny/handler-aws";
import { createInvoke } from "./helpers/invoke";
import { createLambdaContext } from "./helpers/lambdaContext";
import { Plugin } from "@webiny/plugins/types";
import { createCore } from "./helpers/core";
import { PathType } from "./types";
import { getIntrospectionQuery } from "graphql";
import { createGraphQl } from "./graphql";
import { createQueryFactory } from "~tests/handlers/helpers/factory";
import { createMutationFactory } from "~tests/handlers/helpers/factory/mutation";

export interface IGraphQlHandlerParams {
path: PathType;
plugins?: Plugin[];
features?: boolean | string[];
}

export const useGraphQlHandler = (params: IGraphQlHandlerParams) => {
const core = createCore({
...params
});

const handler = createHandler({
plugins: core.plugins,
debug: process.env.DEBUG === "true"
});

const invoke = createInvoke({
handler,
path: params.path,
lambdaContext: createLambdaContext()
});

const createQuery = createQueryFactory({
invoke
});
const createMutation = createMutationFactory({
invoke
});

return {
invoke,
async introspect() {
return invoke({
body: {
query: getIntrospectionQuery()
}
});
},
handler,
cmsStorage: core.cmsStorage,
i18nStorage: core.i18nStorage,
pageBuilderStorage: core.pageBuilderStorage,
fileManagerStorage: core.fileManagerStorage,
securityStorage: core.securityStorage,
tenancyStorage: core.tenancyStorage,
login: core.login,
...createGraphQl({
createQuery,
createMutation
})
};
};
13 changes: 13 additions & 0 deletions packages/api-serverless-cms/__tests__/handlers/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createInstallGraphQL } from "./install";
import { ICreateMutationCb, ICreateQueryCb } from "~tests/handlers/helpers/factory/types";

export interface ICreateGraphQlParams {
createQuery: ICreateQueryCb;
createMutation: ICreateMutationCb;
}

export const createGraphQl = (params: ICreateGraphQlParams) => {
return {
...createInstallGraphQL(params)
};
};
Loading

0 comments on commit a11bb5b

Please sign in to comment.