Skip to content

Commit 0fd0a5e

Browse files
brunozoricadrians5j
authored andcommitted
fix(api-serverless-cms): tests with wcp licence
1 parent 49a33e7 commit 0fd0a5e

File tree

9 files changed

+41
-75
lines changed

9 files changed

+41
-75
lines changed

packages/api-elasticsearch-tasks/tsconfig.build.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
{ "path": "../api/tsconfig.build.json" },
66
{ "path": "../api-dynamodb-to-elasticsearch/tsconfig.build.json" },
77
{ "path": "../api-elasticsearch/tsconfig.build.json" },
8+
{ "path": "../api-i18n/tsconfig.build.json" },
89
{ "path": "../api-log/tsconfig.build.json" },
10+
{ "path": "../api-security/tsconfig.build.json" },
11+
{ "path": "../api-tenancy/tsconfig.build.json" },
912
{ "path": "../aws-sdk/tsconfig.build.json" },
1013
{ "path": "../db/tsconfig.build.json" },
1114
{ "path": "../db-dynamodb/tsconfig.build.json" },
1215
{ "path": "../error/tsconfig.build.json" },
16+
{ "path": "../plugins/tsconfig.build.json" },
1317
{ "path": "../tasks/tsconfig.build.json" },
1418
{ "path": "../utils/tsconfig.build.json" },
1519
{ "path": "../api-headless-cms/tsconfig.build.json" },
16-
{ "path": "../api-i18n/tsconfig.build.json" },
17-
{ "path": "../api-security/tsconfig.build.json" },
18-
{ "path": "../api-tenancy/tsconfig.build.json" },
1920
{ "path": "../api-wcp/tsconfig.build.json" },
2021
{ "path": "../handler/tsconfig.build.json" },
2122
{ "path": "../handler-aws/tsconfig.build.json" },
2223
{ "path": "../handler-db/tsconfig.build.json" },
23-
{ "path": "../handler-graphql/tsconfig.build.json" },
24-
{ "path": "../plugins/tsconfig.build.json" }
24+
{ "path": "../handler-graphql/tsconfig.build.json" }
2525
],
2626
"compilerOptions": {
2727
"rootDir": "./src",

packages/api-elasticsearch-tasks/tsconfig.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
{ "path": "../api" },
66
{ "path": "../api-dynamodb-to-elasticsearch" },
77
{ "path": "../api-elasticsearch" },
8+
{ "path": "../api-i18n" },
89
{ "path": "../api-log" },
10+
{ "path": "../api-security" },
11+
{ "path": "../api-tenancy" },
912
{ "path": "../aws-sdk" },
1013
{ "path": "../db" },
1114
{ "path": "../db-dynamodb" },
1215
{ "path": "../error" },
16+
{ "path": "../plugins" },
1317
{ "path": "../tasks" },
1418
{ "path": "../utils" },
1519
{ "path": "../api-headless-cms" },
16-
{ "path": "../api-i18n" },
17-
{ "path": "../api-security" },
18-
{ "path": "../api-tenancy" },
1920
{ "path": "../api-wcp" },
2021
{ "path": "../handler" },
2122
{ "path": "../handler-aws" },
2223
{ "path": "../handler-db" },
23-
{ "path": "../handler-graphql" },
24-
{ "path": "../plugins" }
24+
{ "path": "../handler-graphql" }
2525
],
2626
"compilerOptions": {
2727
"rootDirs": ["./src", "./__tests__"],
@@ -36,8 +36,14 @@
3636
"@webiny/api-dynamodb-to-elasticsearch": ["../api-dynamodb-to-elasticsearch/src"],
3737
"@webiny/api-elasticsearch/*": ["../api-elasticsearch/src/*"],
3838
"@webiny/api-elasticsearch": ["../api-elasticsearch/src"],
39+
"@webiny/api-i18n/*": ["../api-i18n/src/*"],
40+
"@webiny/api-i18n": ["../api-i18n/src"],
3941
"@webiny/api-log/*": ["../api-log/src/*"],
4042
"@webiny/api-log": ["../api-log/src"],
43+
"@webiny/api-security/*": ["../api-security/src/*"],
44+
"@webiny/api-security": ["../api-security/src"],
45+
"@webiny/api-tenancy/*": ["../api-tenancy/src/*"],
46+
"@webiny/api-tenancy": ["../api-tenancy/src"],
4147
"@webiny/aws-sdk/*": ["../aws-sdk/src/*"],
4248
"@webiny/aws-sdk": ["../aws-sdk/src"],
4349
"@webiny/db/*": ["../db/src/*"],
@@ -46,18 +52,14 @@
4652
"@webiny/db-dynamodb": ["../db-dynamodb/src"],
4753
"@webiny/error/*": ["../error/src/*"],
4854
"@webiny/error": ["../error/src"],
55+
"@webiny/plugins/*": ["../plugins/src/*"],
56+
"@webiny/plugins": ["../plugins/src"],
4957
"@webiny/tasks/*": ["../tasks/src/*"],
5058
"@webiny/tasks": ["../tasks/src"],
5159
"@webiny/utils/*": ["../utils/src/*"],
5260
"@webiny/utils": ["../utils/src"],
5361
"@webiny/api-headless-cms/*": ["../api-headless-cms/src/*"],
5462
"@webiny/api-headless-cms": ["../api-headless-cms/src"],
55-
"@webiny/api-i18n/*": ["../api-i18n/src/*"],
56-
"@webiny/api-i18n": ["../api-i18n/src"],
57-
"@webiny/api-security/*": ["../api-security/src/*"],
58-
"@webiny/api-security": ["../api-security/src"],
59-
"@webiny/api-tenancy/*": ["../api-tenancy/src/*"],
60-
"@webiny/api-tenancy": ["../api-tenancy/src"],
6163
"@webiny/api-wcp/*": ["../api-wcp/src/*"],
6264
"@webiny/api-wcp": ["../api-wcp/src"],
6365
"@webiny/handler/*": ["../handler/src/*"],
@@ -67,9 +69,7 @@
6769
"@webiny/handler-db/*": ["../handler-db/src/*"],
6870
"@webiny/handler-db": ["../handler-db/src"],
6971
"@webiny/handler-graphql/*": ["../handler-graphql/src/*"],
70-
"@webiny/handler-graphql": ["../handler-graphql/src"],
71-
"@webiny/plugins/*": ["../plugins/src/*"],
72-
"@webiny/plugins": ["../plugins/src"]
72+
"@webiny/handler-graphql": ["../handler-graphql/src"]
7373
},
7474
"baseUrl": "."
7575
}

packages/api-serverless-cms/__tests__/handlers/helpers/core.ts

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,19 @@ import { createHcmsTasks } from "@webiny/api-headless-cms-tasks";
3838
import { createApwGraphQL, createApwPageBuilderContext } from "@webiny/api-apw";
3939
import { ApwScheduleActionStorageOperations } from "@webiny/api-apw/scheduler/types";
4040
import { createBackgroundTaskContext, createBackgroundTaskGraphQL } from "@webiny/tasks";
41-
import { ContextPlugin } from "@webiny/api";
4241
import pageBuilderImportExportPlugins from "@webiny/api-page-builder-import-export/graphql";
4342
import { createStorageOperations as createPageBuilderImportExportStorageOperations } from "@webiny/api-page-builder-import-export-so-ddb";
44-
import { Context } from "~/index";
4543
import { getDocumentClient } from "@webiny/project-utils/testing/dynamodb";
4644
import { createLogger } from "@webiny/api-log";
4745
import { createCmsPlugins } from "../cms";
46+
import { createTestWcpLicense } from "@webiny/wcp/testing/createTestWcpLicense";
4847

4948
export interface ICreateCoreParams {
5049
plugins?: Plugin[];
5150
path: PathType;
5251
permissions?: Permission[];
5352
tenant?: Pick<Tenant, "id" | "name" | "parent">;
54-
features?: boolean | string[];
53+
features?: boolean;
5554
}
5655

5756
export interface ICreateCoreResult {
@@ -103,49 +102,10 @@ export const createCore = (params: ICreateCoreParams): ICreateCoreResult => {
103102
logout: security.logout,
104103
plugins: [
105104
enableBenchmarkOnEnvironmentVariable(),
106-
createWcpContext(),
107-
createWcpGraphQL(),
108-
new ContextPlugin<Context>(async context => {
109-
if (!features) {
110-
return;
111-
}
112-
113-
const canUse = (name: string): boolean => {
114-
if (features === true) {
115-
return true;
116-
} else if (!Array.isArray(features) || !features.includes(name)) {
117-
return false;
118-
}
119-
return true;
120-
};
121-
122-
context.wcp = {
123-
ensureCanUseFeature: () => void 0,
124-
canUseFolderLevelPermissions: () => {
125-
if (!canUse("advancedAccessControlLayer")) {
126-
return false;
127-
}
128-
// @ts-expect-error
129-
return !!context.project?.package?.features?.advancedAccessControlLayer
130-
?.options?.folderLevelPermissions;
131-
},
132-
canUseAacl: () => {
133-
return canUse("advancedAccessControlLayer");
134-
},
135-
canUsePrivateFiles: () => true,
136-
canUseTeams: () => true,
137-
decrementSeats: async () => void 0,
138-
incrementSeats: async () => void 0,
139-
decrementTenants: async () => void 0,
140-
incrementTenants: async () => void 0,
141-
getProjectEnvironment: () => null,
142-
getProjectLicense: () => null,
143-
canUseFeature: canUse,
144-
canUseRecordLocking: () => {
145-
return canUse("recordLocking");
146-
}
147-
};
105+
createWcpContext({
106+
testProjectLicense: features ? createTestWcpLicense() : undefined
148107
}),
108+
createWcpGraphQL(),
149109
...cmsStorage.plugins,
150110
...pageBuilderStorage.plugins,
151111
...fileManagerStorage.plugins,

packages/api-serverless-cms/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@webiny/plugins": "0.0.0",
4545
"@webiny/project-utils": "0.0.0",
4646
"@webiny/tasks": "0.0.0",
47+
"@webiny/wcp": "0.0.0",
4748
"graphql": "^15.9.0",
4849
"rimraf": "^6.0.1",
4950
"ttypescript": "^1.5.15",

packages/api-serverless-cms/tsconfig.build.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
{ "path": "../handler/tsconfig.build.json" },
3333
{ "path": "../handler-aws/tsconfig.build.json" },
3434
{ "path": "../plugins/tsconfig.build.json" },
35-
{ "path": "../tasks/tsconfig.build.json" }
35+
{ "path": "../tasks/tsconfig.build.json" },
36+
{ "path": "../wcp/tsconfig.build.json" }
3637
],
3738
"compilerOptions": {
3839
"rootDir": "./src",

packages/api-serverless-cms/tsconfig.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
{ "path": "../handler" },
3333
{ "path": "../handler-aws" },
3434
{ "path": "../plugins" },
35-
{ "path": "../tasks" }
35+
{ "path": "../tasks" },
36+
{ "path": "../wcp" }
3637
],
3738
"compilerOptions": {
3839
"rootDirs": ["./src", "./__tests__"],
@@ -106,7 +107,9 @@
106107
"@webiny/plugins/*": ["../plugins/src/*"],
107108
"@webiny/plugins": ["../plugins/src"],
108109
"@webiny/tasks/*": ["../tasks/src/*"],
109-
"@webiny/tasks": ["../tasks/src"]
110+
"@webiny/tasks": ["../tasks/src"],
111+
"@webiny/wcp/*": ["../wcp/src/*"],
112+
"@webiny/wcp": ["../wcp/src"]
110113
},
111114
"baseUrl": "."
112115
}

packages/app-record-locking/tsconfig.build.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
{ "path": "../app/tsconfig.build.json" },
66
{ "path": "../app-aco/tsconfig.build.json" },
77
{ "path": "../app-admin/tsconfig.build.json" },
8-
{ "path": "../form/tsconfig.build.json" },
9-
{ "path": "../plugins/tsconfig.build.json" },
108
{ "path": "../app-headless-cms/tsconfig.build.json" },
119
{ "path": "../app-security/tsconfig.build.json" },
1210
{ "path": "../app-wcp/tsconfig.build.json" },
1311
{ "path": "../app-websockets/tsconfig.build.json" },
1412
{ "path": "../error/tsconfig.build.json" },
13+
{ "path": "../form/tsconfig.build.json" },
14+
{ "path": "../plugins/tsconfig.build.json" },
1515
{ "path": "../react-router/tsconfig.build.json" },
1616
{ "path": "../ui/tsconfig.build.json" },
1717
{ "path": "../utils/tsconfig.build.json" }

packages/app-record-locking/tsconfig.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
{ "path": "../app" },
66
{ "path": "../app-aco" },
77
{ "path": "../app-admin" },
8-
{ "path": "../form" },
9-
{ "path": "../plugins" },
108
{ "path": "../app-headless-cms" },
119
{ "path": "../app-security" },
1210
{ "path": "../app-wcp" },
1311
{ "path": "../app-websockets" },
1412
{ "path": "../error" },
13+
{ "path": "../form" },
14+
{ "path": "../plugins" },
1515
{ "path": "../react-router" },
1616
{ "path": "../ui" },
1717
{ "path": "../utils" }
@@ -29,10 +29,6 @@
2929
"@webiny/app-aco": ["../app-aco/src"],
3030
"@webiny/app-admin/*": ["../app-admin/src/*"],
3131
"@webiny/app-admin": ["../app-admin/src"],
32-
"@webiny/form/*": ["../form/src/*"],
33-
"@webiny/form": ["../form/src"],
34-
"@webiny/plugins/*": ["../plugins/src/*"],
35-
"@webiny/plugins": ["../plugins/src"],
3632
"@webiny/app-headless-cms/*": ["../app-headless-cms/src/*"],
3733
"@webiny/app-headless-cms": ["../app-headless-cms/src"],
3834
"@webiny/app-security/*": ["../app-security/src/*"],
@@ -43,6 +39,10 @@
4339
"@webiny/app-websockets": ["../app-websockets/src"],
4440
"@webiny/error/*": ["../error/src/*"],
4541
"@webiny/error": ["../error/src"],
42+
"@webiny/form/*": ["../form/src/*"],
43+
"@webiny/form": ["../form/src"],
44+
"@webiny/plugins/*": ["../plugins/src/*"],
45+
"@webiny/plugins": ["../plugins/src"],
4646
"@webiny/react-router/*": ["../react-router/src/*"],
4747
"@webiny/react-router": ["../react-router/src"],
4848
"@webiny/ui/*": ["../ui/src/*"],

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13564,6 +13564,7 @@ __metadata:
1356413564
"@webiny/plugins": "npm:0.0.0"
1356513565
"@webiny/project-utils": "npm:0.0.0"
1356613566
"@webiny/tasks": "npm:0.0.0"
13567+
"@webiny/wcp": "npm:0.0.0"
1356713568
graphql: "npm:^15.9.0"
1356813569
rimraf: "npm:^6.0.1"
1356913570
ttypescript: "npm:^1.5.15"

0 commit comments

Comments
 (0)