From 7027abeaa2a84e06dbc8a1044445eb8a641194fe Mon Sep 17 00:00:00 2001 From: adrinr Date: Thu, 26 Jan 2023 17:18:49 +0000 Subject: [PATCH] Fix issues with parallel tests and self/cloud modes --- packages/backend-core/src/objectStore/objectStore.ts | 10 +++++----- packages/server/__mocks__/aws-sdk.ts | 2 +- packages/server/src/api/routes/tests/static.spec.js | 1 + packages/server/src/api/routes/tests/webhook.spec.js | 1 + .../server/src/automations/tests/executeQuery.spec.js | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/backend-core/src/objectStore/objectStore.ts b/packages/backend-core/src/objectStore/objectStore.ts index f601d40a37..059e1b228d 100644 --- a/packages/backend-core/src/objectStore/objectStore.ts +++ b/packages/backend-core/src/objectStore/objectStore.ts @@ -361,8 +361,8 @@ export const deleteFolder = async ( Prefix: folder, } - let response: any = await client.listObjects(listParams).promise() - if (response.Contents.length === 0) { + const existingObjectsResponse = await client.listObjects(listParams).promise() + if (existingObjectsResponse.Contents?.length === 0) { return } const deleteParams: any = { @@ -372,13 +372,13 @@ export const deleteFolder = async ( }, } - response.Contents.forEach((content: any) => { + existingObjectsResponse.Contents?.forEach((content: any) => { deleteParams.Delete.Objects.push({ Key: content.Key }) }) - response = await client.deleteObjects(deleteParams).promise() + const deleteResponse = await client.deleteObjects(deleteParams).promise() // can only empty 1000 items at once - if (response.Deleted.length === 1000) { + if (deleteResponse.Deleted?.length === 1000) { return deleteFolder(bucketName, folder) } } diff --git a/packages/server/__mocks__/aws-sdk.ts b/packages/server/__mocks__/aws-sdk.ts index 2efbd303f2..8a66f0e213 100644 --- a/packages/server/__mocks__/aws-sdk.ts +++ b/packages/server/__mocks__/aws-sdk.ts @@ -34,7 +34,7 @@ module AwsMock { // @ts-ignore this.listObjects = jest.fn( response({ - Contents: {}, + Contents: [], }) ) diff --git a/packages/server/src/api/routes/tests/static.spec.js b/packages/server/src/api/routes/tests/static.spec.js index cbfe167100..6e0ffd2319 100644 --- a/packages/server/src/api/routes/tests/static.spec.js +++ b/packages/server/src/api/routes/tests/static.spec.js @@ -9,6 +9,7 @@ describe("/static", () => { afterAll(setup.afterAll) beforeEach(async () => { + config.modeSelf() app = await config.init() }) diff --git a/packages/server/src/api/routes/tests/webhook.spec.js b/packages/server/src/api/routes/tests/webhook.spec.js index 5bdc2ced96..2c619e7906 100644 --- a/packages/server/src/api/routes/tests/webhook.spec.js +++ b/packages/server/src/api/routes/tests/webhook.spec.js @@ -10,6 +10,7 @@ describe("/webhooks", () => { afterAll(setup.afterAll) beforeEach(async () => { + config.modeSelf() await config.init() const autoConfig = basicAutomation() autoConfig.definition.trigger = { diff --git a/packages/server/src/automations/tests/executeQuery.spec.js b/packages/server/src/automations/tests/executeQuery.spec.js index c9b7629d09..2136baa99e 100644 --- a/packages/server/src/automations/tests/executeQuery.spec.js +++ b/packages/server/src/automations/tests/executeQuery.spec.js @@ -41,7 +41,7 @@ describe("test the execute query action", () => { query: { queryId: "wrong_id" } } ) - expect(res.response).toEqual('{"status":404,"name":"not_found","message":"missing","reason":"missing"}') + expect(res.response).toEqual('Error: missing') expect(res.success).toEqual(false) })