1
0
Fork 0
mirror of synced 2024-07-01 12:30:41 +12:00

Fixing test cases after removing worker-farm.

This commit is contained in:
mike12345567 2021-09-14 17:14:44 +01:00
parent df1555185d
commit d2fce749c6
2 changed files with 3 additions and 48 deletions

View file

@ -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", () => {

View file

@ -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) {