use utilities api

This commit is contained in:
Peter Clement 2024-09-04 09:31:18 +01:00
parent 0716702646
commit d80123bbcb
2 changed files with 38 additions and 33 deletions

View File

@ -125,14 +125,14 @@ describe("/automations", () => {
it("Should ensure you can't have a branch as not a last step", async () => { it("Should ensure you can't have a branch as not a last step", async () => {
const automation = branchAutomationIncorrectPosition() 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 () => { 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 = {} automation.definition.steps[0].inputs.children = {}
const res = await request await config.api.automation.post(automation, {
.post(`/api/automations`) status: 400,
.set(config.defaultHeaders()) body: {
.send(automation) message:
.expect("Content-Type", /json/) "Invalid body - Branch steps are only allowed as the last step",
.expect(400) },
})
expect(res.body.message).toContain(
"Branch steps are only allowed as the last step"
)
}) })
it("Should check validation on a branch step with empty conditions", async () => { it("Should check validation on a branch step with empty conditions", async () => {
@ -162,14 +159,13 @@ describe("/automations", () => {
] ]
automation.definition.steps[1].inputs.children = {} automation.definition.steps[1].inputs.children = {}
const res = await request await config.api.automation.post(automation, {
.post(`/api/automations`) status: 400,
.set(config.defaultHeaders()) body: {
.send(automation) message:
.expect("Content-Type", /json/) 'Invalid body - "definition.steps[1].inputs.branches[0].condition" must have at least 1 key',
.expect(400) },
})
expect(res.body.message).toContain("must have at least 1 key")
}) })
it("Should check validation on an branch that has a condition that is not valid", async () => { 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 = {} automation.definition.steps[1].inputs.children = {}
const res = await request await config.api.automation.post(automation, {
.post(`/api/automations`) status: 400,
.set(config.defaultHeaders()) body: {
.send(automation) message:
.expect("Content-Type", /json/) 'Invalid body - "definition.steps[1].inputs.branches[0].condition.INCORRECT" is not allowed',
.expect(400) },
})
expect(res.body.message).toContain('INCORRECT" is not allowed')
}) })
it("should apply authorization to endpoint", async () => { it("should apply authorization to endpoint", async () => {

View File

@ -14,4 +14,14 @@ export class AutomationAPI extends TestAPI {
) )
return result return result
} }
post = async (
body: Automation,
expectations?: Expectations
): Promise<Automation> => {
const result = await this._post<Automation>(`/api/automations`, {
body,
expectations,
})
return result
}
} }