@budibase/server 3.3.2 → 3.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  checkBuilderEndpoint,
3
3
  getAllTableRows,
4
- clearAllAutomations,
5
4
  testAutomation,
6
5
  } from "./utilities/TestFunctions"
7
6
  import * as setup from "./utilities"
@@ -12,9 +11,9 @@ import {
12
11
  import { configs, context, events } from "@budibase/backend-core"
13
12
  import sdk from "../../../sdk"
14
13
  import {
15
- Automation,
16
14
  ConfigType,
17
15
  FieldType,
16
+ isDidNotTriggerResponse,
18
17
  SettingsConfig,
19
18
  Table,
20
19
  } from "@budibase/types"
@@ -22,11 +21,13 @@ import { mocks } from "@budibase/backend-core/tests"
22
21
  import { removeDeprecated } from "../../../automations/utils"
23
22
  import { createAutomationBuilder } from "../../../automations/tests/utilities/AutomationTestBuilder"
24
23
  import { automations } from "@budibase/shared-core"
24
+ import { basicTable } from "../../../tests/utilities/structures"
25
+ import TestConfiguration from "../../../tests/utilities/TestConfiguration"
25
26
 
26
27
  const FilterConditions = automations.steps.filter.FilterConditions
27
28
 
28
29
  const MAX_RETRIES = 4
29
- let {
30
+ const {
30
31
  basicAutomation,
31
32
  newAutomation,
32
33
  automationTrigger,
@@ -37,10 +38,11 @@ let {
37
38
  } = setup.structures
38
39
 
39
40
  describe("/automations", () => {
40
- let request = setup.getRequest()
41
- let config = setup.getConfig()
41
+ const config = new TestConfiguration()
42
42
 
43
- afterAll(setup.afterAll)
43
+ afterAll(() => {
44
+ config.end()
45
+ })
44
46
 
45
47
  beforeAll(async () => {
46
48
  await config.init()
@@ -52,40 +54,26 @@ describe("/automations", () => {
52
54
 
53
55
  describe("get definitions", () => {
54
56
  it("returns a list of definitions for actions", async () => {
55
- const res = await request
56
- .get(`/api/automations/action/list`)
57
- .set(config.defaultHeaders())
58
- .expect("Content-Type", /json/)
59
- .expect(200)
60
-
61
- expect(Object.keys(res.body).length).not.toEqual(0)
57
+ const res = await config.api.automation.getActions()
58
+ expect(Object.keys(res).length).not.toEqual(0)
62
59
  })
63
60
 
64
61
  it("returns a list of definitions for triggerInfo", async () => {
65
- const res = await request
66
- .get(`/api/automations/trigger/list`)
67
- .set(config.defaultHeaders())
68
- .expect("Content-Type", /json/)
69
- .expect(200)
70
-
71
- expect(Object.keys(res.body).length).not.toEqual(0)
62
+ const res = await config.api.automation.getTriggers()
63
+ expect(Object.keys(res).length).not.toEqual(0)
72
64
  })
73
65
 
74
66
  it("returns all of the definitions in one", async () => {
75
- const res = await request
76
- .get(`/api/automations/definitions/list`)
77
- .set(config.defaultHeaders())
78
- .expect("Content-Type", /json/)
79
- .expect(200)
67
+ const { action, trigger } = await config.api.automation.getDefinitions()
80
68
 
81
69
  let definitionsLength = Object.keys(
82
70
  removeDeprecated(BUILTIN_ACTION_DEFINITIONS)
83
71
  ).length
84
72
 
85
- expect(Object.keys(res.body.action).length).toBeGreaterThanOrEqual(
73
+ expect(Object.keys(action).length).toBeGreaterThanOrEqual(
86
74
  definitionsLength
87
75
  )
88
- expect(Object.keys(res.body.trigger).length).toEqual(
76
+ expect(Object.keys(trigger).length).toEqual(
89
77
  Object.keys(removeDeprecated(TRIGGER_DEFINITIONS)).length
90
78
  )
91
79
  })
@@ -93,38 +81,27 @@ describe("/automations", () => {
93
81
 
94
82
  describe("create", () => {
95
83
  it("creates an automation with no steps", async () => {
96
- const automation = newAutomation()
97
- automation.definition.steps = []
98
-
99
- const res = await request
100
- .post(`/api/automations`)
101
- .set(config.defaultHeaders())
102
- .send(automation)
103
- .expect("Content-Type", /json/)
104
- .expect(200)
84
+ const { message, automation } = await config.api.automation.post(
85
+ newAutomation({ steps: [] })
86
+ )
105
87
 
106
- expect(res.body.message).toEqual("Automation created successfully")
107
- expect(res.body.automation.name).toEqual("My Automation")
108
- expect(res.body.automation._id).not.toEqual(null)
88
+ expect(message).toEqual("Automation created successfully")
89
+ expect(automation.name).toEqual("My Automation")
90
+ expect(automation._id).not.toEqual(null)
109
91
  expect(events.automation.created).toHaveBeenCalledTimes(1)
110
92
  expect(events.automation.stepCreated).not.toHaveBeenCalled()
111
93
  })
112
94
 
113
95
  it("creates an automation with steps", async () => {
114
- const automation = newAutomation()
115
- automation.definition.steps.push(automationStep())
116
96
  jest.clearAllMocks()
117
97
 
118
- const res = await request
119
- .post(`/api/automations`)
120
- .set(config.defaultHeaders())
121
- .send(automation)
122
- .expect("Content-Type", /json/)
123
- .expect(200)
98
+ const { message, automation } = await config.api.automation.post(
99
+ newAutomation({ steps: [automationStep(), automationStep()] })
100
+ )
124
101
 
125
- expect(res.body.message).toEqual("Automation created successfully")
126
- expect(res.body.automation.name).toEqual("My Automation")
127
- expect(res.body.automation._id).not.toEqual(null)
102
+ expect(message).toEqual("Automation created successfully")
103
+ expect(automation.name).toEqual("My Automation")
104
+ expect(automation._id).not.toEqual(null)
128
105
  expect(events.automation.created).toHaveBeenCalledTimes(1)
129
106
  expect(events.automation.stepCreated).toHaveBeenCalledTimes(2)
130
107
  })
@@ -241,13 +218,9 @@ describe("/automations", () => {
241
218
  describe("find", () => {
242
219
  it("should be able to find the automation", async () => {
243
220
  const automation = await config.createAutomation()
244
- const res = await request
245
- .get(`/api/automations/${automation._id}`)
246
- .set(config.defaultHeaders())
247
- .expect("Content-Type", /json/)
248
- .expect(200)
249
- expect(res.body._id).toEqual(automation._id)
250
- expect(res.body._rev).toEqual(automation._rev)
221
+ const { _id, _rev } = await config.api.automation.get(automation._id!)
222
+ expect(_id).toEqual(automation._id)
223
+ expect(_rev).toEqual(automation._rev)
251
224
  })
252
225
  })
253
226
 
@@ -348,106 +321,104 @@ describe("/automations", () => {
348
321
 
349
322
  describe("trigger", () => {
350
323
  it("does not trigger an automation when not synchronous and in dev", async () => {
351
- let automation = newAutomation()
352
- automation = await config.createAutomation(automation)
353
- const res = await request
354
- .post(`/api/automations/${automation._id}/trigger`)
355
- .set(config.defaultHeaders())
356
- .expect("Content-Type", /json/)
357
- .expect(400)
358
-
359
- expect(res.body.message).toEqual(
360
- "Only apps in production support this endpoint"
324
+ const { automation } = await config.api.automation.post(newAutomation())
325
+ await config.api.automation.trigger(
326
+ automation._id!,
327
+ {
328
+ fields: {},
329
+ timeout: 1000,
330
+ },
331
+ {
332
+ status: 400,
333
+ body: {
334
+ message: "Only apps in production support this endpoint",
335
+ },
336
+ }
361
337
  )
362
338
  })
363
339
 
364
340
  it("triggers a synchronous automation", async () => {
365
341
  mocks.licenses.useSyncAutomations()
366
- let automation = collectAutomation()
367
- automation = await config.createAutomation(automation)
368
- const res = await request
369
- .post(`/api/automations/${automation._id}/trigger`)
370
- .set(config.defaultHeaders())
371
- .expect("Content-Type", /json/)
372
- .expect(200)
373
-
374
- expect(res.body.success).toEqual(true)
375
- expect(res.body.value).toEqual([1, 2, 3])
342
+ const { automation } = await config.api.automation.post(
343
+ collectAutomation()
344
+ )
345
+ await config.api.automation.trigger(
346
+ automation._id!,
347
+ {
348
+ fields: {},
349
+ timeout: 1000,
350
+ },
351
+ {
352
+ status: 200,
353
+ body: {
354
+ success: true,
355
+ value: [1, 2, 3],
356
+ },
357
+ }
358
+ )
376
359
  })
377
360
 
378
361
  it("should throw an error when attempting to trigger a disabled automation", async () => {
379
362
  mocks.licenses.useSyncAutomations()
380
- let automation = collectAutomation()
381
- automation = await config.createAutomation({
382
- ...automation,
383
- disabled: true,
384
- })
385
-
386
- const res = await request
387
- .post(`/api/automations/${automation._id}/trigger`)
388
- .set(config.defaultHeaders())
389
- .expect("Content-Type", /json/)
390
- .expect(400)
363
+ const { automation } = await config.api.automation.post(
364
+ collectAutomation({ disabled: true })
365
+ )
391
366
 
392
- expect(res.body.message).toEqual("Automation is disabled")
367
+ await config.api.automation.trigger(
368
+ automation._id!,
369
+ {
370
+ fields: {},
371
+ timeout: 1000,
372
+ },
373
+ {
374
+ status: 400,
375
+ body: {
376
+ message: "Automation is disabled",
377
+ },
378
+ }
379
+ )
393
380
  })
394
381
 
395
382
  it("triggers an asynchronous automation", async () => {
396
- let automation = newAutomation()
397
- automation = await config.createAutomation(automation)
383
+ const { automation } = await config.api.automation.post(newAutomation())
398
384
  await config.publish()
399
385
 
400
- const res = await request
401
- .post(`/api/automations/${automation._id}/trigger`)
402
- .set(config.defaultHeaders({}, true))
403
- .expect("Content-Type", /json/)
404
- .expect(200)
405
-
406
- expect(res.body.message).toEqual(
407
- `Automation ${automation._id} has been triggered.`
386
+ await config.withProdApp(() =>
387
+ config.api.automation.trigger(
388
+ automation._id!,
389
+ {
390
+ fields: {},
391
+ timeout: 1000,
392
+ },
393
+ {
394
+ status: 200,
395
+ body: {
396
+ message: `Automation ${automation._id} has been triggered.`,
397
+ },
398
+ }
399
+ )
408
400
  )
409
401
  })
410
402
  })
411
403
 
412
404
  describe("update", () => {
413
- const update = async (automation: Automation) => {
414
- return request
415
- .put(`/api/automations`)
416
- .set(config.defaultHeaders())
417
- .send(automation)
418
- .expect("Content-Type", /json/)
419
- .expect(200)
420
- }
421
-
422
- const updateWithPost = async (automation: Automation) => {
423
- return request
424
- .post(`/api/automations`)
425
- .set(config.defaultHeaders())
426
- .send(automation)
427
- .expect("Content-Type", /json/)
428
- .expect(200)
429
- }
430
-
431
405
  it("updates a automations name", async () => {
432
- const automation = await config.createAutomation(newAutomation())
406
+ const { automation } = await config.api.automation.post(basicAutomation())
433
407
  automation.name = "Updated Name"
434
408
  jest.clearAllMocks()
435
409
 
436
- const res = await update(automation)
410
+ const { automation: updatedAutomation, message } =
411
+ await config.api.automation.update(automation)
437
412
 
438
- const automationRes = res.body.automation
439
- const message = res.body.message
413
+ expect(updatedAutomation._id).toEqual(automation._id)
414
+ expect(updatedAutomation._rev).toBeDefined()
415
+ expect(updatedAutomation._rev).not.toEqual(automation._rev)
440
416
 
441
- // doc attributes
442
- expect(automationRes._id).toEqual(automation._id)
443
- expect(automationRes._rev).toBeDefined()
444
- expect(automationRes._rev).not.toEqual(automation._rev)
445
- // content updates
446
- expect(automationRes.name).toEqual("Updated Name")
417
+ expect(updatedAutomation.name).toEqual("Updated Name")
447
418
  expect(message).toEqual(
448
419
  `Automation ${automation._id} updated successfully.`
449
420
  )
450
- // events
421
+
451
422
  expect(events.automation.created).not.toHaveBeenCalled()
452
423
  expect(events.automation.stepCreated).not.toHaveBeenCalled()
453
424
  expect(events.automation.stepDeleted).not.toHaveBeenCalled()
@@ -455,26 +426,23 @@ describe("/automations", () => {
455
426
  })
456
427
 
457
428
  it("updates a automations name using POST request", async () => {
458
- const automation = await config.createAutomation(newAutomation())
429
+ const { automation } = await config.api.automation.post(basicAutomation())
459
430
  automation.name = "Updated Name"
460
431
  jest.clearAllMocks()
461
432
 
462
- // the POST request will defer to the update
463
- // when an id has been supplied.
464
- const res = await updateWithPost(automation)
465
-
466
- const automationRes = res.body.automation
467
- const message = res.body.message
468
- // doc attributes
469
- expect(automationRes._id).toEqual(automation._id)
470
- expect(automationRes._rev).toBeDefined()
471
- expect(automationRes._rev).not.toEqual(automation._rev)
472
- // content updates
473
- expect(automationRes.name).toEqual("Updated Name")
433
+ // the POST request will defer to the update when an id has been supplied.
434
+ const { automation: updatedAutomation, message } =
435
+ await config.api.automation.post(automation)
436
+
437
+ expect(updatedAutomation._id).toEqual(automation._id)
438
+ expect(updatedAutomation._rev).toBeDefined()
439
+ expect(updatedAutomation._rev).not.toEqual(automation._rev)
440
+
441
+ expect(updatedAutomation.name).toEqual("Updated Name")
474
442
  expect(message).toEqual(
475
443
  `Automation ${automation._id} updated successfully.`
476
444
  )
477
- // events
445
+
478
446
  expect(events.automation.created).not.toHaveBeenCalled()
479
447
  expect(events.automation.stepCreated).not.toHaveBeenCalled()
480
448
  expect(events.automation.stepDeleted).not.toHaveBeenCalled()
@@ -482,16 +450,14 @@ describe("/automations", () => {
482
450
  })
483
451
 
484
452
  it("updates an automation trigger", async () => {
485
- let automation = newAutomation()
486
- automation = await config.createAutomation(automation)
453
+ const { automation } = await config.api.automation.post(newAutomation())
487
454
  automation.definition.trigger = automationTrigger(
488
455
  TRIGGER_DEFINITIONS.WEBHOOK
489
456
  )
490
457
  jest.clearAllMocks()
491
458
 
492
- await update(automation)
459
+ await config.api.automation.update(automation)
493
460
 
494
- // events
495
461
  expect(events.automation.created).not.toHaveBeenCalled()
496
462
  expect(events.automation.stepCreated).not.toHaveBeenCalled()
497
463
  expect(events.automation.stepDeleted).not.toHaveBeenCalled()
@@ -499,16 +465,13 @@ describe("/automations", () => {
499
465
  })
500
466
 
501
467
  it("adds automation steps", async () => {
502
- let automation = newAutomation()
503
- automation = await config.createAutomation(automation)
468
+ const { automation } = await config.api.automation.post(newAutomation())
504
469
  automation.definition.steps.push(automationStep())
505
470
  automation.definition.steps.push(automationStep())
506
471
  jest.clearAllMocks()
507
472
 
508
- // check the post request honours updates with same id
509
- await update(automation)
473
+ await config.api.automation.update(automation)
510
474
 
511
- // events
512
475
  expect(events.automation.stepCreated).toHaveBeenCalledTimes(2)
513
476
  expect(events.automation.created).not.toHaveBeenCalled()
514
477
  expect(events.automation.stepDeleted).not.toHaveBeenCalled()
@@ -516,32 +479,25 @@ describe("/automations", () => {
516
479
  })
517
480
 
518
481
  it("removes automation steps", async () => {
519
- let automation = newAutomation()
520
- automation.definition.steps.push(automationStep())
521
- automation = await config.createAutomation(automation)
482
+ const { automation } = await config.api.automation.post(newAutomation())
522
483
  automation.definition.steps = []
523
484
  jest.clearAllMocks()
524
485
 
525
- // check the post request honours updates with same id
526
- await update(automation)
486
+ await config.api.automation.update(automation)
527
487
 
528
- // events
529
- expect(events.automation.stepDeleted).toHaveBeenCalledTimes(2)
488
+ expect(events.automation.stepDeleted).toHaveBeenCalledTimes(1)
530
489
  expect(events.automation.stepCreated).not.toHaveBeenCalled()
531
490
  expect(events.automation.created).not.toHaveBeenCalled()
532
491
  expect(events.automation.triggerUpdated).not.toHaveBeenCalled()
533
492
  })
534
493
 
535
494
  it("adds and removes automation steps", async () => {
536
- let automation = newAutomation()
537
- automation = await config.createAutomation(automation)
495
+ const { automation } = await config.api.automation.post(newAutomation())
538
496
  automation.definition.steps = [automationStep(), automationStep()]
539
497
  jest.clearAllMocks()
540
498
 
541
- // check the post request honours updates with same id
542
- await update(automation)
499
+ await config.api.automation.update(automation)
543
500
 
544
- // events
545
501
  expect(events.automation.stepCreated).toHaveBeenCalledTimes(2)
546
502
  expect(events.automation.stepDeleted).toHaveBeenCalledTimes(1)
547
503
  expect(events.automation.created).not.toHaveBeenCalled()
@@ -551,16 +507,24 @@ describe("/automations", () => {
551
507
 
552
508
  describe("fetch", () => {
553
509
  it("return all the automations for an instance", async () => {
554
- await clearAllAutomations(config)
555
- const autoConfig = await config.createAutomation(basicAutomation())
556
- const res = await request
557
- .get(`/api/automations`)
558
- .set(config.defaultHeaders())
559
- .expect("Content-Type", /json/)
560
- .expect(200)
561
-
562
- expect(res.body.automations[0]).toEqual(
563
- expect.objectContaining(autoConfig)
510
+ const fetchResponse = await config.api.automation.fetch()
511
+ for (const auto of fetchResponse.automations) {
512
+ await config.api.automation.delete(auto)
513
+ }
514
+
515
+ const { automation: automation1 } = await config.api.automation.post(
516
+ newAutomation()
517
+ )
518
+ const { automation: automation2 } = await config.api.automation.post(
519
+ newAutomation()
520
+ )
521
+ const { automation: automation3 } = await config.api.automation.post(
522
+ newAutomation()
523
+ )
524
+
525
+ const { automations } = await config.api.automation.fetch()
526
+ expect(automations).toEqual(
527
+ expect.arrayContaining([automation1, automation2, automation3])
564
528
  )
565
529
  })
566
530
 
@@ -575,29 +539,25 @@ describe("/automations", () => {
575
539
 
576
540
  describe("destroy", () => {
577
541
  it("deletes a automation by its ID", async () => {
578
- const automation = await config.createAutomation()
579
- const res = await request
580
- .delete(`/api/automations/${automation._id}/${automation._rev}`)
581
- .set(config.defaultHeaders())
582
- .expect("Content-Type", /json/)
583
- .expect(200)
542
+ const { automation } = await config.api.automation.post(newAutomation())
543
+ const { id } = await config.api.automation.delete(automation)
584
544
 
585
- expect(res.body.id).toEqual(automation._id)
545
+ expect(id).toEqual(automation._id)
586
546
  expect(events.automation.deleted).toHaveBeenCalledTimes(1)
587
547
  })
588
548
 
589
549
  it("cannot delete a row action automation", async () => {
590
- const automation = await config.createAutomation(
550
+ const { automation } = await config.api.automation.post(
591
551
  setup.structures.rowActionAutomation()
592
552
  )
593
- await request
594
- .delete(`/api/automations/${automation._id}/${automation._rev}`)
595
- .set(config.defaultHeaders())
596
- .expect("Content-Type", /json/)
597
- .expect(422, {
553
+
554
+ await config.api.automation.delete(automation, {
555
+ status: 422,
556
+ body: {
598
557
  message: "Row actions automations cannot be deleted",
599
558
  status: 422,
600
- })
559
+ },
560
+ })
601
561
 
602
562
  expect(events.automation.deleted).not.toHaveBeenCalled()
603
563
  })
@@ -614,10 +574,19 @@ describe("/automations", () => {
614
574
 
615
575
  describe("checkForCollectStep", () => {
616
576
  it("should return true if a collect step exists in an automation", async () => {
617
- let automation = collectAutomation()
618
- await config.createAutomation(automation)
619
- let res = await sdk.automations.utils.checkForCollectStep(automation)
620
- expect(res).toEqual(true)
577
+ const { automation } = await config.api.automation.post(
578
+ collectAutomation()
579
+ )
580
+ expect(sdk.automations.utils.checkForCollectStep(automation)).toEqual(
581
+ true
582
+ )
583
+ })
584
+
585
+ it("should return false if a collect step does not exist in an automation", async () => {
586
+ const { automation } = await config.api.automation.post(newAutomation())
587
+ expect(sdk.automations.utils.checkForCollectStep(automation)).toEqual(
588
+ false
589
+ )
621
590
  })
622
591
  })
623
592
 
@@ -628,28 +597,45 @@ describe("/automations", () => {
628
597
  ])(
629
598
  "triggers an update row automation and compares new to old rows with old city '%s' and new city '%s'",
630
599
  async ({ oldCity, newCity }) => {
631
- const expectedResult = oldCity === newCity
632
-
633
- let table = await config.createTable()
600
+ let table = await config.api.table.save(basicTable())
601
+
602
+ const { automation } = await config.api.automation.post(
603
+ filterAutomation({
604
+ definition: {
605
+ trigger: {
606
+ inputs: {
607
+ tableId: table._id,
608
+ },
609
+ },
610
+ steps: [
611
+ {
612
+ inputs: {
613
+ condition: FilterConditions.EQUAL,
614
+ field: "{{ trigger.row.City }}",
615
+ value: "{{ trigger.oldRow.City }}",
616
+ },
617
+ },
618
+ ],
619
+ },
620
+ })
621
+ )
634
622
 
635
- let automation = await filterAutomation(config.getAppId())
636
- automation.definition.trigger.inputs.tableId = table._id
637
- automation.definition.steps[0].inputs = {
638
- condition: FilterConditions.EQUAL,
639
- field: "{{ trigger.row.City }}",
640
- value: "{{ trigger.oldRow.City }}",
641
- }
642
- automation = await config.createAutomation(automation)
643
- let triggerInputs = {
623
+ const res = await config.api.automation.test(automation._id!, {
624
+ fields: {},
644
625
  oldRow: {
645
626
  City: oldCity,
646
627
  },
647
628
  row: {
648
629
  City: newCity,
649
630
  },
631
+ })
632
+
633
+ if (isDidNotTriggerResponse(res)) {
634
+ throw new Error("Automation did not trigger")
650
635
  }
651
- const res = await testAutomation(config, automation, triggerInputs)
652
- expect(res.body.steps[1].outputs.result).toEqual(expectedResult)
636
+
637
+ const expectedResult = oldCity === newCity
638
+ expect(res.steps[1].outputs.result).toEqual(expectedResult)
653
639
  }
654
640
  )
655
641
  })
@@ -657,16 +643,18 @@ describe("/automations", () => {
657
643
  let table: Table
658
644
 
659
645
  beforeAll(async () => {
660
- table = await config.createTable({
661
- name: "table",
662
- type: "table",
663
- schema: {
664
- Approved: {
665
- name: "Approved",
666
- type: FieldType.BOOLEAN,
646
+ table = await config.api.table.save(
647
+ basicTable(undefined, {
648
+ name: "table",
649
+ type: "table",
650
+ schema: {
651
+ Approved: {
652
+ name: "Approved",
653
+ type: FieldType.BOOLEAN,
654
+ },
667
655
  },
668
- },
669
- })
656
+ })
657
+ )
670
658
  })
671
659
 
672
660
  const testCases = [
@@ -712,33 +700,29 @@ describe("/automations", () => {
712
700
  it.each(testCases)(
713
701
  "$description",
714
702
  async ({ filters, row, oldRow, expectToRun }) => {
715
- let automation = await updateRowAutomationWithFilters(
716
- config.getAppId(),
717
- table._id!
718
- )
719
- automation.definition.trigger.inputs = {
703
+ let req = updateRowAutomationWithFilters(config.getAppId(), table._id!)
704
+ req.definition.trigger.inputs = {
720
705
  tableId: table._id,
721
706
  filters,
722
707
  }
723
- automation = await config.createAutomation(automation)
724
708
 
725
- const inputs = {
726
- row: {
727
- tableId: table._id,
728
- ...row,
729
- },
709
+ const { automation } = await config.api.automation.post(req)
710
+ const res = await config.api.automation.test(automation._id!, {
711
+ fields: {},
730
712
  oldRow: {
731
713
  tableId: table._id,
732
714
  ...oldRow,
733
715
  },
734
- }
735
-
736
- const res = await testAutomation(config, automation, inputs)
716
+ row: {
717
+ tableId: table._id,
718
+ ...row,
719
+ },
720
+ })
737
721
 
738
- if (expectToRun) {
739
- expect(res.body.steps[1].outputs.success).toEqual(true)
722
+ if (isDidNotTriggerResponse(res)) {
723
+ expect(expectToRun).toEqual(false)
740
724
  } else {
741
- expect(res.body.outputs.success).toEqual(false)
725
+ expect(res.steps[1].outputs.success).toEqual(expectToRun)
742
726
  }
743
727
  }
744
728
  )