diff --git a/jest.config.base.js b/jest.config.base.js index 1644c48fd8d..4cf9487ed92 100644 --- a/jest.config.base.js +++ b/jest.config.base.js @@ -1,13 +1,10 @@ +const findUp = require("find-up"); const { basename } = require("path"); const merge = require("merge"); const tsPreset = require("ts-jest/presets/js-with-babel/jest-preset"); const { version } = require("@webiny/cli/package.json"); -process.env.DB_TABLE = "DynamoDB"; -process.env.DB_TABLE_ELASTICSEARCH = "ElasticSearchStream"; -process.env.WEBINY_VERSION = version; - -module.exports = ({ path }, presets = []) => { +module.exports = function ({ path }, presets = []) { const name = basename(path); // Enables us to run tests of only a specific type (for example "integration" or "e2e"). @@ -43,3 +40,59 @@ module.exports = ({ path }, presets = []) => { coverageReporters: ["html"] }); }; + +process.env.DB_TABLE = "DynamoDB"; +process.env.DB_TABLE_ELASTICSEARCH = "ElasticsearchStream"; +process.env.WEBINY_VERSION = version; + +const createDynaliteTables = () => { + return { + tables: [ + { + TableName: process.env.DB_TABLE, + KeySchema: [ + { AttributeName: "PK", KeyType: "HASH" }, + { AttributeName: "SK", KeyType: "RANGE" } + ], + AttributeDefinitions: [ + { AttributeName: "PK", AttributeType: "S" }, + { AttributeName: "SK", AttributeType: "S" }, + { AttributeName: "GSI1_PK", AttributeType: "S" }, + { AttributeName: "GSI1_SK", AttributeType: "S" } + ], + ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 }, + GlobalSecondaryIndexes: [ + { + IndexName: "GSI1", + KeySchema: [ + { AttributeName: "GSI1_PK", KeyType: "HASH" }, + { AttributeName: "GSI1_SK", KeyType: "RANGE" } + ], + Projection: { + ProjectionType: "ALL" + }, + ProvisionedThroughput: { + ReadCapacityUnits: 1, + WriteCapacityUnits: 1 + } + } + ] + }, + { + TableName: process.env.DB_TABLE_ELASTICSEARCH, + KeySchema: [ + { AttributeName: "PK", KeyType: "HASH" }, + { AttributeName: "SK", KeyType: "RANGE" } + ], + AttributeDefinitions: [ + { AttributeName: "PK", AttributeType: "S" }, + { AttributeName: "SK", AttributeType: "S" } + ], + ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } + } + ], + basePort: 8000 + }; +}; + +module.exports.createDynaliteTables = createDynaliteTables; diff --git a/packages/api-admin-users-cognito-so-ddb/__tests__/__api__/setupAfterEnv.js b/packages/api-admin-users-cognito-so-ddb/__tests__/__api__/setupAfterEnv.js index 60ede6c1efc..9a30daa9513 100644 --- a/packages/api-admin-users-cognito-so-ddb/__tests__/__api__/setupAfterEnv.js +++ b/packages/api-admin-users-cognito-so-ddb/__tests__/__api__/setupAfterEnv.js @@ -10,15 +10,27 @@ jestDynalite.setup(path.resolve(__dirname, "../../")); */ beforeAll(async () => { await jestDynalite.startDb(); + if (typeof __beforeAll === "function") { + await __beforeAll(); + } }); beforeEach(async () => { await jestDynalite.createTables(); + if (typeof __beforeEach === "function") { + await __beforeEach(); + } }); afterEach(async () => { await jestDynalite.deleteTables(); + if (typeof __afterEach === "function") { + await __afterEach(); + } }); afterAll(async () => { await jestDynalite.stopDb(); + if (typeof __afterAll === "function") { + await __afterAll(); + } }); diff --git a/packages/api-admin-users-cognito-so-ddb/jest-dynalite-config.js b/packages/api-admin-users-cognito-so-ddb/jest-dynalite-config.js index 41ef7ebfb76..dd245ea811f 100644 --- a/packages/api-admin-users-cognito-so-ddb/jest-dynalite-config.js +++ b/packages/api-admin-users-cognito-so-ddb/jest-dynalite-config.js @@ -1,35 +1,2 @@ -module.exports = { - tables: [ - { - TableName: process.env.DB_TABLE, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" }, - { AttributeName: "GSI1_PK", AttributeType: "S" }, - { AttributeName: "GSI1_SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 }, - GlobalSecondaryIndexes: [ - { - IndexName: "GSI1", - KeySchema: [ - { AttributeName: "GSI1_PK", KeyType: "HASH" }, - { AttributeName: "GSI1_SK", KeyType: "RANGE" } - ], - Projection: { - ProjectionType: "ALL" - }, - ProvisionedThroughput: { - ReadCapacityUnits: 1, - WriteCapacityUnits: 1 - } - } - ] - } - ], - basePort: 8000 -}; +const { createDynaliteTables } = require("../../jest.config.base"); +module.exports = createDynaliteTables(); diff --git a/packages/api-file-manager-ddb-es/__tests__/__api__/environment.js b/packages/api-file-manager-ddb-es/__tests__/__api__/environment.js index 53584f61cc3..d52c71d7293 100644 --- a/packages/api-file-manager-ddb-es/__tests__/__api__/environment.js +++ b/packages/api-file-manager-ddb-es/__tests__/__api__/environment.js @@ -10,6 +10,9 @@ const NodeEnvironment = require("jest-environment-node"); const elasticsearchDataGzipCompression = require("@webiny/api-elasticsearch/plugins/GzipCompression").default; const { ContextPlugin } = require("@webiny/handler/plugins/ContextPlugin"); +const { + elasticIndexManager +} = require("@webiny/project-utils/testing/helpers/elasticIndexManager"); /** * For this to work it must load plugins that have already been built */ @@ -21,24 +24,6 @@ if (typeof plugins !== "function") { const ELASTICSEARCH_PORT = process.env.ELASTICSEARCH_PORT || "9200"; -const getStorageOperationsPlugins = ({ documentClient, elasticsearchClientContext }) => { - return () => { - const pluginsValue = plugins(); - const dbPluginsValue = dbPlugins({ - table: process.env.DB_TABLE, - driver: new DynamoDbDriver({ - documentClient - }) - }); - return [ - elasticsearchDataGzipCompression(), - ...pluginsValue, - ...dbPluginsValue, - elasticsearchClientContext - ]; - }; -}; - class FileManagerTestEnvironment extends NodeEnvironment { async setup() { await super.setup(); @@ -68,29 +53,28 @@ class FileManagerTestEnvironment extends NodeEnvironment { }); simulateStream(documentClient, createHandler(simulationContext, dynamoToElastic())); - const clearEsIndices = async () => { - return elasticsearchClient.indices.delete({ - index: "_all" - }); - }; /** * This is a global function that will be called inside the tests to get all relevant plugins, methods and objects. */ this.global.__getStorageOperationsPlugins = () => { - return getStorageOperationsPlugins({ - elasticsearchClientContext, - documentClient - }); + return () => { + const pluginsValue = plugins(); + const dbPluginsValue = dbPlugins({ + table: process.env.DB_TABLE, + driver: new DynamoDbDriver({ + documentClient + }) + }); + return [ + elasticsearchDataGzipCompression(), + ...pluginsValue, + ...dbPluginsValue, + elasticsearchClientContext + ]; + }; }; - this.global.__beforeEach = async () => { - await clearEsIndices(); - return elasticsearchClient.indices.create({ - index: "root-file-manager" - }); - }; - this.global.__afterEach = clearEsIndices; - this.global.__beforeAll = clearEsIndices; - this.global.__afterAll = clearEsIndices; + + elasticIndexManager(this.global, elasticsearchClient); } } diff --git a/packages/api-file-manager-ddb-es/__tests__/__api__/setupAfterEnv.js b/packages/api-file-manager-ddb-es/__tests__/__api__/setupAfterEnv.js index b8857b963d9..9a30daa9513 100644 --- a/packages/api-file-manager-ddb-es/__tests__/__api__/setupAfterEnv.js +++ b/packages/api-file-manager-ddb-es/__tests__/__api__/setupAfterEnv.js @@ -10,19 +10,27 @@ jestDynalite.setup(path.resolve(__dirname, "../../")); */ beforeAll(async () => { await jestDynalite.startDb(); - //await __beforeAll(); + if (typeof __beforeAll === "function") { + await __beforeAll(); + } }); beforeEach(async () => { await jestDynalite.createTables(); - await __beforeEach(); + if (typeof __beforeEach === "function") { + await __beforeEach(); + } }); afterEach(async () => { await jestDynalite.deleteTables(); - await __afterEach(); + if (typeof __afterEach === "function") { + await __afterEach(); + } }); afterAll(async () => { await jestDynalite.stopDb(); - //await __afterAll(); + if (typeof __afterAll === "function") { + await __afterAll(); + } }); diff --git a/packages/api-file-manager-ddb-es/jest-dynalite-config.js b/packages/api-file-manager-ddb-es/jest-dynalite-config.js index 3a1659ec4bb..6d5840539c8 100644 --- a/packages/api-file-manager-ddb-es/jest-dynalite-config.js +++ b/packages/api-file-manager-ddb-es/jest-dynalite-config.js @@ -1,29 +1,3 @@ -module.exports = { - tables: [ - { - TableName: process.env.DB_TABLE, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } - }, - { - TableName: process.env.DB_TABLE_ELASTICSEARCH, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } - } - ], - basePort: 8000 -}; +const { createDynaliteTables } = require("../../jest.config.base"); + +module.exports = createDynaliteTables(); diff --git a/packages/api-file-manager-ddb-es/src/definitions/table.ts b/packages/api-file-manager-ddb-es/src/definitions/table.ts index 86059d4cb21..2d7f5b6fdbf 100644 --- a/packages/api-file-manager-ddb-es/src/definitions/table.ts +++ b/packages/api-file-manager-ddb-es/src/definitions/table.ts @@ -1,12 +1,11 @@ import { Table } from "dynamodb-toolbox"; -import configurations from "~/operations/configurations"; import { getDocumentClient, getTable } from "~/operations/utils"; import { FileManagerContext } from "@webiny/api-file-manager/types"; export default (params: { context: FileManagerContext }): Table => { const { context } = params; return new Table({ - name: configurations.db().table || getTable(context), + name: process.env.DB_TABLE || getTable(context), partitionKey: "PK", sortKey: "SK", DocumentClient: getDocumentClient(context) diff --git a/packages/api-file-manager-ddb-es/src/operations/configurations.ts b/packages/api-file-manager-ddb-es/src/operations/configurations.ts index c58cd2bfa1b..d3fd3754e0a 100644 --- a/packages/api-file-manager-ddb-es/src/operations/configurations.ts +++ b/packages/api-file-manager-ddb-es/src/operations/configurations.ts @@ -2,7 +2,7 @@ import { FileManagerContext } from "@webiny/api-file-manager/types"; export default { db: () => ({ - table: process.env.DB_TABLE_FILE_MANGER || process.env.DB_TABLE, + table: process.env.DB_TABLE, keys: [ { primary: true, diff --git a/packages/api-file-manager-ddb/__tests__/__api__/environment.js b/packages/api-file-manager-ddb/__tests__/__api__/environment.js index da6851b4930..aac42df831a 100644 --- a/packages/api-file-manager-ddb/__tests__/__api__/environment.js +++ b/packages/api-file-manager-ddb/__tests__/__api__/environment.js @@ -3,6 +3,7 @@ const { DynamoDbDriver } = require("@webiny/db-dynamodb"); const dynamoDbPlugins = require("@webiny/db-dynamodb/plugins").default; const { DocumentClient } = require("aws-sdk/clients/dynamodb"); const NodeEnvironment = require("jest-environment-node"); + /** * For this to work it must load plugins that have already been built */ @@ -12,21 +13,6 @@ if (typeof plugins !== "function") { throw new Error(`Loaded plugins file must export a function that returns an array of plugins.`); } -const getStorageOperationsPlugins = ({ documentClient }) => { - return () => { - return [ - ...dynamoDbPlugins(), - ...plugins(), - ...dbPlugins({ - table: process.env.DB_TABLE, - driver: new DynamoDbDriver({ - documentClient - }) - }) - ]; - }; -}; - class FileManagerTestEnvironment extends NodeEnvironment { async setup() { await super.setup(); @@ -43,9 +29,18 @@ class FileManagerTestEnvironment extends NodeEnvironment { * This is a global function that will be called inside the tests to get all relevant plugins, methods and objects. */ this.global.__getStorageOperationsPlugins = () => { - return getStorageOperationsPlugins({ - documentClient - }); + return () => { + return [ + ...dynamoDbPlugins(), + ...plugins(), + ...dbPlugins({ + table: process.env.DB_TABLE, + driver: new DynamoDbDriver({ + documentClient + }) + }) + ]; + }; }; } } diff --git a/packages/api-file-manager-ddb/__tests__/__api__/setupAfterEnv.js b/packages/api-file-manager-ddb/__tests__/__api__/setupAfterEnv.js index 60ede6c1efc..9a30daa9513 100644 --- a/packages/api-file-manager-ddb/__tests__/__api__/setupAfterEnv.js +++ b/packages/api-file-manager-ddb/__tests__/__api__/setupAfterEnv.js @@ -10,15 +10,27 @@ jestDynalite.setup(path.resolve(__dirname, "../../")); */ beforeAll(async () => { await jestDynalite.startDb(); + if (typeof __beforeAll === "function") { + await __beforeAll(); + } }); beforeEach(async () => { await jestDynalite.createTables(); + if (typeof __beforeEach === "function") { + await __beforeEach(); + } }); afterEach(async () => { await jestDynalite.deleteTables(); + if (typeof __afterEach === "function") { + await __afterEach(); + } }); afterAll(async () => { await jestDynalite.stopDb(); + if (typeof __afterAll === "function") { + await __afterAll(); + } }); diff --git a/packages/api-file-manager-ddb/jest-dynalite-config.js b/packages/api-file-manager-ddb/jest-dynalite-config.js index 22a244634b8..6d5840539c8 100644 --- a/packages/api-file-manager-ddb/jest-dynalite-config.js +++ b/packages/api-file-manager-ddb/jest-dynalite-config.js @@ -1,17 +1,3 @@ -module.exports = { - tables: [ - { - TableName: process.env.DB_TABLE, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } - } - ], - basePort: 8000 -}; +const { createDynaliteTables } = require("../../jest.config.base"); + +module.exports = createDynaliteTables(); diff --git a/packages/api-file-manager/__tests__/files.test.ts b/packages/api-file-manager/__tests__/files.test.ts index cf4a1724dc8..34e1630dd60 100644 --- a/packages/api-file-manager/__tests__/files.test.ts +++ b/packages/api-file-manager/__tests__/files.test.ts @@ -24,8 +24,10 @@ const fileCData = { tags: ["art", "sketch", "webiny", "file-c"] }; +jest.setTimeout(100000); + describe("Files CRUD test", () => { - const { createFile, updateFile, createFiles, getFile, listFiles, listTags, until } = + const { createFile, updateFile, createFiles, getFile, listFiles, listTags, until, sleep } = useGqlHandler(); test("should create, read, update and delete files", async () => { @@ -83,6 +85,7 @@ describe("Files CRUD test", () => { id: fileAId, data: { tags: [...fileAData.tags, "design"] } }); + expect(update2).toEqual({ data: { fileManager: { @@ -94,6 +97,8 @@ describe("Files CRUD test", () => { } }); + await sleep(2000); + // Only update "tags" const [update3] = await updateFile({ id: fileAId, @@ -113,17 +118,21 @@ describe("Files CRUD test", () => { } } }); + + await sleep(2000); await until( () => listFiles().then(([data]) => data), - ({ data }) => - Array.isArray(data.fileManager.listFiles.data) && - data.fileManager.listFiles.data.length === 1 && - data.fileManager.listFiles.data[0].tags.length === 1, + ({ data }) => { + const file = data.fileManager.listFiles.data.find(f => f.id === fileAId); + if (!file) { + return false; + } + return file.tags.length === 1 && file.tags[0] === "sketch"; + }, { - tries: 10, - wait: 400, - name: "list files after update tags" + name: "list files after update tags", + wait: 3000 } ); @@ -168,7 +177,7 @@ describe("Files CRUD test", () => { ({ data }) => { return data.fileManager.listFiles.data.length === 2; }, - { name: "list all files", tries: 10 } + { name: "list all files" } ); // Let's get a all files @@ -346,7 +355,7 @@ describe("Files CRUD test", () => { ({ data }) => { return data.fileManager.listFiles.data.length === 3; }, - { name: "list all files", tries: 20 } + { name: "list all files" } ); const [cResponse] = await listFiles({ diff --git a/packages/api-file-manager/__tests__/helpers.ts b/packages/api-file-manager/__tests__/helpers.ts deleted file mode 100644 index 142c9f85276..00000000000 --- a/packages/api-file-manager/__tests__/helpers.ts +++ /dev/null @@ -1,43 +0,0 @@ -type UntilOptions = { - name?: string; - tries?: number; - wait?: number; -}; - -export const until = async (execute, until, options: UntilOptions = {}) => { - const { name = "NO_NAME", tries = 5, wait = 300 } = options; - - let result; - let triesCount = 0; - - while (true) { - result = await execute(); - - let done; - try { - done = await until(result); - } catch {} - - if (done) { - return result; - } - - triesCount++; - if (triesCount === tries) { - break; - } - - // Wait. - await new Promise((resolve: any) => { - setTimeout(() => resolve(), wait); - }); - } - - throw new Error( - `[${name}] Tried ${tries} times but failed. Last result that was received: ${JSON.stringify( - result, - null, - 2 - )}` - ); -}; diff --git a/packages/api-file-manager/__tests__/tenancySecurity.ts b/packages/api-file-manager/__tests__/tenancySecurity.ts index 4d5c45f74ff..1ed5290c7fe 100644 --- a/packages/api-file-manager/__tests__/tenancySecurity.ts +++ b/packages/api-file-manager/__tests__/tenancySecurity.ts @@ -23,7 +23,7 @@ interface Config { identity?: SecurityIdentity; } -export const createTenancyAndSecurity = ({ permissions, identity }: Config = {}) => { +export const createTenancyAndSecurity = ({ permissions, identity }: Config) => { return [ createTenancyContext({ storageOperations: tenancyStorageOperations({ @@ -33,10 +33,7 @@ export const createTenancyAndSecurity = ({ permissions, identity }: Config = {}) }), createTenancyGraphQL(), createSecurityContext({ - storageOperations: securityStorageOperations({ - documentClient, - table: process.env.DB_TABLE - }) + storageOperations: securityStorageOperations({ documentClient, table: process.env.DB_TABLE }) }), createSecurityGraphQL(), new ContextPlugin(context => { diff --git a/packages/api-file-manager/__tests__/useGqlHandler.ts b/packages/api-file-manager/__tests__/useGqlHandler.ts index 13b2439070b..710c15601cd 100644 --- a/packages/api-file-manager/__tests__/useGqlHandler.ts +++ b/packages/api-file-manager/__tests__/useGqlHandler.ts @@ -5,6 +5,7 @@ import i18nContext from "@webiny/api-i18n/graphql/context"; import i18nDynamoDbStorageOperations from "@webiny/api-i18n-ddb"; import i18nContentPlugins from "@webiny/api-i18n-content/plugins"; import { mockLocalesPlugins } from "@webiny/api-i18n/graphql/testing"; +import { until } from "@webiny/project-utils/testing/helpers/until"; import filesPlugins from "~/plugins"; // Graphql @@ -24,7 +25,6 @@ import { UPDATE_SETTINGS } from "./graphql/fileManagerSettings"; import { SecurityIdentity, SecurityPermission } from "@webiny/api-security/types"; -import { until } from "./helpers"; import { FilePhysicalStoragePlugin } from "~/plugins/definitions/FilePhysicalStoragePlugin"; export interface UseGqlHandlerParams { @@ -33,6 +33,12 @@ export interface UseGqlHandlerParams { plugins?: any; } +const sleep = (ms = 333) => { + return new Promise(resolve => { + setTimeout(resolve, ms); + }); +}; + export default (params: UseGqlHandlerParams = {}) => { const { permissions, identity, plugins = [] } = params; // @ts-ignore @@ -46,21 +52,12 @@ export default (params: UseGqlHandlerParams = {}) => { `A product of "__getStorageOperationsPlugins" must be a function to initialize storage operations.` ); } - const tenant = { id: "root", name: "Root", parent: null }; // Creates the actual handler. Feel free to add additional plugins if needed. const handler = createHandler( storageOperations(), i18nDynamoDbStorageOperations(), graphqlHandlerPlugins(), ...createTenancyAndSecurity({ permissions, identity }), - { - type: "context", - apply(context) { - context.tenancy.getCurrentTenant = () => { - return tenant; - }; - } - }, i18nContext(), i18nContentPlugins(), mockLocalesPlugins(), @@ -94,8 +91,8 @@ export default (params: UseGqlHandlerParams = {}) => { }; return { - tenant, until, + sleep, handler, invoke, // Files diff --git a/packages/api-form-builder-so-ddb-es/__tests__/__api__/environment.js b/packages/api-form-builder-so-ddb-es/__tests__/__api__/environment.js index d43100c254a..a51f5151b62 100644 --- a/packages/api-form-builder-so-ddb-es/__tests__/__api__/environment.js +++ b/packages/api-form-builder-so-ddb-es/__tests__/__api__/environment.js @@ -16,6 +16,9 @@ const { getElasticsearchOperators } = require("@webiny/api-elasticsearch/operato * For this to work it must load plugins that have already been built */ const { createFormBuilderStorageOperations } = require("../../dist/index"); +const { + elasticIndexManager +} = require("@webiny/project-utils/testing/helpers/elasticIndexManager"); if (typeof createFormBuilderStorageOperations !== "function") { throw new Error( @@ -54,11 +57,6 @@ class FormBuilderTestEnvironment extends NodeEnvironment { }); simulateStream(documentClient, createHandler(simulationContext, dynamoToElastic())); - const clearEsIndices = async () => { - return elasticsearchClient.indices.delete({ - index: "_all" - }); - }; /** * This is a global function that will be called inside the tests to get all relevant plugins, methods and objects. */ @@ -94,10 +92,9 @@ class FormBuilderTestEnvironment extends NodeEnvironment { } }; }; - this.global.__beforeEach = clearEsIndices; - this.global.__afterEach = clearEsIndices; - this.global.__beforeAll = clearEsIndices; - this.global.__afterAll = clearEsIndices; + + // Each test should work with its own ES index, and only those indexes have to be deleted. + elasticIndexManager(this.global, elasticsearchClient); } } diff --git a/packages/api-form-builder-so-ddb-es/__tests__/__api__/setupAfterEnv.js b/packages/api-form-builder-so-ddb-es/__tests__/__api__/setupAfterEnv.js index b8857b963d9..9a30daa9513 100644 --- a/packages/api-form-builder-so-ddb-es/__tests__/__api__/setupAfterEnv.js +++ b/packages/api-form-builder-so-ddb-es/__tests__/__api__/setupAfterEnv.js @@ -10,19 +10,27 @@ jestDynalite.setup(path.resolve(__dirname, "../../")); */ beforeAll(async () => { await jestDynalite.startDb(); - //await __beforeAll(); + if (typeof __beforeAll === "function") { + await __beforeAll(); + } }); beforeEach(async () => { await jestDynalite.createTables(); - await __beforeEach(); + if (typeof __beforeEach === "function") { + await __beforeEach(); + } }); afterEach(async () => { await jestDynalite.deleteTables(); - await __afterEach(); + if (typeof __afterEach === "function") { + await __afterEach(); + } }); afterAll(async () => { await jestDynalite.stopDb(); - //await __afterAll(); + if (typeof __afterAll === "function") { + await __afterAll(); + } }); diff --git a/packages/api-form-builder-so-ddb-es/jest-dynalite-config.js b/packages/api-form-builder-so-ddb-es/jest-dynalite-config.js index 3a1659ec4bb..dd245ea811f 100644 --- a/packages/api-form-builder-so-ddb-es/jest-dynalite-config.js +++ b/packages/api-form-builder-so-ddb-es/jest-dynalite-config.js @@ -1,29 +1,2 @@ -module.exports = { - tables: [ - { - TableName: process.env.DB_TABLE, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } - }, - { - TableName: process.env.DB_TABLE_ELASTICSEARCH, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } - } - ], - basePort: 8000 -}; +const { createDynaliteTables } = require("../../jest.config.base"); +module.exports = createDynaliteTables(); diff --git a/packages/api-form-builder-so-ddb-es/src/definitions/table.ts b/packages/api-form-builder-so-ddb-es/src/definitions/table.ts index 486b95cfee7..89fb7b91622 100644 --- a/packages/api-form-builder-so-ddb-es/src/definitions/table.ts +++ b/packages/api-form-builder-so-ddb-es/src/definitions/table.ts @@ -10,7 +10,7 @@ export const createTable = (params: Params): Table => { const { tableName, documentClient } = params; return new Table({ - name: tableName || process.env.DB_TABLE_FORM_BUILDER || process.env.DB_TABLE, + name: tableName || process.env.DB_TABLE, partitionKey: "PK", sortKey: "SK", DocumentClient: documentClient diff --git a/packages/api-form-builder-so-ddb/__tests__/__api__/environment.js b/packages/api-form-builder-so-ddb/__tests__/__api__/environment.js index 924f01d548e..53fa279b84b 100644 --- a/packages/api-form-builder-so-ddb/__tests__/__api__/environment.js +++ b/packages/api-form-builder-so-ddb/__tests__/__api__/environment.js @@ -17,6 +17,7 @@ if (typeof createFormBuilderStorageOperations !== "function") { class FormBuilderTestEnvironment extends NodeEnvironment { async setup() { await super.setup(); + const documentClient = new DocumentClient({ convertEmptyValues: true, endpoint: process.env.MOCK_DYNAMODB_ENDPOINT || "http://localhost:8001", diff --git a/packages/api-form-builder-so-ddb/__tests__/__api__/setupAfterEnv.js b/packages/api-form-builder-so-ddb/__tests__/__api__/setupAfterEnv.js index 60ede6c1efc..9a30daa9513 100644 --- a/packages/api-form-builder-so-ddb/__tests__/__api__/setupAfterEnv.js +++ b/packages/api-form-builder-so-ddb/__tests__/__api__/setupAfterEnv.js @@ -10,15 +10,27 @@ jestDynalite.setup(path.resolve(__dirname, "../../")); */ beforeAll(async () => { await jestDynalite.startDb(); + if (typeof __beforeAll === "function") { + await __beforeAll(); + } }); beforeEach(async () => { await jestDynalite.createTables(); + if (typeof __beforeEach === "function") { + await __beforeEach(); + } }); afterEach(async () => { await jestDynalite.deleteTables(); + if (typeof __afterEach === "function") { + await __afterEach(); + } }); afterAll(async () => { await jestDynalite.stopDb(); + if (typeof __afterAll === "function") { + await __afterAll(); + } }); diff --git a/packages/api-form-builder-so-ddb/jest-dynalite-config.js b/packages/api-form-builder-so-ddb/jest-dynalite-config.js index 41ef7ebfb76..dd245ea811f 100644 --- a/packages/api-form-builder-so-ddb/jest-dynalite-config.js +++ b/packages/api-form-builder-so-ddb/jest-dynalite-config.js @@ -1,35 +1,2 @@ -module.exports = { - tables: [ - { - TableName: process.env.DB_TABLE, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" }, - { AttributeName: "GSI1_PK", AttributeType: "S" }, - { AttributeName: "GSI1_SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 }, - GlobalSecondaryIndexes: [ - { - IndexName: "GSI1", - KeySchema: [ - { AttributeName: "GSI1_PK", KeyType: "HASH" }, - { AttributeName: "GSI1_SK", KeyType: "RANGE" } - ], - Projection: { - ProjectionType: "ALL" - }, - ProvisionedThroughput: { - ReadCapacityUnits: 1, - WriteCapacityUnits: 1 - } - } - ] - } - ], - basePort: 8000 -}; +const { createDynaliteTables } = require("../../jest.config.base"); +module.exports = createDynaliteTables(); diff --git a/packages/api-form-builder-so-ddb/src/definitions/table.ts b/packages/api-form-builder-so-ddb/src/definitions/table.ts index 3dfd4e241e7..032d5eaef2f 100644 --- a/packages/api-form-builder-so-ddb/src/definitions/table.ts +++ b/packages/api-form-builder-so-ddb/src/definitions/table.ts @@ -10,7 +10,7 @@ export const createTable = (params: Params): Table => { const { tableName, documentClient } = params; return new Table({ - name: tableName || process.env.DB_TABLE_FORM_BUILDER || process.env.DB_TABLE, + name: tableName || process.env.DB_TABLE, partitionKey: "PK", sortKey: "SK", DocumentClient: documentClient, diff --git a/packages/api-headless-cms-ddb-es/__tests__/__api__/environment.js b/packages/api-headless-cms-ddb-es/__tests__/__api__/environment.js index 67c7cb80073..5510e617542 100644 --- a/packages/api-headless-cms-ddb-es/__tests__/__api__/environment.js +++ b/packages/api-headless-cms-ddb-es/__tests__/__api__/environment.js @@ -10,6 +10,7 @@ const NodeEnvironment = require("jest-environment-node"); const elasticsearchDataGzipCompression = require("@webiny/api-elasticsearch/plugins/GzipCompression").default; const { ContextPlugin } = require("@webiny/handler/plugins/ContextPlugin"); +const {elasticIndexManager} = require("@webiny/project-utils/testing/helpers/elasticIndexManager"); /** * For this to work it must load plugins that have already been built */ @@ -109,11 +110,7 @@ class CmsTestEnvironment extends NodeEnvironment { endpoint: `http://localhost:${ELASTICSEARCH_PORT}`, auth: {} }); - const clearEsIndices = async () => { - return elasticsearchClient.indices.delete({ - index: "_all" - }); - }; + /** * This is a global function that will be called inside the tests to get all relevant plugins, methods and objects. */ @@ -124,10 +121,8 @@ class CmsTestEnvironment extends NodeEnvironment { documentClient }); }; - this.global.__beforeEach = clearEsIndices; - this.global.__afterEach = clearEsIndices; - this.global.__beforeAll = clearEsIndices; - this.global.__afterAll = clearEsIndices; + + elasticIndexManager(this.global, elasticsearchClient); } } diff --git a/packages/api-headless-cms-ddb-es/__tests__/__api__/setupAfterEnv.js b/packages/api-headless-cms-ddb-es/__tests__/__api__/setupAfterEnv.js index b8857b963d9..9a30daa9513 100644 --- a/packages/api-headless-cms-ddb-es/__tests__/__api__/setupAfterEnv.js +++ b/packages/api-headless-cms-ddb-es/__tests__/__api__/setupAfterEnv.js @@ -10,19 +10,27 @@ jestDynalite.setup(path.resolve(__dirname, "../../")); */ beforeAll(async () => { await jestDynalite.startDb(); - //await __beforeAll(); + if (typeof __beforeAll === "function") { + await __beforeAll(); + } }); beforeEach(async () => { await jestDynalite.createTables(); - await __beforeEach(); + if (typeof __beforeEach === "function") { + await __beforeEach(); + } }); afterEach(async () => { await jestDynalite.deleteTables(); - await __afterEach(); + if (typeof __afterEach === "function") { + await __afterEach(); + } }); afterAll(async () => { await jestDynalite.stopDb(); - //await __afterAll(); + if (typeof __afterAll === "function") { + await __afterAll(); + } }); diff --git a/packages/api-headless-cms-ddb-es/jest-dynalite-config.js b/packages/api-headless-cms-ddb-es/jest-dynalite-config.js index 3a1659ec4bb..6d5840539c8 100644 --- a/packages/api-headless-cms-ddb-es/jest-dynalite-config.js +++ b/packages/api-headless-cms-ddb-es/jest-dynalite-config.js @@ -1,29 +1,3 @@ -module.exports = { - tables: [ - { - TableName: process.env.DB_TABLE, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } - }, - { - TableName: process.env.DB_TABLE_ELASTICSEARCH, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } - } - ], - basePort: 8000 -}; +const { createDynaliteTables } = require("../../jest.config.base"); + +module.exports = createDynaliteTables(); diff --git a/packages/api-headless-cms-ddb-es/src/configurations.ts b/packages/api-headless-cms-ddb-es/src/configurations.ts index b208b66d874..932640ace58 100644 --- a/packages/api-headless-cms-ddb-es/src/configurations.ts +++ b/packages/api-headless-cms-ddb-es/src/configurations.ts @@ -28,7 +28,7 @@ interface Configurations { const configurations: Configurations = { db: () => ({ - table: process.env.DB_TABLE_HEADLESS_CMS || process.env.DB_TABLE, + table: process.env.DB_TABLE, keys: [ { primary: true, @@ -39,8 +39,7 @@ const configurations: Configurations = { ] }), esDb: () => ({ - table: - process.env.DB_TABLE_HEADLESS_CMS_ELASTICSEARCH || process.env.DB_TABLE_ELASTICSEARCH, + table: process.env.DB_TABLE_ELASTICSEARCH, keys: [ { primary: true, diff --git a/packages/api-headless-cms-ddb/__tests__/__api__/environment.js b/packages/api-headless-cms-ddb/__tests__/__api__/environment.js index f798c4085a1..3555d4437a3 100644 --- a/packages/api-headless-cms-ddb/__tests__/__api__/environment.js +++ b/packages/api-headless-cms-ddb/__tests__/__api__/environment.js @@ -13,21 +13,6 @@ if (typeof plugins !== "function") { throw new Error(`Loaded plugins file must export a function that returns an array of plugins.`); } -const getStorageOperationsPlugins = ({ documentClient }) => { - return () => { - return [ - plugins(), - dbPlugins({ - table: process.env.DB_TABLE, - driver: new DynamoDbDriver({ - documentClient - }) - }), - ...dynamoDbPlugins() - ]; - }; -}; - class CmsTestEnvironment extends NodeEnvironment { async setup() { await super.setup(); @@ -44,9 +29,18 @@ class CmsTestEnvironment extends NodeEnvironment { * This is a global function that will be called inside the tests to get all relevant plugins, methods and objects. */ this.global.__getStorageOperationsPlugins = () => { - return getStorageOperationsPlugins({ - documentClient - }); + return () => { + return [ + plugins(), + dbPlugins({ + table: process.env.DB_TABLE, + driver: new DynamoDbDriver({ + documentClient + }) + }), + ...dynamoDbPlugins() + ]; + }; }; } } diff --git a/packages/api-headless-cms-ddb/__tests__/__api__/setupAfterEnv.js b/packages/api-headless-cms-ddb/__tests__/__api__/setupAfterEnv.js index f71ad03a47b..9a30daa9513 100644 --- a/packages/api-headless-cms-ddb/__tests__/__api__/setupAfterEnv.js +++ b/packages/api-headless-cms-ddb/__tests__/__api__/setupAfterEnv.js @@ -10,19 +10,27 @@ jestDynalite.setup(path.resolve(__dirname, "../../")); */ beforeAll(async () => { await jestDynalite.startDb(); - //await __beforeAll(); + if (typeof __beforeAll === "function") { + await __beforeAll(); + } }); beforeEach(async () => { await jestDynalite.createTables(); - //await __beforeEach(); + if (typeof __beforeEach === "function") { + await __beforeEach(); + } }); afterEach(async () => { await jestDynalite.deleteTables(); - //await __afterEach(); + if (typeof __afterEach === "function") { + await __afterEach(); + } }); afterAll(async () => { await jestDynalite.stopDb(); - //await __afterAll(); + if (typeof __afterAll === "function") { + await __afterAll(); + } }); diff --git a/packages/api-headless-cms-ddb/jest-dynalite-config.js b/packages/api-headless-cms-ddb/jest-dynalite-config.js index 41ef7ebfb76..6d5840539c8 100644 --- a/packages/api-headless-cms-ddb/jest-dynalite-config.js +++ b/packages/api-headless-cms-ddb/jest-dynalite-config.js @@ -1,35 +1,3 @@ -module.exports = { - tables: [ - { - TableName: process.env.DB_TABLE, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" }, - { AttributeName: "GSI1_PK", AttributeType: "S" }, - { AttributeName: "GSI1_SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 }, - GlobalSecondaryIndexes: [ - { - IndexName: "GSI1", - KeySchema: [ - { AttributeName: "GSI1_PK", KeyType: "HASH" }, - { AttributeName: "GSI1_SK", KeyType: "RANGE" } - ], - Projection: { - ProjectionType: "ALL" - }, - ProvisionedThroughput: { - ReadCapacityUnits: 1, - WriteCapacityUnits: 1 - } - } - ] - } - ], - basePort: 8000 -}; +const { createDynaliteTables } = require("../../jest.config.base"); + +module.exports = createDynaliteTables(); diff --git a/packages/api-headless-cms/__tests__/contentAPI/contentModel.crud.test.ts b/packages/api-headless-cms/__tests__/contentAPI/contentModel.crud.test.ts index 107dde077d6..5a6191f9ffd 100644 --- a/packages/api-headless-cms/__tests__/contentAPI/contentModel.crud.test.ts +++ b/packages/api-headless-cms/__tests__/contentAPI/contentModel.crud.test.ts @@ -15,8 +15,6 @@ const getTypeObject = (schema, type) => { return schema.types.find(t => t.name === type); }; -jest.setTimeout(15000); - const createPermissions = ({ models, groups }: { models?: string[]; groups?: string[] }) => [ { name: "cms.settings" @@ -46,6 +44,8 @@ const createPermissions = ({ models, groups }: { models?: string[]; groups?: str } ]; +jest.setTimeout(100000); + describe("content model test", () => { const readHandlerOpts = { path: "read/en-US" }; const manageHandlerOpts = { path: "manage/en-US" }; diff --git a/packages/api-headless-cms/__tests__/contentAPI/contentModel.crud.uniqueModelId.test.ts b/packages/api-headless-cms/__tests__/contentAPI/contentModel.crud.uniqueModelId.test.ts index 13b6f93afe7..02c912c43e1 100644 --- a/packages/api-headless-cms/__tests__/contentAPI/contentModel.crud.uniqueModelId.test.ts +++ b/packages/api-headless-cms/__tests__/contentAPI/contentModel.crud.uniqueModelId.test.ts @@ -2,8 +2,6 @@ import { CmsContentModelGroup } from "../../src/types"; import { useContentGqlHandler } from "../utils/useContentGqlHandler"; import { hooksTracker } from "./mocks/lifecycleHooks"; -jest.setTimeout(15000); - describe("content model test", () => { const manageHandlerOpts = { path: "manage/en-US" }; diff --git a/packages/api-headless-cms/__tests__/contentAPI/filtering.test.ts b/packages/api-headless-cms/__tests__/contentAPI/filtering.test.ts index 4d50f29ad48..10721580f72 100644 --- a/packages/api-headless-cms/__tests__/contentAPI/filtering.test.ts +++ b/packages/api-headless-cms/__tests__/contentAPI/filtering.test.ts @@ -8,8 +8,6 @@ import { useArticleManageHandler } from "../utils/useArticleManageHandler"; import { useArticleReadHandler } from "../utils/useArticleReadHandler"; import { setupContentModelGroup, setupContentModels } from "../utils/setup"; -jest.setTimeout(25000); - const appleData = { name: "Apple", isSomething: false, @@ -55,6 +53,8 @@ const bananaData = { time: "11:59:01" }; +jest.setTimeout(100000); + describe("filtering", () => { const manageOpts = { path: "manage/en-US" }; const readOpts = { path: "read/en-US" }; diff --git a/packages/api-headless-cms/__tests__/contentAPI/httpOptions.test.ts b/packages/api-headless-cms/__tests__/contentAPI/httpOptions.test.ts index d56a36c5705..b502b0c9964 100644 --- a/packages/api-headless-cms/__tests__/contentAPI/httpOptions.test.ts +++ b/packages/api-headless-cms/__tests__/contentAPI/httpOptions.test.ts @@ -1,7 +1,5 @@ import { useCategoryManageHandler } from "../utils/useCategoryManageHandler"; -jest.setTimeout(15000); - describe("HTTP Options request", () => { const manageOpts = { path: "manage/en-US" }; diff --git a/packages/api-headless-cms/__tests__/contentAPI/latestEntries.test.ts b/packages/api-headless-cms/__tests__/contentAPI/latestEntries.test.ts index d275d6b3999..386b415eeab 100644 --- a/packages/api-headless-cms/__tests__/contentAPI/latestEntries.test.ts +++ b/packages/api-headless-cms/__tests__/contentAPI/latestEntries.test.ts @@ -5,6 +5,8 @@ import { useCategoryManageHandler } from "../utils/useCategoryManageHandler"; import { useArticleManageHandler } from "../utils/useArticleManageHandler"; import { useArticleReadHandler } from "../utils/useArticleReadHandler"; +jest.setTimeout(100000); + describe("latest entries", function () { const manageOpts = { path: "manage/en-US" }; const previewOpts = { path: "preview/en-US" }; diff --git a/packages/api-headless-cms/__tests__/contentAPI/refField.test.ts b/packages/api-headless-cms/__tests__/contentAPI/refField.test.ts index 333ca50a94d..436d80f271e 100644 --- a/packages/api-headless-cms/__tests__/contentAPI/refField.test.ts +++ b/packages/api-headless-cms/__tests__/contentAPI/refField.test.ts @@ -7,8 +7,6 @@ import { useCategoryManageHandler } from "../utils/useCategoryManageHandler"; import { useReviewReadHandler } from "../utils/useReviewReadHandler"; import { useAuthorManageHandler } from "../utils/useAuthorManageHandler"; -jest.setTimeout(25000); - describe("refField", () => { const manageOpts = { path: "manage/en-US" }; const readOpts = { path: "read/en-US" }; diff --git a/packages/api-headless-cms/__tests__/contentAPI/requestReview.test.ts b/packages/api-headless-cms/__tests__/contentAPI/requestReview.test.ts index 54009bd14c0..3baa39234b7 100644 --- a/packages/api-headless-cms/__tests__/contentAPI/requestReview.test.ts +++ b/packages/api-headless-cms/__tests__/contentAPI/requestReview.test.ts @@ -4,8 +4,6 @@ import { useContentGqlHandler } from "../utils/useContentGqlHandler"; import { useCategoryManageHandler } from "../utils/useCategoryManageHandler"; import models from "./mocks/contentModels"; -jest.setTimeout(15000); - describe("Request review", () => { let contentModelGroup: CmsContentModelGroup; diff --git a/packages/api-headless-cms/__tests__/contentAPI/resolvers.manage.test.ts b/packages/api-headless-cms/__tests__/contentAPI/resolvers.manage.test.ts index 57434c7a03c..57075fde1f1 100644 --- a/packages/api-headless-cms/__tests__/contentAPI/resolvers.manage.test.ts +++ b/packages/api-headless-cms/__tests__/contentAPI/resolvers.manage.test.ts @@ -8,8 +8,6 @@ import models from "./mocks/contentModels"; import modelsWithoutValidation from "./mocks/contentModels.noValidation"; import { useProductManageHandler } from "../utils/useProductManageHandler"; -jest.setTimeout(15000); - interface CreateCategoriesResult { fruits: CmsContentEntry; vegetables: CmsContentEntry; @@ -44,6 +42,8 @@ const createPermissions = ({ groups, models }: { groups?: string[]; models?: str } ]; +jest.setTimeout(100000); + describe("MANAGE - Resolvers", () => { let contentModelGroup: CmsContentModelGroup; diff --git a/packages/api-headless-cms/__tests__/contentAPI/resolvers.read.test.ts b/packages/api-headless-cms/__tests__/contentAPI/resolvers.read.test.ts index b833ca5358f..c132f452941 100644 --- a/packages/api-headless-cms/__tests__/contentAPI/resolvers.read.test.ts +++ b/packages/api-headless-cms/__tests__/contentAPI/resolvers.read.test.ts @@ -6,8 +6,6 @@ import { useCategoryReadHandler } from "../utils/useCategoryReadHandler"; import { useProductManageHandler } from "../utils/useProductManageHandler"; import { useProductReadHandler } from "../utils/useProductReadHandler"; -jest.setTimeout(25000); - const createPermissions = ({ groups, models }: { groups?: string[]; models?: string[] }) => [ { name: "cms.settings" @@ -80,6 +78,8 @@ const categoryManagerHelper = async manageOpts => { }; }; +jest.setTimeout(100000); + describe("READ - Resolvers", () => { let contentModelGroup: CmsContentModelGroup; diff --git a/packages/api-headless-cms/__tests__/contentAPI/richTextField.test.ts b/packages/api-headless-cms/__tests__/contentAPI/richTextField.test.ts index 473aa3bd8b3..89316c1a8d2 100644 --- a/packages/api-headless-cms/__tests__/contentAPI/richTextField.test.ts +++ b/packages/api-headless-cms/__tests__/contentAPI/richTextField.test.ts @@ -5,8 +5,6 @@ import { useProductManageHandler } from "../utils/useProductManageHandler"; import { useCategoryManageHandler } from "../utils/useCategoryManageHandler"; import { useProductReadHandler } from "../utils/useProductReadHandler"; -jest.setTimeout(25000); - const richTextMock = [ { tag: "h1", diff --git a/packages/api-headless-cms/__tests__/contentAPI/sorting.test.ts b/packages/api-headless-cms/__tests__/contentAPI/sorting.test.ts index 55cf3ebc6f4..5da6a89a675 100644 --- a/packages/api-headless-cms/__tests__/contentAPI/sorting.test.ts +++ b/packages/api-headless-cms/__tests__/contentAPI/sorting.test.ts @@ -63,6 +63,8 @@ const grahamData = { time: "11:59:01" }; +jest.setTimeout(100000); + describe("sorting + cursor", () => { const manageOpts = { path: "manage/en-US" }; const readOpts = { path: "read/en-US" }; diff --git a/packages/api-headless-cms/__tests__/utils/helpers.ts b/packages/api-headless-cms/__tests__/utils/helpers.ts index 39b5b4b445f..03d5a9be133 100644 --- a/packages/api-headless-cms/__tests__/utils/helpers.ts +++ b/packages/api-headless-cms/__tests__/utils/helpers.ts @@ -83,6 +83,12 @@ type UntilOptions = { wait?: number; }; +export const sleep = (ms = 333) => { + return new Promise(resolve => { + setTimeout(resolve, ms); + }); +}; + export const until = async (execute, until, options: UntilOptions = {}) => { const { name = "NO_NAME", tries = 5, wait = 300 } = options; diff --git a/packages/api-i18n-ddb/__tests__/__api__/setupAfterEnv.js b/packages/api-i18n-ddb/__tests__/__api__/setupAfterEnv.js index 60ede6c1efc..9a30daa9513 100644 --- a/packages/api-i18n-ddb/__tests__/__api__/setupAfterEnv.js +++ b/packages/api-i18n-ddb/__tests__/__api__/setupAfterEnv.js @@ -10,15 +10,27 @@ jestDynalite.setup(path.resolve(__dirname, "../../")); */ beforeAll(async () => { await jestDynalite.startDb(); + if (typeof __beforeAll === "function") { + await __beforeAll(); + } }); beforeEach(async () => { await jestDynalite.createTables(); + if (typeof __beforeEach === "function") { + await __beforeEach(); + } }); afterEach(async () => { await jestDynalite.deleteTables(); + if (typeof __afterEach === "function") { + await __afterEach(); + } }); afterAll(async () => { await jestDynalite.stopDb(); + if (typeof __afterAll === "function") { + await __afterAll(); + } }); diff --git a/packages/api-i18n-ddb/jest-dynalite-config.js b/packages/api-i18n-ddb/jest-dynalite-config.js index 22a244634b8..dd245ea811f 100644 --- a/packages/api-i18n-ddb/jest-dynalite-config.js +++ b/packages/api-i18n-ddb/jest-dynalite-config.js @@ -1,17 +1,2 @@ -module.exports = { - tables: [ - { - TableName: process.env.DB_TABLE, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } - } - ], - basePort: 8000 -}; +const { createDynaliteTables } = require("../../jest.config.base"); +module.exports = createDynaliteTables(); diff --git a/packages/api-i18n-ddb/src/operations/configurations.ts b/packages/api-i18n-ddb/src/operations/configurations.ts index 5b31a116e4d..9c7a8a627fe 100644 --- a/packages/api-i18n-ddb/src/operations/configurations.ts +++ b/packages/api-i18n-ddb/src/operations/configurations.ts @@ -1,6 +1,6 @@ export default { db: () => ({ - table: process.env.DB_TABLE_I18N || process.env.DB_TABLE, + table: process.env.DB_TABLE, keys: [ { primary: true, diff --git a/packages/api-page-builder-import-export-so-ddb/__tests__/__api__/setupAfterEnv.js b/packages/api-page-builder-import-export-so-ddb/__tests__/__api__/setupAfterEnv.js index f71ad03a47b..9a30daa9513 100644 --- a/packages/api-page-builder-import-export-so-ddb/__tests__/__api__/setupAfterEnv.js +++ b/packages/api-page-builder-import-export-so-ddb/__tests__/__api__/setupAfterEnv.js @@ -10,19 +10,27 @@ jestDynalite.setup(path.resolve(__dirname, "../../")); */ beforeAll(async () => { await jestDynalite.startDb(); - //await __beforeAll(); + if (typeof __beforeAll === "function") { + await __beforeAll(); + } }); beforeEach(async () => { await jestDynalite.createTables(); - //await __beforeEach(); + if (typeof __beforeEach === "function") { + await __beforeEach(); + } }); afterEach(async () => { await jestDynalite.deleteTables(); - //await __afterEach(); + if (typeof __afterEach === "function") { + await __afterEach(); + } }); afterAll(async () => { await jestDynalite.stopDb(); - //await __afterAll(); + if (typeof __afterAll === "function") { + await __afterAll(); + } }); diff --git a/packages/api-page-builder-import-export-so-ddb/jest-dynalite-config.js b/packages/api-page-builder-import-export-so-ddb/jest-dynalite-config.js index 41ef7ebfb76..6d5840539c8 100644 --- a/packages/api-page-builder-import-export-so-ddb/jest-dynalite-config.js +++ b/packages/api-page-builder-import-export-so-ddb/jest-dynalite-config.js @@ -1,35 +1,3 @@ -module.exports = { - tables: [ - { - TableName: process.env.DB_TABLE, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" }, - { AttributeName: "GSI1_PK", AttributeType: "S" }, - { AttributeName: "GSI1_SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 }, - GlobalSecondaryIndexes: [ - { - IndexName: "GSI1", - KeySchema: [ - { AttributeName: "GSI1_PK", KeyType: "HASH" }, - { AttributeName: "GSI1_SK", KeyType: "RANGE" } - ], - Projection: { - ProjectionType: "ALL" - }, - ProvisionedThroughput: { - ReadCapacityUnits: 1, - WriteCapacityUnits: 1 - } - } - ] - } - ], - basePort: 8000 -}; +const { createDynaliteTables } = require("../../jest.config.base"); + +module.exports = createDynaliteTables(); diff --git a/packages/api-page-builder-so-ddb-es/__tests__/__api__/environment.js b/packages/api-page-builder-so-ddb-es/__tests__/__api__/environment.js index 2fe2c189718..63192c231bf 100644 --- a/packages/api-page-builder-so-ddb-es/__tests__/__api__/environment.js +++ b/packages/api-page-builder-so-ddb-es/__tests__/__api__/environment.js @@ -10,6 +10,7 @@ const NodeEnvironment = require("jest-environment-node"); const elasticsearchDataGzipCompression = require("@webiny/api-elasticsearch/plugins/GzipCompression").default; const { ContextPlugin } = require("@webiny/handler/plugins/ContextPlugin"); +const {elasticIndexManager} = require("@webiny/project-utils/testing/helpers/elasticIndexManager"); const dynamoDbPlugins = require("@webiny/db-dynamodb/plugins").default; /** * For this to work it must load plugins that have already been built @@ -70,11 +71,6 @@ class PageBuilderTestEnvironment extends NodeEnvironment { }); simulateStream(documentClient, createHandler(simulationContext, dynamoToElastic())); - const clearEsIndices = async () => { - return elasticsearchClient.indices.delete({ - index: "_all" - }); - }; /** * This is a global function that will be called inside the tests to get all relevant plugins, methods and objects. */ @@ -84,10 +80,8 @@ class PageBuilderTestEnvironment extends NodeEnvironment { documentClient }); }; - this.global.__beforeEach = clearEsIndices; - this.global.__afterEach = clearEsIndices; - this.global.__beforeAll = clearEsIndices; - this.global.__afterAll = clearEsIndices; + + elasticIndexManager(this.global, elasticsearchClient); } } diff --git a/packages/api-page-builder-so-ddb-es/__tests__/__api__/setupAfterEnv.js b/packages/api-page-builder-so-ddb-es/__tests__/__api__/setupAfterEnv.js index b8857b963d9..9a30daa9513 100644 --- a/packages/api-page-builder-so-ddb-es/__tests__/__api__/setupAfterEnv.js +++ b/packages/api-page-builder-so-ddb-es/__tests__/__api__/setupAfterEnv.js @@ -10,19 +10,27 @@ jestDynalite.setup(path.resolve(__dirname, "../../")); */ beforeAll(async () => { await jestDynalite.startDb(); - //await __beforeAll(); + if (typeof __beforeAll === "function") { + await __beforeAll(); + } }); beforeEach(async () => { await jestDynalite.createTables(); - await __beforeEach(); + if (typeof __beforeEach === "function") { + await __beforeEach(); + } }); afterEach(async () => { await jestDynalite.deleteTables(); - await __afterEach(); + if (typeof __afterEach === "function") { + await __afterEach(); + } }); afterAll(async () => { await jestDynalite.stopDb(); - //await __afterAll(); + if (typeof __afterAll === "function") { + await __afterAll(); + } }); diff --git a/packages/api-page-builder-so-ddb-es/jest-dynalite-config.js b/packages/api-page-builder-so-ddb-es/jest-dynalite-config.js index 3a1659ec4bb..6d5840539c8 100644 --- a/packages/api-page-builder-so-ddb-es/jest-dynalite-config.js +++ b/packages/api-page-builder-so-ddb-es/jest-dynalite-config.js @@ -1,29 +1,3 @@ -module.exports = { - tables: [ - { - TableName: process.env.DB_TABLE, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } - }, - { - TableName: process.env.DB_TABLE_ELASTICSEARCH, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } - } - ], - basePort: 8000 -}; +const { createDynaliteTables } = require("../../jest.config.base"); + +module.exports = createDynaliteTables(); diff --git a/packages/api-page-builder-so-ddb-es/src/operations/configurations.ts b/packages/api-page-builder-so-ddb-es/src/operations/configurations.ts index b8be2732ea0..7ddf65eed7a 100644 --- a/packages/api-page-builder-so-ddb-es/src/operations/configurations.ts +++ b/packages/api-page-builder-so-ddb-es/src/operations/configurations.ts @@ -3,7 +3,7 @@ import { PbContext } from "@webiny/api-page-builder/graphql/types"; export default { db: () => ({ - table: process.env.DB_TABLE_PAGE_BUILDER || process.env.DB_TABLE, + table: process.env.DB_TABLE, keys: [ { primary: true, @@ -14,17 +14,19 @@ export default { { unique: true, name: "GSI1", fields: [{ name: "GSI1_PK" }, { name: "GSI1_SK" }] } ] }), - esDb: () => ({ - table: process.env.DB_TABLE_ELASTICSEARCH, - keys: [ - { - primary: true, - unique: true, - name: "primary", - fields: [{ name: "PK" }, { name: "SK" }] - } - ] - }), + esDb: () => { + return { + table: process.env.DB_TABLE_ELASTICSEARCH, + keys: [ + { + primary: true, + unique: true, + name: "primary", + fields: [{ name: "PK" }, { name: "SK" }] + } + ] + }; + }, es: (context: PbContext) => { const tenant = context.tenancy.getCurrentTenant(); if (!tenant) { diff --git a/packages/api-page-builder-so-ddb-es/src/operations/system/InstallationDdbEsPlugin.ts b/packages/api-page-builder-so-ddb-es/src/operations/system/InstallationDdbEsPlugin.ts index b474ee736c1..52e280e9aee 100644 --- a/packages/api-page-builder-so-ddb-es/src/operations/system/InstallationDdbEsPlugin.ts +++ b/packages/api-page-builder-so-ddb-es/src/operations/system/InstallationDdbEsPlugin.ts @@ -11,7 +11,7 @@ export const installation = () => { const { elasticsearch } = context; const { index } = configurations.es(context); - + const { body: exists } = await elasticsearch.indices.exists({ index }); if (exists) { return; diff --git a/packages/api-page-builder-so-ddb/__tests__/__api__/setupAfterEnv.js b/packages/api-page-builder-so-ddb/__tests__/__api__/setupAfterEnv.js index f71ad03a47b..9a30daa9513 100644 --- a/packages/api-page-builder-so-ddb/__tests__/__api__/setupAfterEnv.js +++ b/packages/api-page-builder-so-ddb/__tests__/__api__/setupAfterEnv.js @@ -10,19 +10,27 @@ jestDynalite.setup(path.resolve(__dirname, "../../")); */ beforeAll(async () => { await jestDynalite.startDb(); - //await __beforeAll(); + if (typeof __beforeAll === "function") { + await __beforeAll(); + } }); beforeEach(async () => { await jestDynalite.createTables(); - //await __beforeEach(); + if (typeof __beforeEach === "function") { + await __beforeEach(); + } }); afterEach(async () => { await jestDynalite.deleteTables(); - //await __afterEach(); + if (typeof __afterEach === "function") { + await __afterEach(); + } }); afterAll(async () => { await jestDynalite.stopDb(); - //await __afterAll(); + if (typeof __afterAll === "function") { + await __afterAll(); + } }); diff --git a/packages/api-page-builder-so-ddb/jest-dynalite-config.js b/packages/api-page-builder-so-ddb/jest-dynalite-config.js index 41ef7ebfb76..6d5840539c8 100644 --- a/packages/api-page-builder-so-ddb/jest-dynalite-config.js +++ b/packages/api-page-builder-so-ddb/jest-dynalite-config.js @@ -1,35 +1,3 @@ -module.exports = { - tables: [ - { - TableName: process.env.DB_TABLE, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" }, - { AttributeName: "GSI1_PK", AttributeType: "S" }, - { AttributeName: "GSI1_SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 }, - GlobalSecondaryIndexes: [ - { - IndexName: "GSI1", - KeySchema: [ - { AttributeName: "GSI1_PK", KeyType: "HASH" }, - { AttributeName: "GSI1_SK", KeyType: "RANGE" } - ], - Projection: { - ProjectionType: "ALL" - }, - ProvisionedThroughput: { - ReadCapacityUnits: 1, - WriteCapacityUnits: 1 - } - } - ] - } - ], - basePort: 8000 -}; +const { createDynaliteTables } = require("../../jest.config.base"); + +module.exports = createDynaliteTables(); diff --git a/packages/api-page-builder-so-ddb/src/definitions/table.ts b/packages/api-page-builder-so-ddb/src/definitions/table.ts index 22ea2c42c76..206ac640f67 100644 --- a/packages/api-page-builder-so-ddb/src/definitions/table.ts +++ b/packages/api-page-builder-so-ddb/src/definitions/table.ts @@ -18,7 +18,7 @@ export interface Params { export const defineTable = (params: Params): Table => { const { context, indexes } = params; return new Table({ - name: process.env.DB_TABLE_PAGE_BUILDER || getTable(context), + name: process.env.DB_TABLE || getTable(context), partitionKey: "PK", sortKey: "SK", DocumentClient: getDocumentClient(context), diff --git a/packages/api-page-builder/__tests__/graphql/categories.test.ts b/packages/api-page-builder/__tests__/graphql/categories.test.ts index 75ca510ea8c..138b124fc6f 100644 --- a/packages/api-page-builder/__tests__/graphql/categories.test.ts +++ b/packages/api-page-builder/__tests__/graphql/categories.test.ts @@ -1,6 +1,8 @@ import useGqlHandler from "./useGqlHandler"; import { defaultIdentity } from "../tenancySecurity"; +jest.setTimeout(100000); + describe("Categories CRUD Test", () => { const { createCategory, diff --git a/packages/api-page-builder/__tests__/graphql/categoriesSecurity.test.ts b/packages/api-page-builder/__tests__/graphql/categoriesSecurity.test.ts index 913f67f1f5b..f6b77fed2f9 100644 --- a/packages/api-page-builder/__tests__/graphql/categoriesSecurity.test.ts +++ b/packages/api-page-builder/__tests__/graphql/categoriesSecurity.test.ts @@ -23,6 +23,8 @@ const NOT_AUTHORIZED_RESPONSE = operation => ({ } }); +jest.setTimeout(100000); + describe("Categories Security Test", () => { const { createCategory } = useGqlHandler({ permissions: [{ name: "content.i18n" }, { name: "pb.*" }], diff --git a/packages/api-page-builder/__tests__/graphql/install.test.ts b/packages/api-page-builder/__tests__/graphql/install.test.ts index aa1c5e4cd9f..50948b3dd50 100644 --- a/packages/api-page-builder/__tests__/graphql/install.test.ts +++ b/packages/api-page-builder/__tests__/graphql/install.test.ts @@ -1,6 +1,8 @@ import useGqlHandler from "./useGqlHandler"; import { defaultIdentity } from "../tenancySecurity"; +jest.setTimeout(100000); + describe("Install Test", () => { const handler = useGqlHandler(); diff --git a/packages/api-page-builder/__tests__/graphql/listPageTags.test.ts b/packages/api-page-builder/__tests__/graphql/listPageTags.test.ts index 9afd364c3c6..d01d62af4b0 100644 --- a/packages/api-page-builder/__tests__/graphql/listPageTags.test.ts +++ b/packages/api-page-builder/__tests__/graphql/listPageTags.test.ts @@ -1,6 +1,6 @@ import useGqlHandler from "./useGqlHandler"; -jest.setTimeout(15000); +jest.setTimeout(100000); describe("listing tags used by pages", () => { const { createCategory, createPage, listPages, updatePage, listPageTags, until } = diff --git a/packages/api-page-builder/__tests__/graphql/menus.test.ts b/packages/api-page-builder/__tests__/graphql/menus.test.ts index 63b6ac044fb..e9c8a982b15 100644 --- a/packages/api-page-builder/__tests__/graphql/menus.test.ts +++ b/packages/api-page-builder/__tests__/graphql/menus.test.ts @@ -1,6 +1,8 @@ import useGqlHandler from "./useGqlHandler"; import { defaultIdentity } from "../tenancySecurity"; +jest.setTimeout(100000); + describe("Menus Test", () => { const { createMenu, deleteMenu, listMenus, getMenu, updateMenu } = useGqlHandler(); diff --git a/packages/api-page-builder/__tests__/graphql/menusSecurity.test.ts b/packages/api-page-builder/__tests__/graphql/menusSecurity.test.ts index 2d3c6594d58..f68b923f7ef 100644 --- a/packages/api-page-builder/__tests__/graphql/menusSecurity.test.ts +++ b/packages/api-page-builder/__tests__/graphql/menusSecurity.test.ts @@ -29,6 +29,8 @@ const createBMenus = async () => { await handler.createMenu({ data: new Mock("list-menus-4-") }); }; +jest.setTimeout(100000); + describe("Menus Security Test", () => { const insufficientPermissions = [ [[], null], diff --git a/packages/api-page-builder/__tests__/graphql/pageElements.test.ts b/packages/api-page-builder/__tests__/graphql/pageElements.test.ts index df8654ff2c6..70145062774 100644 --- a/packages/api-page-builder/__tests__/graphql/pageElements.test.ts +++ b/packages/api-page-builder/__tests__/graphql/pageElements.test.ts @@ -1,6 +1,8 @@ import useGqlHandler from "./useGqlHandler"; import { defaultIdentity } from "../tenancySecurity"; +jest.setTimeout(100000); + describe("PageElements Test", () => { const { createPageElement, diff --git a/packages/api-page-builder/__tests__/graphql/pageSettings.test.ts b/packages/api-page-builder/__tests__/graphql/pageSettings.test.ts index 51430f9ca44..e0f3fc1bcdb 100644 --- a/packages/api-page-builder/__tests__/graphql/pageSettings.test.ts +++ b/packages/api-page-builder/__tests__/graphql/pageSettings.test.ts @@ -1,5 +1,7 @@ import useGqlHandler from "./useGqlHandler"; +jest.setTimeout(100000); + describe("Page Settings Test", () => { const { createCategory, createPage, getPage, updatePage } = useGqlHandler(); diff --git a/packages/api-page-builder/__tests__/graphql/pages.deletion.test.ts b/packages/api-page-builder/__tests__/graphql/pages.deletion.test.ts index 82e44c7581b..516b63d66ea 100644 --- a/packages/api-page-builder/__tests__/graphql/pages.deletion.test.ts +++ b/packages/api-page-builder/__tests__/graphql/pages.deletion.test.ts @@ -1,7 +1,7 @@ import useGqlHandler from "./useGqlHandler"; import { waitPage } from "./utils/waitPage"; -jest.setTimeout(25000); +jest.setTimeout(100000); describe("deleting pages", () => { const handler = useGqlHandler(); diff --git a/packages/api-page-builder/__tests__/graphql/pages.test.ts b/packages/api-page-builder/__tests__/graphql/pages.test.ts index 60869e73261..508a4a5c4fc 100644 --- a/packages/api-page-builder/__tests__/graphql/pages.test.ts +++ b/packages/api-page-builder/__tests__/graphql/pages.test.ts @@ -2,7 +2,7 @@ import useGqlHandler from "./useGqlHandler"; import { waitPage } from "./utils/waitPage"; import { defaultIdentity } from "../tenancySecurity"; -jest.setTimeout(25000); +jest.setTimeout(100000); describe("CRUD Test", () => { const handler = useGqlHandler(); diff --git a/packages/api-page-builder/__tests__/graphql/pages.visibility.test.ts b/packages/api-page-builder/__tests__/graphql/pages.visibility.test.ts index 0ee9d5f42c3..1108249bbdb 100644 --- a/packages/api-page-builder/__tests__/graphql/pages.visibility.test.ts +++ b/packages/api-page-builder/__tests__/graphql/pages.visibility.test.ts @@ -1,5 +1,7 @@ import useGqlHandler from "./useGqlHandler"; +jest.setTimeout(100000); + describe("page visibility test", () => { const { createCategory, diff --git a/packages/api-page-builder/__tests__/graphql/pagesGetPublished.test.ts b/packages/api-page-builder/__tests__/graphql/pagesGetPublished.test.ts index 405b870b6fb..3d359825c3a 100644 --- a/packages/api-page-builder/__tests__/graphql/pagesGetPublished.test.ts +++ b/packages/api-page-builder/__tests__/graphql/pagesGetPublished.test.ts @@ -2,7 +2,7 @@ import useGqlHandler from "./useGqlHandler"; import { waitPage } from "./utils/waitPage"; import { Page } from "~/types"; -jest.setTimeout(30000); +jest.setTimeout(100000); describe("getting published pages", () => { const handler = useGqlHandler(); @@ -72,9 +72,7 @@ describe("getting published pages", () => { return published && data[0].title === "page-c"; }, { - name: "list published pages after update and publish", - tries: 30, - wait: 500 + name: "list published pages after update and publish" } ); diff --git a/packages/api-page-builder/__tests__/graphql/pagesListingLatest.test.ts b/packages/api-page-builder/__tests__/graphql/pagesListingLatest.test.ts index 875c51a72ad..d8547ee7065 100644 --- a/packages/api-page-builder/__tests__/graphql/pagesListingLatest.test.ts +++ b/packages/api-page-builder/__tests__/graphql/pagesListingLatest.test.ts @@ -3,6 +3,8 @@ import { identityB } from "./mocks"; import { Page } from "~/types"; import { waitPage } from "./utils/waitPage"; +jest.setTimeout(100000); + describe("listing latest pages", () => { const handler = useGqlHandler(); @@ -77,9 +79,7 @@ describe("listing latest pages", () => { ); }, { - name: "list pages in create initial data", - tries: 20, - wait: 500 + name: "list pages in create initial data" } ); @@ -100,9 +100,7 @@ describe("listing latest pages", () => { }), ([res]) => res.data.pageBuilder.listPages.data[4].title === "page-c", { - name: "list pages createdOn ASC", - wait: 400, - tries: 20 + name: "list pages createdOn ASC" } ); @@ -186,9 +184,7 @@ describe("listing latest pages", () => { return data[0].title === "page-a" && data[9].title === "page-Z"; }, { - name: "after creating new pages with uppercase titles", - wait: 400, - tries: 20 + name: "after creating new pages with uppercase titles" } ); @@ -737,9 +733,7 @@ describe("listing latest pages", () => { return res.data.pageBuilder.listPages.data.length === initialData.pages.length; }, { - name: "filtering by tags - list pages after creating initial data", - wait: 500, - tries: 30 + name: "filtering by tags - list pages after creating initial data" } ); diff --git a/packages/api-page-builder/__tests__/graphql/pagesListingPublished.test.ts b/packages/api-page-builder/__tests__/graphql/pagesListingPublished.test.ts index e8a37206c79..e841560142b 100644 --- a/packages/api-page-builder/__tests__/graphql/pagesListingPublished.test.ts +++ b/packages/api-page-builder/__tests__/graphql/pagesListingPublished.test.ts @@ -1,6 +1,6 @@ import useGqlHandler from "./useGqlHandler"; -jest.setTimeout(15000); +jest.setTimeout(100000); describe("listing published pages", () => { const { createCategory, createPage, publishPage, listPublishedPages, updatePage, until } = diff --git a/packages/api-page-builder/__tests__/graphql/pagesSecurity.test.ts b/packages/api-page-builder/__tests__/graphql/pagesSecurity.test.ts index 94261a49972..d0c59eb2051 100644 --- a/packages/api-page-builder/__tests__/graphql/pagesSecurity.test.ts +++ b/packages/api-page-builder/__tests__/graphql/pagesSecurity.test.ts @@ -2,13 +2,13 @@ import useGqlHandler from "./useGqlHandler"; import { identityA, identityB, NOT_AUTHORIZED_RESPONSE } from "./mocks"; import mdbid from "mdbid"; -jest.setTimeout(15000); - const defaultHandler = useGqlHandler({ permissions: [{ name: "content.i18n" }, { name: "pb.*" }], identity: identityA }); +jest.setTimeout(100000); + describe("Pages Security Test", () => { const { createCategory, until } = useGqlHandler(); diff --git a/packages/api-page-builder/__tests__/graphql/publicMenu.test.ts b/packages/api-page-builder/__tests__/graphql/publicMenu.test.ts index 249e5070baf..1fce8717aa5 100644 --- a/packages/api-page-builder/__tests__/graphql/publicMenu.test.ts +++ b/packages/api-page-builder/__tests__/graphql/publicMenu.test.ts @@ -1,6 +1,6 @@ import useGqlHandler from "./useGqlHandler"; -jest.setTimeout(15000); +jest.setTimeout(100000); describe("Prepared Menus Test", () => { const { diff --git a/packages/api-page-builder/__tests__/graphql/publishingWorkflow.test.ts b/packages/api-page-builder/__tests__/graphql/publishingWorkflow.test.ts index c5750f1499f..4841f2fb3b8 100644 --- a/packages/api-page-builder/__tests__/graphql/publishingWorkflow.test.ts +++ b/packages/api-page-builder/__tests__/graphql/publishingWorkflow.test.ts @@ -3,7 +3,7 @@ import { identityA, identityB, NOT_AUTHORIZED_RESPONSE } from "./mocks"; import { SecurityIdentity } from "@webiny/api-security"; import { Page } from "~/types"; -jest.setTimeout(25000); +jest.setTimeout(100000); describe("publishing workflow", () => { const { diff --git a/packages/api-page-builder/__tests__/graphql/settings.test.ts b/packages/api-page-builder/__tests__/graphql/settings.test.ts index 80d7891be63..6fdf16e9f8f 100644 --- a/packages/api-page-builder/__tests__/graphql/settings.test.ts +++ b/packages/api-page-builder/__tests__/graphql/settings.test.ts @@ -1,7 +1,7 @@ import useGqlHandler from "./useGqlHandler"; import useHandler from "./../updateSettings/useHandler"; -jest.setTimeout(15000); +jest.setTimeout(100000); describe("Settings Test", () => { const { diff --git a/packages/api-page-builder/__tests__/graphql/simple.pages.test.ts b/packages/api-page-builder/__tests__/graphql/simple.pages.test.ts index e41ce3b5f24..6b15701d6a1 100644 --- a/packages/api-page-builder/__tests__/graphql/simple.pages.test.ts +++ b/packages/api-page-builder/__tests__/graphql/simple.pages.test.ts @@ -5,8 +5,6 @@ import { identityB } from "./mocks"; const sort: string[] = ["createdOn_DESC"]; -jest.setTimeout(50000); - const content = [ { type: "heading", diff --git a/packages/api-page-builder/__tests__/graphql/useGqlHandler.ts b/packages/api-page-builder/__tests__/graphql/useGqlHandler.ts index d0e9e8374ca..bc8283b2ae0 100644 --- a/packages/api-page-builder/__tests__/graphql/useGqlHandler.ts +++ b/packages/api-page-builder/__tests__/graphql/useGqlHandler.ts @@ -43,7 +43,7 @@ import { OEMBED_DATA } from "./graphql/pages"; -import { SecurityIdentity } from "@webiny/api-security"; +import { SecurityIdentity } from "@webiny/api-security/types"; import { CREATE_CATEGORY, DELETE_CATEGORY, @@ -55,7 +55,7 @@ import { import { GET_SETTINGS, GET_DEFAULT_SETTINGS, UPDATE_SETTINGS } from "./graphql/settings"; import path from "path"; import fs from "fs"; -import { UntilOptions } from "@webiny/project-utils/testing/helpers/until"; +import { until } from "@webiny/project-utils/testing/helpers/until"; import { createTenancyAndSecurity } from "../tenancySecurity"; interface Params { @@ -149,48 +149,17 @@ export default ({ permissions, identity, plugins }: Params = {}) => { invoke, // Helpers. sleep, - until: async (execute, until, options: UntilOptions = {}) => { - const { name = "NO_NAME", tries = 5, wait = 300 } = options; - - let result; - let triesCount = 0; - - while (true) { - result = await execute(); - - let done; - try { - done = await until(result); - } catch {} - - if (done) { - return result; - } - - triesCount++; - if (triesCount === tries) { - break; - } - - // Wait. - await new Promise((resolve: any) => { - setTimeout(() => resolve(), wait); - }); - } - - throw new Error( - `[${name}] Tried ${tries} times but failed. Last result that was received: ${JSON.stringify( - result, - null, - 2 - )}` - ); - }, + until, // GraphQL queries and mutations. // Install. - async install(variables) { - return invoke({ body: { query: INSTALL, variables } }); + async install(variables = { insertDemoData: false, name: "Test" }) { + return invoke({ + body: { + query: INSTALL, + variables + } + }); }, async isInstalled(variables = {}) { diff --git a/packages/api-page-builder/__tests__/graphql/versioningAndPublishingPages.test.ts b/packages/api-page-builder/__tests__/graphql/versioningAndPublishingPages.test.ts index 4477d74f596..edb2beb6006 100644 --- a/packages/api-page-builder/__tests__/graphql/versioningAndPublishingPages.test.ts +++ b/packages/api-page-builder/__tests__/graphql/versioningAndPublishingPages.test.ts @@ -1,6 +1,6 @@ import useGqlHandler from "./useGqlHandler"; -jest.setTimeout(30000); +jest.setTimeout(100000); describe("versioning and publishing pages", () => { const { diff --git a/packages/api-page-builder/src/graphql/graphql/install.gql.ts b/packages/api-page-builder/src/graphql/graphql/install.gql.ts index 429f23389c9..a539259bbc8 100644 --- a/packages/api-page-builder/src/graphql/graphql/install.gql.ts +++ b/packages/api-page-builder/src/graphql/graphql/install.gql.ts @@ -7,6 +7,7 @@ const plugin: GraphQLSchemaPlugin = { schema: { typeDefs: /* GraphQL */ ` input PbInstallInput { + insertDemoData: Boolean websiteUrl: String name: String! } @@ -50,12 +51,10 @@ const plugin: GraphQLSchemaPlugin = { try { await context.pageBuilder.system.install({ name: args.data.name, - insertDemoData: true + insertDemoData: "insertDemoData" in args ? args.insertDemoData : true }); return new Response(true); } catch (e) { - console.log(e); - console.log(JSON.stringify(e.stack, null, 2)); return new ErrorResponse(e); } }, diff --git a/packages/api-security-so-ddb/__tests__/__api__/setupAfterEnv.js b/packages/api-security-so-ddb/__tests__/__api__/setupAfterEnv.js index 60ede6c1efc..9a30daa9513 100644 --- a/packages/api-security-so-ddb/__tests__/__api__/setupAfterEnv.js +++ b/packages/api-security-so-ddb/__tests__/__api__/setupAfterEnv.js @@ -10,15 +10,27 @@ jestDynalite.setup(path.resolve(__dirname, "../../")); */ beforeAll(async () => { await jestDynalite.startDb(); + if (typeof __beforeAll === "function") { + await __beforeAll(); + } }); beforeEach(async () => { await jestDynalite.createTables(); + if (typeof __beforeEach === "function") { + await __beforeEach(); + } }); afterEach(async () => { await jestDynalite.deleteTables(); + if (typeof __afterEach === "function") { + await __afterEach(); + } }); afterAll(async () => { await jestDynalite.stopDb(); + if (typeof __afterAll === "function") { + await __afterAll(); + } }); diff --git a/packages/api-security-so-ddb/jest-dynalite-config.js b/packages/api-security-so-ddb/jest-dynalite-config.js index 41ef7ebfb76..6d5840539c8 100644 --- a/packages/api-security-so-ddb/jest-dynalite-config.js +++ b/packages/api-security-so-ddb/jest-dynalite-config.js @@ -1,35 +1,3 @@ -module.exports = { - tables: [ - { - TableName: process.env.DB_TABLE, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" }, - { AttributeName: "GSI1_PK", AttributeType: "S" }, - { AttributeName: "GSI1_SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 }, - GlobalSecondaryIndexes: [ - { - IndexName: "GSI1", - KeySchema: [ - { AttributeName: "GSI1_PK", KeyType: "HASH" }, - { AttributeName: "GSI1_SK", KeyType: "RANGE" } - ], - Projection: { - ProjectionType: "ALL" - }, - ProvisionedThroughput: { - ReadCapacityUnits: 1, - WriteCapacityUnits: 1 - } - } - ] - } - ], - basePort: 8000 -}; +const { createDynaliteTables } = require("../../jest.config.base"); + +module.exports = createDynaliteTables(); diff --git a/packages/api-security-so-ddb/src/definitions/table.ts b/packages/api-security-so-ddb/src/definitions/table.ts index 7f9a3b43436..0979630c5ba 100644 --- a/packages/api-security-so-ddb/src/definitions/table.ts +++ b/packages/api-security-so-ddb/src/definitions/table.ts @@ -8,7 +8,7 @@ export interface Params { export const createTable = ({ table, documentClient }: Params) => { return new Table({ - name: table || process.env.DB_TABLE_SECURITY || process.env.DB_TABLE, + name: table || process.env.DB_TABLE, partitionKey: "PK", sortKey: "SK", DocumentClient: documentClient, diff --git a/packages/api-security/src/types.ts b/packages/api-security/src/types.ts index e2c0d74a7de..cd519f47871 100644 --- a/packages/api-security/src/types.ts +++ b/packages/api-security/src/types.ts @@ -266,7 +266,7 @@ export interface ApiKey { permissions: SecurityPermission[]; createdBy: CreatedBy; createdOn: string; - webinyVersion: string; + webinyVersion?: string; } export interface ApiKeyInput { diff --git a/packages/api-tenancy-so-ddb/__tests__/__api__/setupAfterEnv.js b/packages/api-tenancy-so-ddb/__tests__/__api__/setupAfterEnv.js index 60ede6c1efc..9a30daa9513 100644 --- a/packages/api-tenancy-so-ddb/__tests__/__api__/setupAfterEnv.js +++ b/packages/api-tenancy-so-ddb/__tests__/__api__/setupAfterEnv.js @@ -10,15 +10,27 @@ jestDynalite.setup(path.resolve(__dirname, "../../")); */ beforeAll(async () => { await jestDynalite.startDb(); + if (typeof __beforeAll === "function") { + await __beforeAll(); + } }); beforeEach(async () => { await jestDynalite.createTables(); + if (typeof __beforeEach === "function") { + await __beforeEach(); + } }); afterEach(async () => { await jestDynalite.deleteTables(); + if (typeof __afterEach === "function") { + await __afterEach(); + } }); afterAll(async () => { await jestDynalite.stopDb(); + if (typeof __afterAll === "function") { + await __afterAll(); + } }); diff --git a/packages/api-tenancy-so-ddb/jest-dynalite-config.js b/packages/api-tenancy-so-ddb/jest-dynalite-config.js index 41ef7ebfb76..6d5840539c8 100644 --- a/packages/api-tenancy-so-ddb/jest-dynalite-config.js +++ b/packages/api-tenancy-so-ddb/jest-dynalite-config.js @@ -1,35 +1,3 @@ -module.exports = { - tables: [ - { - TableName: process.env.DB_TABLE, - KeySchema: [ - { AttributeName: "PK", KeyType: "HASH" }, - { AttributeName: "SK", KeyType: "RANGE" } - ], - AttributeDefinitions: [ - { AttributeName: "PK", AttributeType: "S" }, - { AttributeName: "SK", AttributeType: "S" }, - { AttributeName: "GSI1_PK", AttributeType: "S" }, - { AttributeName: "GSI1_SK", AttributeType: "S" } - ], - ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 }, - GlobalSecondaryIndexes: [ - { - IndexName: "GSI1", - KeySchema: [ - { AttributeName: "GSI1_PK", KeyType: "HASH" }, - { AttributeName: "GSI1_SK", KeyType: "RANGE" } - ], - Projection: { - ProjectionType: "ALL" - }, - ProvisionedThroughput: { - ReadCapacityUnits: 1, - WriteCapacityUnits: 1 - } - } - ] - } - ], - basePort: 8000 -}; +const { createDynaliteTables } = require("../../jest.config.base"); + +module.exports = createDynaliteTables(); diff --git a/packages/api-tenancy/src/types.ts b/packages/api-tenancy/src/types.ts index fd8552176e4..f2137a48bda 100644 --- a/packages/api-tenancy/src/types.ts +++ b/packages/api-tenancy/src/types.ts @@ -8,7 +8,7 @@ export interface Tenant { name: string; description?: string; parent?: string | null; - webinyVersion: string; + webinyVersion?: string; } export interface Tenancy { diff --git a/packages/project-utils/testing/helpers/elasticIndexManager.js b/packages/project-utils/testing/helpers/elasticIndexManager.js new file mode 100644 index 00000000000..cf0d50d9d7b --- /dev/null +++ b/packages/project-utils/testing/helpers/elasticIndexManager.js @@ -0,0 +1,22 @@ +module.exports.elasticIndexManager = (global, elasticsearchClient) => { + const prefixes = []; + + const clearEsIndices = async () => { + if (!prefixes.length) { + return; + } + + return elasticsearchClient.indices.delete({ + index: prefixes.map(p => `${p}-*`).join(",") + }); + }; + + global.__beforeEach = () => { + const prefix = `${Date.now()}-`; + prefixes.push(prefix); + process.env.ELASTIC_SEARCH_INDEX_PREFIX = prefix; + }; + + global.__beforeAll = clearEsIndices; + global.__afterAll = clearEsIndices; +}; diff --git a/packages/project-utils/testing/helpers/until.ts b/packages/project-utils/testing/helpers/until.ts index dc507f24a8d..0f840a9f4d0 100644 --- a/packages/project-utils/testing/helpers/until.ts +++ b/packages/project-utils/testing/helpers/until.ts @@ -5,7 +5,7 @@ export interface UntilOptions { } export const until = async (execute, until, options: UntilOptions = {}) => { - const { name = "NO_NAME", tries = 5, wait = 300 } = options; + const { name = "NO_NAME", tries = 10, wait = 1000 } = options; let result; let triesCount = 0; @@ -34,10 +34,6 @@ export const until = async (execute, until, options: UntilOptions = {}) => { } throw new Error( - `[${name}] Tried ${tries} times but failed. Last result that was received: ${JSON.stringify( - result, - null, - 2 - )}` + `[${name}] Tried ${tries} times but failed.` ); };