@budibase/server 1.0.200-alpha.3 → 1.0.200

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.
Files changed (285) hide show
  1. package/Dockerfile +0 -2
  2. package/builder/assets/index.f83b3433.js +1315 -0
  3. package/builder/index.html +1 -1
  4. package/coverage/clover.xml +1998 -2086
  5. package/coverage/coverage-final.json +122 -121
  6. package/coverage/lcov-report/api/controllers/analytics.js.html +202 -0
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  8. package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
  9. package/coverage/lcov-report/api/controllers/automation.js.html +72 -174
  10. package/coverage/lcov-report/api/controllers/backup.js.html +6 -30
  11. package/coverage/lcov-report/api/controllers/cloud.js.html +11 -11
  12. package/coverage/lcov-report/api/controllers/component.js.html +5 -5
  13. package/coverage/lcov-report/api/controllers/datasource.js.html +41 -53
  14. package/coverage/lcov-report/api/controllers/dev.js.html +70 -94
  15. package/coverage/lcov-report/api/controllers/index.html +72 -57
  16. package/coverage/lcov-report/api/controllers/integration.js.html +8 -8
  17. package/coverage/lcov-report/api/controllers/layout.js.html +19 -28
  18. package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
  19. package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
  20. package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
  21. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  22. package/coverage/lcov-report/api/controllers/query/validation.js.html +10 -10
  23. package/coverage/lcov-report/api/controllers/role.js.html +48 -78
  24. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  25. package/coverage/lcov-report/api/controllers/row/external.js.html +19 -19
  26. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/internal.js.html +54 -54
  28. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +9 -9
  29. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -24
  30. package/coverage/lcov-report/api/controllers/row/utils.js.html +24 -24
  31. package/coverage/lcov-report/api/controllers/screen.js.html +20 -56
  32. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  33. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +49 -49
  34. package/coverage/lcov-report/api/controllers/table/external.js.html +17 -23
  35. package/coverage/lcov-report/api/controllers/table/index.html +26 -26
  36. package/coverage/lcov-report/api/controllers/table/index.js.html +49 -85
  37. package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
  38. package/coverage/lcov-report/api/controllers/user.js.html +19 -19
  39. package/coverage/lcov-report/api/controllers/view/exporters.js.html +11 -11
  40. package/coverage/lcov-report/api/controllers/view/index.html +21 -21
  41. package/coverage/lcov-report/api/controllers/view/index.js.html +65 -275
  42. package/coverage/lcov-report/api/controllers/view/utils.js.html +23 -23
  43. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +40 -40
  44. package/coverage/lcov-report/api/controllers/webhook.js.html +17 -17
  45. package/coverage/lcov-report/api/index.html +15 -15
  46. package/coverage/lcov-report/api/index.js.html +45 -39
  47. package/coverage/lcov-report/api/routes/analytics.js.html +13 -7
  48. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  49. package/coverage/lcov-report/api/routes/auth.js.html +6 -6
  50. package/coverage/lcov-report/api/routes/automation.js.html +11 -11
  51. package/coverage/lcov-report/api/routes/backup.js.html +8 -8
  52. package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
  53. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  54. package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
  55. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  56. package/coverage/lcov-report/api/routes/dev.js.html +13 -13
  57. package/coverage/lcov-report/api/routes/index.html +1 -1
  58. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  59. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  60. package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
  61. package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
  62. package/coverage/lcov-report/api/routes/permission.js.html +9 -9
  63. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  64. package/coverage/lcov-report/api/routes/role.js.html +9 -9
  65. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  66. package/coverage/lcov-report/api/routes/screen.js.html +9 -9
  67. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/table.js.html +10 -10
  69. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  70. package/coverage/lcov-report/api/routes/user.js.html +8 -8
  71. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  72. package/coverage/lcov-report/api/routes/utils/validators.js.html +36 -36
  73. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  74. package/coverage/lcov-report/api/routes/webhook.js.html +9 -9
  75. package/coverage/lcov-report/automations/actions.js.html +25 -25
  76. package/coverage/lcov-report/automations/automationUtils.js.html +8 -8
  77. package/coverage/lcov-report/automations/bullboard.js.html +35 -35
  78. package/coverage/lcov-report/automations/index.html +29 -29
  79. package/coverage/lcov-report/automations/index.js.html +17 -29
  80. package/coverage/lcov-report/automations/steps/bash.js.html +7 -7
  81. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  82. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  83. package/coverage/lcov-report/automations/steps/executeQuery.js.html +7 -7
  84. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  85. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  86. package/coverage/lcov-report/automations/steps/index.html +1 -1
  87. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  88. package/coverage/lcov-report/automations/steps/loop.js.html +2 -2
  89. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  90. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  91. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  92. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  93. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  94. package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
  95. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  96. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  97. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  98. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  99. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  101. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  102. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  103. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  104. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  105. package/coverage/lcov-report/automations/triggers.js.html +18 -18
  106. package/coverage/lcov-report/constants/index.html +1 -1
  107. package/coverage/lcov-report/constants/index.js.html +30 -30
  108. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  109. package/coverage/lcov-report/constants/screens.js.html +4 -4
  110. package/coverage/lcov-report/db/inMemoryView.js.html +5 -5
  111. package/coverage/lcov-report/db/index.html +1 -1
  112. package/coverage/lcov-report/db/index.js.html +9 -9
  113. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +17 -17
  114. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  115. package/coverage/lcov-report/db/linkedRows/index.js.html +36 -36
  116. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +19 -19
  117. package/coverage/lcov-report/db/newid.js.html +4 -4
  118. package/coverage/lcov-report/db/utils.js.html +81 -81
  119. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  120. package/coverage/lcov-report/events/index.html +1 -1
  121. package/coverage/lcov-report/events/index.js.html +7 -7
  122. package/coverage/lcov-report/events/utils.js.html +10 -10
  123. package/coverage/lcov-report/index.html +74 -74
  124. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  125. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  126. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  127. package/coverage/lcov-report/middleware/builder.js.html +20 -20
  128. package/coverage/lcov-report/middleware/currentapp.js.html +49 -49
  129. package/coverage/lcov-report/middleware/index.html +1 -1
  130. package/coverage/lcov-report/middleware/joi-validator.js.html +14 -14
  131. package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
  132. package/coverage/lcov-report/middleware/resourceId.js.html +29 -29
  133. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  134. package/coverage/lcov-report/middleware/utils.js.html +4 -4
  135. package/coverage/lcov-report/threads/automation.js.html +1 -1
  136. package/coverage/lcov-report/threads/index.html +1 -1
  137. package/coverage/lcov-report/threads/query.js.html +1 -1
  138. package/coverage/lcov-report/threads/utils.js.html +13 -13
  139. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  140. package/coverage/lcov-report/utilities/centralPath.js.html +14 -14
  141. package/coverage/lcov-report/utilities/csvParser.js.html +34 -34
  142. package/coverage/lcov-report/utilities/global.js.html +28 -28
  143. package/coverage/lcov-report/utilities/index.html +25 -25
  144. package/coverage/lcov-report/utilities/index.js.html +41 -41
  145. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +18 -18
  146. package/coverage/lcov-report/utilities/queue/index.html +15 -15
  147. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  148. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  149. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  150. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +59 -59
  151. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +15 -15
  152. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  153. package/coverage/lcov-report/utilities/security.js.html +8 -8
  154. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  155. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  156. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +30 -30
  157. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  158. package/coverage/lcov-report/utilities/users.js.html +7 -7
  159. package/coverage/lcov-report/utilities/workerRequests.js.html +29 -29
  160. package/coverage/lcov.info +2762 -2903
  161. package/dist/api/controllers/analytics.js +30 -7
  162. package/dist/api/controllers/application.js +16 -56
  163. package/dist/api/controllers/automation.js +2 -31
  164. package/dist/api/controllers/backup.js +0 -7
  165. package/dist/api/controllers/datasource.js +2 -8
  166. package/dist/api/controllers/deploy/index.js +2 -6
  167. package/dist/api/controllers/dev.js +2 -9
  168. package/dist/api/controllers/layout.js +0 -3
  169. package/dist/api/controllers/query/import/index.js +2 -12
  170. package/dist/api/controllers/query/import/sources/curl.js +0 -3
  171. package/dist/api/controllers/query/import/sources/openapi2.js +0 -3
  172. package/dist/api/controllers/query/import/sources/openapi3.js +0 -3
  173. package/dist/api/controllers/query/index.js +2 -16
  174. package/dist/api/controllers/role.js +0 -11
  175. package/dist/api/controllers/screen.js +1 -10
  176. package/dist/api/controllers/static/index.js +15 -29
  177. package/dist/api/controllers/table/external.js +0 -2
  178. package/dist/api/controllers/table/index.js +0 -12
  179. package/dist/api/controllers/table/utils.js +3 -3
  180. package/dist/api/controllers/view/index.js +6 -62
  181. package/dist/api/index.js +4 -2
  182. package/dist/api/routes/analytics.js +3 -1
  183. package/dist/app.js +8 -16
  184. package/dist/automations/index.js +0 -4
  185. package/dist/automations/steps/executeQuery.js +1 -1
  186. package/dist/environment.js +2 -4
  187. package/dist/integrations/firebase.js +0 -1
  188. package/dist/migrations/index.js +31 -95
  189. package/dist/package.json +69 -79
  190. package/dist/tests/utilities/TestConfiguration.js +93 -121
  191. package/dist/tests/utilities/structures.js +0 -45
  192. package/dist/tsconfig.build.tsbuildinfo +1 -1
  193. package/nodemon.json +1 -1
  194. package/package.json +70 -80
  195. package/scripts/dev/manage.js +0 -2
  196. package/scripts/jestSetup.js +0 -7
  197. package/scripts/likeCypress.ts +1 -1
  198. package/src/api/controllers/analytics.js +39 -0
  199. package/src/api/controllers/application.ts +18 -60
  200. package/src/api/controllers/automation.js +2 -36
  201. package/src/api/controllers/backup.js +0 -8
  202. package/src/api/controllers/datasource.js +4 -8
  203. package/src/api/controllers/deploy/index.ts +2 -6
  204. package/src/api/controllers/dev.js +2 -10
  205. package/src/api/controllers/layout.js +0 -3
  206. package/src/api/controllers/query/import/index.ts +3 -16
  207. package/src/api/controllers/query/import/sources/base/index.ts +1 -2
  208. package/src/api/controllers/query/import/sources/curl.ts +0 -4
  209. package/src/api/controllers/query/import/sources/openapi2.ts +0 -4
  210. package/src/api/controllers/query/import/sources/openapi3.ts +0 -4
  211. package/src/api/controllers/query/import/tests/index.spec.js +7 -20
  212. package/src/api/controllers/query/index.ts +3 -16
  213. package/src/api/controllers/role.js +0 -10
  214. package/src/api/controllers/screen.js +1 -13
  215. package/src/api/controllers/static/index.js +15 -28
  216. package/src/api/controllers/table/external.js +0 -2
  217. package/src/api/controllers/table/index.js +0 -12
  218. package/src/api/controllers/table/utils.ts +4 -4
  219. package/src/api/controllers/view/index.js +6 -76
  220. package/src/api/index.js +4 -2
  221. package/src/api/routes/analytics.js +3 -1
  222. package/src/api/routes/public/utils/Endpoint.ts +1 -1
  223. package/src/api/routes/tests/__snapshots__/datasource.spec.js.snap +1 -5
  224. package/src/api/routes/tests/application.spec.js +4 -64
  225. package/src/api/routes/tests/automation.spec.js +60 -168
  226. package/src/api/routes/tests/backup.spec.js +0 -2
  227. package/src/api/routes/tests/datasource.spec.js +0 -5
  228. package/src/api/routes/tests/layout.spec.js +0 -4
  229. package/src/api/routes/tests/query.spec.js +13 -56
  230. package/src/api/routes/tests/role.spec.js +7 -40
  231. package/src/api/routes/tests/row.spec.js +3 -2
  232. package/src/api/routes/tests/screen.spec.js +4 -30
  233. package/src/api/routes/tests/static.spec.js +54 -120
  234. package/src/api/routes/tests/table.spec.js +38 -102
  235. package/src/api/routes/tests/view.spec.js +43 -222
  236. package/src/app.ts +9 -18
  237. package/src/automations/index.js +0 -4
  238. package/src/automations/steps/executeQuery.js +1 -1
  239. package/src/automations/tests/delay.spec.js +0 -4
  240. package/src/environment.js +2 -5
  241. package/src/integrations/firebase.ts +0 -1
  242. package/src/migrations/index.ts +51 -120
  243. package/src/module.d.ts +1 -0
  244. package/src/tests/utilities/TestConfiguration.js +90 -138
  245. package/src/tests/utilities/structures.js +0 -71
  246. package/tsconfig.build.json +5 -20
  247. package/tsconfig.json +17 -22
  248. package/builder/assets/index.05491b9d.js +0 -1315
  249. package/dist/migrations/functions/backfill/app/automations.js +0 -31
  250. package/dist/migrations/functions/backfill/app/datasources.js +0 -28
  251. package/dist/migrations/functions/backfill/app/layouts.js +0 -33
  252. package/dist/migrations/functions/backfill/app/queries.js +0 -32
  253. package/dist/migrations/functions/backfill/app/roles.js +0 -28
  254. package/dist/migrations/functions/backfill/app/screens.js +0 -28
  255. package/dist/migrations/functions/backfill/app/tables.js +0 -40
  256. package/dist/migrations/functions/backfill/app.js +0 -175
  257. package/dist/migrations/functions/backfill/global/configs.js +0 -61
  258. package/dist/migrations/functions/backfill/global/quotas.js +0 -60
  259. package/dist/migrations/functions/backfill/global/users.js +0 -50
  260. package/dist/migrations/functions/backfill/global.js +0 -189
  261. package/dist/migrations/functions/backfill/index.js +0 -32
  262. package/dist/migrations/functions/backfill/installation.js +0 -80
  263. package/dist/migrations/tests/helpers.js +0 -72
  264. package/dist/migrations/tests/structures.js +0 -37
  265. package/src/api/controllers/analytics.ts +0 -8
  266. package/src/api/routes/tests/data/export.txt +0 -1
  267. package/src/api/routes/tests/deployment.spec.js +0 -25
  268. package/src/api/routes/tests/dev.spec.js +0 -40
  269. package/src/migrations/functions/backfill/app/automations.ts +0 -26
  270. package/src/migrations/functions/backfill/app/datasources.ts +0 -22
  271. package/src/migrations/functions/backfill/app/layouts.ts +0 -29
  272. package/src/migrations/functions/backfill/app/queries.ts +0 -33
  273. package/src/migrations/functions/backfill/app/roles.ts +0 -22
  274. package/src/migrations/functions/backfill/app/screens.ts +0 -22
  275. package/src/migrations/functions/backfill/app/tables.ts +0 -36
  276. package/src/migrations/functions/backfill/app.ts +0 -148
  277. package/src/migrations/functions/backfill/global/configs.ts +0 -66
  278. package/src/migrations/functions/backfill/global/quotas.ts +0 -60
  279. package/src/migrations/functions/backfill/global/users.ts +0 -49
  280. package/src/migrations/functions/backfill/global.ts +0 -194
  281. package/src/migrations/functions/backfill/index.ts +0 -7
  282. package/src/migrations/functions/backfill/installation.ts +0 -50
  283. package/src/migrations/tests/helpers.ts +0 -40
  284. package/src/migrations/tests/index.spec.ts +0 -132
  285. package/src/migrations/tests/structures.ts +0 -66
package/src/api/index.js CHANGED
@@ -71,8 +71,10 @@ router.use(async (ctx, next) => {
71
71
  validationErrors: err.validation,
72
72
  error,
73
73
  }
74
- ctx.log.error(err)
75
- console.trace(err)
74
+ if (env.NODE_ENV !== "jest") {
75
+ ctx.log.error(err)
76
+ console.trace(err)
77
+ }
76
78
  }
77
79
  })
78
80
 
@@ -3,6 +3,8 @@ const controller = require("../controllers/analytics")
3
3
 
4
4
  const router = Router()
5
5
 
6
- router.get("/api/bbtel", controller.isEnabled)
6
+ router
7
+ .get("/api/bbtel", controller.isEnabled)
8
+ .post("/api/bbtel/ping", controller.endUserPing)
7
9
 
8
10
  module.exports = router
@@ -1,4 +1,4 @@
1
- import Router from "@koa/router"
1
+ import Router from "koa-router"
2
2
 
3
3
  export type CtxFn = (ctx: any, next?: any) => void | Promise<any>
4
4
 
@@ -7,8 +7,7 @@ Array [
7
7
  "entities": Array [
8
8
  Object {
9
9
  "_id": "ta_users",
10
- "_rev": "1-6f4013e796887f1771bf7837598d87e7",
11
- "createdAt": "2020-01-01T00:00:00.000Z",
10
+ "_rev": "1-039883a06c1f9cb3945731d79838181e",
12
11
  "name": "Users",
13
12
  "primaryDisplay": "email",
14
13
  "schema": Object {
@@ -73,7 +72,6 @@ Array [
73
72
  },
74
73
  },
75
74
  "type": "table",
76
- "updatedAt": "2020-01-01T00:00:00.000Z",
77
75
  "views": Object {},
78
76
  },
79
77
  ],
@@ -83,11 +81,9 @@ Array [
83
81
  },
84
82
  Object {
85
83
  "config": Object {},
86
- "createdAt": "2020-01-01T00:00:00.000Z",
87
84
  "name": "Test",
88
85
  "source": "POSTGRES",
89
86
  "type": "datasource",
90
- "updatedAt": "2020-01-01T00:00:00.000Z",
91
87
  },
92
88
  ]
93
89
  `;
@@ -18,7 +18,6 @@ const {
18
18
  } = require("./utilities/TestFunctions")
19
19
  const setup = require("./utilities")
20
20
  const { AppStatus } = require("../../../db/utils")
21
- const { events } = require("@budibase/backend-core")
22
21
 
23
22
  describe("/applications", () => {
24
23
  let request = setup.getRequest()
@@ -29,49 +28,17 @@ describe("/applications", () => {
29
28
  beforeEach(async () => {
30
29
  await clearAllApps()
31
30
  await config.init()
32
- jest.clearAllMocks()
33
31
  })
34
32
 
35
33
  describe("create", () => {
36
- it("creates empty app", async () => {
34
+ it("returns a success message when the application is successfully created", async () => {
37
35
  const res = await request
38
36
  .post("/api/applications")
39
- .field("name", "My App")
37
+ .send({ name: "My App" })
40
38
  .set(config.defaultHeaders())
41
39
  .expect("Content-Type", /json/)
42
40
  .expect(200)
43
41
  expect(res.body._id).toBeDefined()
44
- expect(events.app.created).toBeCalledTimes(1)
45
- })
46
-
47
- it("creates app from template", async () => {
48
- const res = await request
49
- .post("/api/applications")
50
- .field("name", "My App")
51
- .field("useTemplate", "true")
52
- .field("templateKey", "test")
53
- .field("templateString", "{}") // override the file download
54
- .set(config.defaultHeaders())
55
- .expect("Content-Type", /json/)
56
- .expect(200)
57
- expect(res.body._id).toBeDefined()
58
- expect(events.app.created).toBeCalledTimes(1)
59
- expect(events.app.templateImported).toBeCalledTimes(1)
60
- })
61
-
62
-
63
- it("creates app from file", async () => {
64
- const res = await request
65
- .post("/api/applications")
66
- .field("name", "My App")
67
- .field("useTemplate", "true")
68
- .set(config.defaultHeaders())
69
- .attach('templateFile', 'src/api/routes/tests/data/export.txt')
70
- .expect("Content-Type", /json/)
71
- .expect(200)
72
- expect(res.body._id).toBeDefined()
73
- expect(events.app.created).toBeCalledTimes(1)
74
- expect(events.app.fileImported).toBeCalledTimes(1)
75
42
  })
76
43
 
77
44
  it("should apply authorization to endpoint", async () => {
@@ -134,32 +101,7 @@ describe("/applications", () => {
134
101
  .set(config.defaultHeaders())
135
102
  .expect("Content-Type", /json/)
136
103
  .expect(200)
137
- expect(res.body._rev).toBeDefined()
138
- expect(events.app.updated).toBeCalledTimes(1)
139
- })
140
- })
141
-
142
- describe("delete", () => {
143
- it("should delete app", async () => {
144
- await config.createApp("to-delete")
145
- const appId = config.getAppId()
146
- await request
147
- .delete(`/api/applications/${appId}`)
148
- .set(config.defaultHeaders())
149
- .expect("Content-Type", /json/)
150
- .expect(200)
151
- expect(events.app.deleted).toBeCalledTimes(1)
152
- })
153
-
154
- it("should unpublish app", async () => {
155
- await config.createApp("to-unpublish")
156
- const appId = config.getProdAppId()
157
- await request
158
- .delete(`/api/applications/${appId}?unpublish=true`)
159
- .set(config.defaultHeaders())
160
- .expect("Content-Type", /json/)
161
- .expect(200)
162
- expect(events.app.unpublished).toBeCalledTimes(1)
104
+ expect(res.body.rev).toBeDefined()
163
105
  })
164
106
  })
165
107
 
@@ -171,7 +113,6 @@ describe("/applications", () => {
171
113
  .set(config.defaultHeaders())
172
114
  .expect("Content-Type", /json/)
173
115
  .expect(200)
174
- expect(events.app.versionUpdated).toBeCalledTimes(1)
175
116
  })
176
117
  it("should be able to revert the app client library version", async () => {
177
118
  // We need to first update the version so that we can then revert
@@ -185,7 +126,6 @@ describe("/applications", () => {
185
126
  .set(config.defaultHeaders())
186
127
  .expect("Content-Type", /json/)
187
128
  .expect(200)
188
- expect(events.app.versionReverted).toBeCalledTimes(1)
189
129
  })
190
130
  })
191
131
 
@@ -201,7 +141,7 @@ describe("/applications", () => {
201
141
  .set(headers)
202
142
  .expect("Content-Type", /json/)
203
143
  .expect(200)
204
- expect(res.body._rev).toBeDefined()
144
+ expect(res.body.rev).toBeDefined()
205
145
  // retrieve the app to check it
206
146
  const getRes = await request
207
147
  .get(`/api/applications/${config.getAppId()}/appPackage`)
@@ -5,14 +5,17 @@ const {
5
5
  testAutomation,
6
6
  } = require("./utilities/TestFunctions")
7
7
  const setup = require("./utilities")
8
- const { basicAutomation, newAutomation, automationTrigger, automationStep } = setup.structures
8
+ const { basicAutomation } = setup.structures
9
+
9
10
  const MAX_RETRIES = 4
10
- const { TRIGGER_DEFINITIONS, ACTION_DEFINITIONS } = require("../../../automations")
11
- const { events } = require("@budibase/backend-core")
11
+
12
+ let ACTION_DEFINITIONS = {}
13
+ let TRIGGER_DEFINITIONS = {}
12
14
 
13
15
  describe("/automations", () => {
14
16
  let request = setup.getRequest()
15
17
  let config = setup.getConfig()
18
+ let automation
16
19
 
17
20
  afterAll(setup.afterAll)
18
21
 
@@ -29,6 +32,7 @@ describe("/automations", () => {
29
32
  .expect(200)
30
33
 
31
34
  expect(Object.keys(res.body).length).not.toEqual(0)
35
+ ACTION_DEFINITIONS = res.body
32
36
  })
33
37
 
34
38
  it("returns a list of definitions for triggerInfo", async () => {
@@ -39,6 +43,7 @@ describe("/automations", () => {
39
43
  .expect(200)
40
44
 
41
45
  expect(Object.keys(res.body).length).not.toEqual(0)
46
+ TRIGGER_DEFINITIONS = res.body
42
47
  })
43
48
 
44
49
  it("returns all of the definitions in one", async () => {
@@ -48,59 +53,76 @@ describe("/automations", () => {
48
53
  .expect('Content-Type', /json/)
49
54
  .expect(200)
50
55
 
51
- let definitionsLength = Object.keys(ACTION_DEFINITIONS).length
52
- definitionsLength-- // OUTGOING_WEBHOOK is deprecated
53
-
54
- expect(Object.keys(res.body.action).length).toBeGreaterThanOrEqual(definitionsLength)
56
+ expect(Object.keys(res.body.action).length).toBeGreaterThanOrEqual(Object.keys(ACTION_DEFINITIONS).length)
55
57
  expect(Object.keys(res.body.trigger).length).toEqual(Object.keys(TRIGGER_DEFINITIONS).length)
56
58
  })
57
59
  })
58
60
 
59
61
  describe("create", () => {
60
- it("creates an automation with no steps", async () => {
61
- const automation = newAutomation()
62
- automation.definition.steps = []
62
+ const autoConfig = basicAutomation()
63
+ it("should setup the automation fully", () => {
64
+ let trigger = TRIGGER_DEFINITIONS["ROW_SAVED"]
65
+ trigger.id = "wadiawdo34"
66
+ let createAction = ACTION_DEFINITIONS["CREATE_ROW"]
67
+ createAction.inputs.row = {
68
+ name: "{{trigger.row.name}}",
69
+ description: "{{trigger.row.description}}"
70
+ }
71
+ createAction.id = "awde444wk"
63
72
 
73
+ autoConfig.definition.steps.push(createAction)
74
+ autoConfig.definition.trigger = trigger
75
+ })
76
+
77
+ it("returns a success message when the automation is successfully created", async () => {
64
78
  const res = await request
65
79
  .post(`/api/automations`)
66
80
  .set(config.defaultHeaders())
67
- .send(automation)
81
+ .send(autoConfig)
68
82
  .expect('Content-Type', /json/)
69
83
  .expect(200)
70
84
 
71
85
  expect(res.body.message).toEqual("Automation created successfully")
72
86
  expect(res.body.automation.name).toEqual("My Automation")
73
87
  expect(res.body.automation._id).not.toEqual(null)
74
- expect(events.automation.created).toBeCalledTimes(1)
75
- expect(events.automation.stepCreated).not.toBeCalled()
88
+ automation = res.body.automation
76
89
  })
77
90
 
78
- it("creates an automation with steps", async () => {
79
- const automation = newAutomation()
80
- automation.definition.steps.push(automationStep())
81
- jest.clearAllMocks()
82
-
91
+ it("should be able to create an automation with a webhook trigger", async () => {
92
+ const autoConfig = basicAutomation()
93
+ autoConfig.definition.trigger = TRIGGER_DEFINITIONS["WEBHOOK"]
94
+ autoConfig.definition.trigger.id = "webhook_trigger_id"
83
95
  const res = await request
84
96
  .post(`/api/automations`)
85
97
  .set(config.defaultHeaders())
86
- .send(automation)
98
+ .send(autoConfig)
87
99
  .expect('Content-Type', /json/)
88
100
  .expect(200)
89
-
90
- expect(res.body.message).toEqual("Automation created successfully")
91
- expect(res.body.automation.name).toEqual("My Automation")
92
- expect(res.body.automation._id).not.toEqual(null)
93
- expect(events.automation.created).toBeCalledTimes(1)
94
- expect(events.automation.stepCreated).toBeCalledTimes(2)
101
+ const originalAuto = res.body.automation
102
+ expect(originalAuto._id).toBeDefined()
103
+ expect(originalAuto._rev).toBeDefined()
104
+ // try removing the webhook trigger
105
+ const newConfig = originalAuto
106
+ newConfig.definition.trigger = TRIGGER_DEFINITIONS["ROW_SAVED"]
107
+ newConfig.definition.trigger.id = "row_saved_id"
108
+ const newRes = await request
109
+ .post(`/api/automations`)
110
+ .set(config.defaultHeaders())
111
+ .send(newConfig)
112
+ .expect('Content-Type', /json/)
113
+ .expect(200)
114
+ const newAuto = newRes.body.automation
115
+ expect(newAuto._id).toEqual(originalAuto._id)
116
+ expect(newAuto._rev).toBeDefined()
117
+ expect(newAuto._rev).not.toEqual(originalAuto._rev)
95
118
  })
96
119
 
97
120
  it("should apply authorization to endpoint", async () => {
98
- const automation = newAutomation()
99
121
  await checkBuilderEndpoint({
100
122
  config,
101
123
  method: "POST",
102
124
  url: `/api/automations`,
103
- body: automation
125
+ body: autoConfig
104
126
  })
105
127
  })
106
128
  })
@@ -118,23 +140,15 @@ describe("/automations", () => {
118
140
  })
119
141
  })
120
142
 
121
- describe("test", () => {
122
- it("tests the automation successfully", async () => {
143
+ describe("trigger", () => {
144
+ it("trigger the automation successfully", async () => {
123
145
  let table = await config.createTable()
124
- let automation = newAutomation()
125
146
  automation.definition.trigger.inputs.tableId = table._id
126
- automation.definition.steps[0].inputs = {
127
- row: {
128
- name: "{{trigger.row.name}}",
129
- description: "{{trigger.row.description}}",
130
- tableId: table._id
131
- }
132
- }
147
+ automation.definition.steps[0].inputs.row.tableId = table._id
133
148
  automation.appId = config.appId
134
149
  automation = await config.createAutomation(automation)
135
150
  await setup.delay(500)
136
151
  const res = await testAutomation(config, automation)
137
- expect(events.automation.tested).toBeCalledTimes(1)
138
152
  // this looks a bit mad but we don't actually have a way to wait for a response from the automation to
139
153
  // know that it has finished all of its actions - this is currently the best way
140
154
  // also when this runs in CI it is very temper-mental so for now trying to make run stable by repeating until it works
@@ -156,141 +170,20 @@ describe("/automations", () => {
156
170
  })
157
171
 
158
172
  describe("update", () => {
173
+ it("updates a automations data", async () => {
174
+ automation = await config.createAutomation(automation)
175
+ automation.name = "Updated Name"
176
+ automation.type = "automation"
159
177
 
160
- const update = async (automation) => {
161
- return request
178
+ const res = await request
162
179
  .put(`/api/automations`)
163
180
  .set(config.defaultHeaders())
164
181
  .send(automation)
165
182
  .expect('Content-Type', /json/)
166
183
  .expect(200)
167
- }
168
-
169
- const updateWithPost = async (automation) => {
170
- return request
171
- .post(`/api/automations`)
172
- .set(config.defaultHeaders())
173
- .send(automation)
174
- .expect('Content-Type', /json/)
175
- .expect(200)
176
- }
177
-
178
- it("updates a automations name", async () => {
179
- let automation = newAutomation()
180
- await config.createAutomation(automation)
181
- automation.name = "Updated Name"
182
- jest.clearAllMocks()
183
-
184
- const res = await update(automation)
185
-
186
- const automationRes = res.body.automation
187
- const message = res.body.message
188
-
189
- // doc attributes
190
- expect(automationRes._id).toEqual(automation._id)
191
- expect(automationRes._rev).toBeDefined()
192
- expect(automationRes._rev).not.toEqual(automation._rev)
193
- // content updates
194
- expect(automationRes.name).toEqual("Updated Name")
195
- expect(message).toEqual(`Automation ${automation._id} updated successfully.`)
196
- // events
197
- expect(events.automation.created).not.toBeCalled()
198
- expect(events.automation.stepCreated).not.toBeCalled()
199
- expect(events.automation.stepDeleted).not.toBeCalled()
200
- expect(events.automation.triggerUpdated).not.toBeCalled()
201
- })
202
-
203
-
204
- it("updates a automations name using POST request", async () => {
205
- let automation = newAutomation()
206
- await config.createAutomation(automation)
207
- automation.name = "Updated Name"
208
- jest.clearAllMocks()
209
-
210
- // the POST request will defer to the update
211
- // when an id has been supplied.
212
- const res = await updateWithPost(automation)
213
-
214
- const automationRes = res.body.automation
215
- const message = res.body.message
216
- // doc attributes
217
- expect(automationRes._id).toEqual(automation._id)
218
- expect(automationRes._rev).toBeDefined()
219
- expect(automationRes._rev).not.toEqual(automation._rev)
220
- // content updates
221
- expect(automationRes.name).toEqual("Updated Name")
222
- expect(message).toEqual(`Automation ${automation._id} updated successfully.`)
223
- // events
224
- expect(events.automation.created).not.toBeCalled()
225
- expect(events.automation.stepCreated).not.toBeCalled()
226
- expect(events.automation.stepDeleted).not.toBeCalled()
227
- expect(events.automation.triggerUpdated).not.toBeCalled()
228
- })
229
-
230
- it("updates an automation trigger", async () => {
231
- let automation = newAutomation()
232
- automation = await config.createAutomation(automation)
233
- automation.definition.trigger = automationTrigger(TRIGGER_DEFINITIONS.WEBHOOK)
234
- jest.clearAllMocks()
235
-
236
- await update(automation)
237
-
238
- // events
239
- expect(events.automation.created).not.toBeCalled()
240
- expect(events.automation.stepCreated).not.toBeCalled()
241
- expect(events.automation.stepDeleted).not.toBeCalled()
242
- expect(events.automation.triggerUpdated).toBeCalledTimes(1)
243
- })
244
-
245
- it("adds automation steps", async () => {
246
- let automation = newAutomation()
247
- automation = await config.createAutomation(automation)
248
- automation.definition.steps.push(automationStep())
249
- automation.definition.steps.push(automationStep())
250
- jest.clearAllMocks()
251
-
252
- // check the post request honours updates with same id
253
- await update(automation)
254
-
255
- // events
256
- expect(events.automation.stepCreated).toBeCalledTimes(2)
257
- expect(events.automation.created).not.toBeCalled()
258
- expect(events.automation.stepDeleted).not.toBeCalled()
259
- expect(events.automation.triggerUpdated).not.toBeCalled()
260
- })
261
-
262
-
263
- it("removes automation steps", async () => {
264
- let automation = newAutomation()
265
- automation.definition.steps.push(automationStep())
266
- automation = await config.createAutomation(automation)
267
- automation.definition.steps = []
268
- jest.clearAllMocks()
269
-
270
- // check the post request honours updates with same id
271
- await update(automation)
272
-
273
- // events
274
- expect(events.automation.stepDeleted).toBeCalledTimes(2)
275
- expect(events.automation.stepCreated).not.toBeCalled()
276
- expect(events.automation.created).not.toBeCalled()
277
- expect(events.automation.triggerUpdated).not.toBeCalled()
278
- })
279
-
280
- it("adds and removes automation steps", async () => {
281
- let automation = newAutomation()
282
- automation = await config.createAutomation(automation)
283
- automation.definition.steps = [automationStep(), automationStep()]
284
- jest.clearAllMocks()
285
-
286
- // check the post request honours updates with same id
287
- await update(automation)
288
184
 
289
- // events
290
- expect(events.automation.stepCreated).toBeCalledTimes(2)
291
- expect(events.automation.stepDeleted).toBeCalledTimes(1)
292
- expect(events.automation.created).not.toBeCalled()
293
- expect(events.automation.triggerUpdated).not.toBeCalled()
185
+ expect(res.body.message).toEqual(`Automation ${automation._id} updated successfully.`)
186
+ expect(res.body.automation.name).toEqual("Updated Name")
294
187
  })
295
188
  })
296
189
 
@@ -326,8 +219,7 @@ describe("/automations", () => {
326
219
  .expect('Content-Type', /json/)
327
220
  .expect(200)
328
221
 
329
- expect(res.body.id).toEqual(automation._id)
330
- expect(events.automation.deleted).toBeCalledTimes(1)
222
+ expect(res.body.id).toEqual(automation._id)
331
223
  })
332
224
 
333
225
  it("should apply authorization to endpoint", async () => {
@@ -2,7 +2,6 @@ jest.mock("../../../utilities/fileSystem/utilities")
2
2
 
3
3
  const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
4
4
  const setup = require("./utilities")
5
- const { events } = require("@budibase/backend-core")
6
5
 
7
6
  describe("/backups", () => {
8
7
  let request = setup.getRequest()
@@ -22,7 +21,6 @@ describe("/backups", () => {
22
21
  .expect(200)
23
22
  expect(res.text).toBeDefined()
24
23
  expect(res.text.includes(`"db_name":"${config.getAppId()}"`)).toEqual(true)
25
- expect(events.app.exported.mock.calls.length).toBe(1)
26
24
  })
27
25
 
28
26
  it("should apply authorization to endpoint", async () => {
@@ -5,7 +5,6 @@ let { basicDatasource } = setup.structures
5
5
  let { checkBuilderEndpoint } = require("./utilities/TestFunctions")
6
6
  const pg = require("pg")
7
7
  const { checkCacheForDynamicVariable } = require("../../../threads/utils")
8
- const { events } = require("@budibase/backend-core")
9
8
 
10
9
  describe("/datasources", () => {
11
10
  let request = setup.getRequest()
@@ -17,7 +16,6 @@ describe("/datasources", () => {
17
16
  beforeEach(async () => {
18
17
  await config.init()
19
18
  datasource = await config.createDatasource()
20
- jest.clearAllMocks()
21
19
  })
22
20
 
23
21
  describe("create", () => {
@@ -31,7 +29,6 @@ describe("/datasources", () => {
31
29
 
32
30
  expect(res.body.datasource.name).toEqual("Test")
33
31
  expect(res.body.errors).toBeUndefined()
34
- expect(events.datasource.created).toBeCalledTimes(1)
35
32
  })
36
33
  })
37
34
 
@@ -47,7 +44,6 @@ describe("/datasources", () => {
47
44
 
48
45
  expect(res.body.datasource.name).toEqual("Updated Test")
49
46
  expect(res.body.errors).toBeUndefined()
50
- expect(events.datasource.updated).toBeCalledTimes(1)
51
47
  })
52
48
 
53
49
  describe("dynamic variables", () => {
@@ -164,7 +160,6 @@ describe("/datasources", () => {
164
160
  .expect(200)
165
161
 
166
162
  expect(res.body.length).toEqual(1)
167
- expect(events.datasource.deleted).toBeCalledTimes(1)
168
163
  })
169
164
 
170
165
  it("should apply authorization to endpoint", async () => {
@@ -1,7 +1,6 @@
1
1
  const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
2
2
  const setup = require("./utilities")
3
3
  const { basicLayout } = setup.structures
4
- const { events } = require("@budibase/backend-core")
5
4
 
6
5
  describe("/layouts", () => {
7
6
  let request = setup.getRequest()
@@ -13,7 +12,6 @@ describe("/layouts", () => {
13
12
  beforeEach(async () => {
14
13
  await config.init()
15
14
  layout = await config.createLayout()
16
- jest.clearAllMocks()
17
15
  })
18
16
 
19
17
  describe("save", () => {
@@ -25,7 +23,6 @@ describe("/layouts", () => {
25
23
  .expect("Content-Type", /json/)
26
24
  .expect(200)
27
25
  expect(res.body._rev).toBeDefined()
28
- expect(events.layout.created).toBeCalledTimes(1)
29
26
  })
30
27
 
31
28
  it("should apply authorization to endpoint", async () => {
@@ -45,7 +42,6 @@ describe("/layouts", () => {
45
42
  .expect("Content-Type", /json/)
46
43
  .expect(200)
47
44
  expect(res.body.message).toBeDefined()
48
- expect(events.layout.deleted).toBeCalledTimes(1)
49
45
  })
50
46
 
51
47
  it("should apply authorization to endpoint", async () => {