Add test
This commit is contained in:
parent
cbf0cf76d3
commit
0667dd9d30
|
@ -141,7 +141,7 @@ class InMemoryQueue implements Partial<Queue> {
|
||||||
} else {
|
} else {
|
||||||
pushMessage()
|
pushMessage()
|
||||||
}
|
}
|
||||||
return {} as any
|
return { id: jobId } as any
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
import tk from "timekeeper"
|
||||||
|
import "../../environment"
|
||||||
|
import * as automations from "../index"
|
||||||
|
import * as setup from "./utilities"
|
||||||
|
import { basicCronAutomation } from "../../tests/utilities/structures"
|
||||||
|
|
||||||
|
const initialTime = Date.now()
|
||||||
|
tk.freeze(initialTime)
|
||||||
|
|
||||||
|
const oneMinuteInMs = 60 * 1000
|
||||||
|
|
||||||
|
describe("cron automations", () => {
|
||||||
|
let config = setup.getConfig()
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await automations.init()
|
||||||
|
await config.init()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await automations.shutdown()
|
||||||
|
setup.afterAll()
|
||||||
|
})
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
tk.freeze(initialTime)
|
||||||
|
})
|
||||||
|
|
||||||
|
async function travel(ms: number) {
|
||||||
|
tk.travel(Date.now() + ms)
|
||||||
|
}
|
||||||
|
|
||||||
|
it("should initialise the automation timestamp", async () => {
|
||||||
|
const automation = basicCronAutomation(config.appId!, "* * * * *")
|
||||||
|
await config.api.automation.post(automation)
|
||||||
|
await travel(oneMinuteInMs)
|
||||||
|
await config.publish()
|
||||||
|
|
||||||
|
const automationLogs = await config.getAutomationLogs()
|
||||||
|
expect(automationLogs.data).toHaveLength(1)
|
||||||
|
expect(automationLogs.data).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
trigger: expect.objectContaining({
|
||||||
|
outputs: { timestamp: initialTime + oneMinuteInMs },
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
|
@ -245,6 +245,38 @@ export function basicAutomation(appId?: string): Automation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function basicCronAutomation(appId: string, cron: string): Automation {
|
||||||
|
const automation: Automation = {
|
||||||
|
name: `Automation ${generator.guid()}`,
|
||||||
|
definition: {
|
||||||
|
trigger: {
|
||||||
|
stepId: AutomationTriggerStepId.CRON,
|
||||||
|
name: "test",
|
||||||
|
tagline: "test",
|
||||||
|
icon: "test",
|
||||||
|
description: "test",
|
||||||
|
type: AutomationStepType.TRIGGER,
|
||||||
|
id: "test",
|
||||||
|
inputs: {
|
||||||
|
cron,
|
||||||
|
},
|
||||||
|
schema: {
|
||||||
|
inputs: {
|
||||||
|
properties: {},
|
||||||
|
},
|
||||||
|
outputs: {
|
||||||
|
properties: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
steps: [],
|
||||||
|
},
|
||||||
|
type: "automation",
|
||||||
|
appId,
|
||||||
|
}
|
||||||
|
return automation
|
||||||
|
}
|
||||||
|
|
||||||
export function serverLogAutomation(appId?: string): Automation {
|
export function serverLogAutomation(appId?: string): Automation {
|
||||||
return {
|
return {
|
||||||
name: "My Automation",
|
name: "My Automation",
|
||||||
|
|
Loading…
Reference in New Issue