From d80123bbcb559a63f9f0681fa48d8a18bfccfee2 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 4 Sep 2024 09:31:18 +0100 Subject: [PATCH] use utilities api --- .../src/api/routes/tests/automation.spec.ts | 61 +++++++++---------- .../src/tests/utilities/api/automation.ts | 10 +++ 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/packages/server/src/api/routes/tests/automation.spec.ts b/packages/server/src/api/routes/tests/automation.spec.ts index 3f35eb0c9a..9a31cce9a6 100644 --- a/packages/server/src/api/routes/tests/automation.spec.ts +++ b/packages/server/src/api/routes/tests/automation.spec.ts @@ -125,14 +125,14 @@ describe("/automations", () => { it("Should ensure you can't have a branch as not a last step", async () => { const automation = branchAutomationIncorrectPosition() - const res = await request - .post(`/api/automations`) - .set(config.defaultHeaders()) - .send(automation) - .expect("Content-Type", /json/) - .expect(400) - expect(res.body.message).toContain("must contain at least 1 items") + await config.api.automation.post(automation, { + status: 400, + body: { + message: + 'Invalid body - "definition.steps[0].inputs.branches" must contain at least 1 items', + }, + }) }) it("Should check validation on an automation that has a branch step with no children", async () => { @@ -142,16 +142,13 @@ describe("/automations", () => { ] automation.definition.steps[0].inputs.children = {} - const res = await request - .post(`/api/automations`) - .set(config.defaultHeaders()) - .send(automation) - .expect("Content-Type", /json/) - .expect(400) - - expect(res.body.message).toContain( - "Branch steps are only allowed as the last step" - ) + await config.api.automation.post(automation, { + status: 400, + body: { + message: + "Invalid body - Branch steps are only allowed as the last step", + }, + }) }) it("Should check validation on a branch step with empty conditions", async () => { @@ -162,14 +159,13 @@ describe("/automations", () => { ] automation.definition.steps[1].inputs.children = {} - const res = await request - .post(`/api/automations`) - .set(config.defaultHeaders()) - .send(automation) - .expect("Content-Type", /json/) - .expect(400) - - expect(res.body.message).toContain("must have at least 1 key") + await config.api.automation.post(automation, { + status: 400, + body: { + message: + 'Invalid body - "definition.steps[1].inputs.branches[0].condition" must have at least 1 key', + }, + }) }) it("Should check validation on an branch that has a condition that is not valid", async () => { @@ -185,14 +181,13 @@ describe("/automations", () => { ] automation.definition.steps[1].inputs.children = {} - const res = await request - .post(`/api/automations`) - .set(config.defaultHeaders()) - .send(automation) - .expect("Content-Type", /json/) - .expect(400) - - expect(res.body.message).toContain('INCORRECT" is not allowed') + await config.api.automation.post(automation, { + status: 400, + body: { + message: + 'Invalid body - "definition.steps[1].inputs.branches[0].condition.INCORRECT" is not allowed', + }, + }) }) it("should apply authorization to endpoint", async () => { diff --git a/packages/server/src/tests/utilities/api/automation.ts b/packages/server/src/tests/utilities/api/automation.ts index 9620e2011c..61bd915647 100644 --- a/packages/server/src/tests/utilities/api/automation.ts +++ b/packages/server/src/tests/utilities/api/automation.ts @@ -14,4 +14,14 @@ export class AutomationAPI extends TestAPI { ) return result } + post = async ( + body: Automation, + expectations?: Expectations + ): Promise => { + const result = await this._post(`/api/automations`, { + body, + expectations, + }) + return result + } }