From 6ad9ebe63c5aee257a778d59ccdcbb14d25e77e1 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 5 Feb 2025 15:24:54 +0000 Subject: [PATCH] Add failing test. --- .../automations/tests/triggers/cron.spec.ts | 19 ++++++++++++- .../src/tests/utilities/api/application.ts | 28 +++++++++++++------ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/packages/server/src/automations/tests/triggers/cron.spec.ts b/packages/server/src/automations/tests/triggers/cron.spec.ts index c377554df5..956f054ca4 100644 --- a/packages/server/src/automations/tests/triggers/cron.spec.ts +++ b/packages/server/src/automations/tests/triggers/cron.spec.ts @@ -31,7 +31,7 @@ describe("cron trigger", () => { }) .save() - await config.publish() + await config.api.application.publish(config.getAppId()) expect(await queue.getCompletedCount()).toEqual(1) @@ -42,4 +42,21 @@ describe("cron trigger", () => { } expect(repeat.cron).toEqual("* * * * *") }) + + it("should fail if the cron expression is invalid", async () => { + await createAutomationBuilder({ config }) + .cron({ cron: "* * * * * *" }) + .serverLog({ + text: "Hello, world!", + }) + .save() + + await config.api.application.publish(config.getAppId(), { + status: 500, + body: { + message: + 'Deployment Failed: Invalid automation CRON "* * * * * *" - Expected 5 values, but got 6.', + }, + }) + }) }) diff --git a/packages/server/src/tests/utilities/api/application.ts b/packages/server/src/tests/utilities/api/application.ts index 1fe9840c1d..d0fcb60804 100644 --- a/packages/server/src/tests/utilities/api/application.ts +++ b/packages/server/src/tests/utilities/api/application.ts @@ -33,7 +33,10 @@ export class ApplicationAPI extends TestAPI { await this._delete(`/api/applications/${appId}`, { expectations }) } - publish = async (appId: string): Promise => { + publish = async ( + appId: string, + expectations?: Expectations + ): Promise => { return await this._post( `/api/applications/${appId}/publish`, { @@ -42,14 +45,16 @@ export class ApplicationAPI extends TestAPI { headers: { [constants.Header.APP_ID]: appId, }, + expectations, } ) } - unpublish = async (appId: string): Promise => { - await this._post(`/api/applications/${appId}/unpublish`, { - expectations: { status: 200 }, - }) + unpublish = async ( + appId: string, + expectations?: Expectations + ): Promise => { + await this._post(`/api/applications/${appId}/unpublish`, { expectations }) } sync = async ( @@ -144,13 +149,20 @@ export class ApplicationAPI extends TestAPI { }) } - fetch = async ({ status }: { status?: AppStatus } = {}): Promise => { + fetch = async ( + { status }: { status?: AppStatus } = {}, + expectations?: Expectations + ): Promise => { return await this._get("/api/applications", { query: { status }, + expectations, }) } - addSampleData = async (appId: string): Promise => { - await this._post(`/api/applications/${appId}/sample`) + addSampleData = async ( + appId: string, + expectations?: Expectations + ): Promise => { + await this._post(`/api/applications/${appId}/sample`, { expectations }) } }