From 35dba2e1cb8713f08ff0e736c6623642cd599356 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 14 Sep 2021 17:14:44 +0100 Subject: [PATCH] Fixing test cases after removing worker-farm. --- .../src/automations/tests/automation.spec.js | 38 ++----------------- packages/server/src/automations/utils.js | 13 ------- 2 files changed, 3 insertions(+), 48 deletions(-) diff --git a/packages/server/src/automations/tests/automation.spec.js b/packages/server/src/automations/tests/automation.spec.js index 689ee4ab76..e1b82e4327 100644 --- a/packages/server/src/automations/tests/automation.spec.js +++ b/packages/server/src/automations/tests/automation.spec.js @@ -1,20 +1,6 @@ jest.mock("../../utilities/usageQuota") jest.mock("../thread") jest.spyOn(global.console, "error") -jest.mock("worker-farm", () => { - return () => { - const value = jest - .fn() - .mockReturnValueOnce(undefined) - .mockReturnValueOnce("Error") - return (input, callback) => { - workerJob = input - if (callback) { - callback(value()) - } - } - } -}) require("../../environment") const automation = require("../index") @@ -27,8 +13,6 @@ const { makePartial } = require("../../tests/utilities") const { cleanInputValues } = require("../automationUtils") const setup = require("./utilities") -let workerJob - usageQuota.getAPIKey.mockReturnValue({ apiKey: "test" }) describe("Run through some parts of the automations system", () => { @@ -44,28 +28,12 @@ describe("Run through some parts of the automations system", () => { it("should be able to init in builder", async () => { await triggers.externalTrigger(basicAutomation(), { a: 1 }) await wait(100) - expect(workerJob).toBeUndefined() expect(thread).toHaveBeenCalled() }) it("should be able to init in prod", async () => { - await setup.runInProd(async () => { - await triggers.externalTrigger(basicAutomation(), { a: 1 }) - await wait(100) - // haven't added a mock implementation so getAPIKey of usageQuota just returns undefined - expect(usageQuota.update).toHaveBeenCalledWith("test", "automationRuns", 1) - expect(workerJob).toBeDefined() - }) - }) - - it("try error scenario", async () => { - await setup.runInProd(async () => { - // the second call will throw an error - const response = await triggers.externalTrigger(basicAutomation(), {a: 1}, {getResponses: true}) - await wait(100) - expect(console.error).toHaveBeenCalled() - expect(response.err).toBeDefined() - }) + await triggers.externalTrigger(basicAutomation(), { a: 1 }) + await wait(100) }) it("should check coercion", async () => { @@ -89,7 +57,7 @@ describe("Run through some parts of the automations system", () => { } } } - }), expect.any(Function)) + })) }) it("should be able to clean inputs with the utilities", () => { diff --git a/packages/server/src/automations/utils.js b/packages/server/src/automations/utils.js index f9de64de59..4bef91a153 100644 --- a/packages/server/src/automations/utils.js +++ b/packages/server/src/automations/utils.js @@ -1,5 +1,3 @@ -const env = require("../environment") -const { getAPIKey, update, Properties } = require("../utilities/usageQuota") const runner = require("./thread") const { definitions } = require("./triggerInfo") const webhooks = require("../api/controllers/webhook") @@ -12,19 +10,8 @@ const { MetadataTypes } = require("../constants") const WH_STEP_ID = definitions.WEBHOOK.stepId const CRON_STEP_ID = definitions.CRON.stepId -async function updateQuota(automation) { - const appId = automation.appId - const apiObj = await getAPIKey(appId) - // this will fail, causing automation to escape if limits reached - await update(apiObj.apiKey, Properties.AUTOMATION, 1) - return apiObj.apiKey -} - exports.processEvent = async job => { try { - if (env.USE_QUOTAS) { - job.data.automation.apiKey = await updateQuota(job.data.automation) - } // need to actually await these so that an error can be captured properly return await runner(job) } catch (err) {