@budibase/worker 2.3.17-alpha.1 → 2.3.17

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 (134) hide show
  1. package/coverage/clover.xml +2199 -0
  2. package/coverage/coverage-final.json +84 -0
  3. package/coverage/lcov-report/base.css +224 -0
  4. package/coverage/lcov-report/block-navigation.js +87 -0
  5. package/coverage/lcov-report/favicon.png +0 -0
  6. package/coverage/lcov-report/index.html +431 -0
  7. package/coverage/lcov-report/prettify.css +1 -0
  8. package/coverage/lcov-report/prettify.js +2 -0
  9. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  10. package/coverage/lcov-report/sorter.js +196 -0
  11. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +934 -0
  12. package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +1348 -0
  13. package/coverage/lcov-report/src/api/controllers/global/email.ts.html +196 -0
  14. package/coverage/lcov-report/src/api/controllers/global/events.ts.html +136 -0
  15. package/coverage/lcov-report/src/api/controllers/global/index.html +251 -0
  16. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +187 -0
  17. package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +283 -0
  18. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +577 -0
  19. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +316 -0
  20. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +838 -0
  21. package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +244 -0
  22. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +148 -0
  23. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +124 -0
  24. package/coverage/lcov-report/src/api/controllers/system/index.html +191 -0
  25. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +124 -0
  26. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +124 -0
  27. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +133 -0
  28. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +154 -0
  29. package/coverage/lcov-report/src/api/index.html +116 -0
  30. package/coverage/lcov-report/src/api/index.ts.html +595 -0
  31. package/coverage/lcov-report/src/api/routes/global/auth.ts.html +349 -0
  32. package/coverage/lcov-report/src/api/routes/global/configs.ts.html +457 -0
  33. package/coverage/lcov-report/src/api/routes/global/email.ts.html +193 -0
  34. package/coverage/lcov-report/src/api/routes/global/events.ts.html +109 -0
  35. package/coverage/lcov-report/src/api/routes/global/index.html +251 -0
  36. package/coverage/lcov-report/src/api/routes/global/license.ts.html +124 -0
  37. package/coverage/lcov-report/src/api/routes/global/roles.ts.html +133 -0
  38. package/coverage/lcov-report/src/api/routes/global/self.ts.html +139 -0
  39. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +196 -0
  40. package/coverage/lcov-report/src/api/routes/global/users.ts.html +475 -0
  41. package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +196 -0
  42. package/coverage/lcov-report/src/api/routes/index.html +116 -0
  43. package/coverage/lcov-report/src/api/routes/index.ts.html +202 -0
  44. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +142 -0
  45. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +109 -0
  46. package/coverage/lcov-report/src/api/routes/system/index.html +191 -0
  47. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +142 -0
  48. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +109 -0
  49. package/coverage/lcov-report/src/api/routes/system/status.ts.html +109 -0
  50. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +124 -0
  51. package/coverage/lcov-report/src/api/routes/validation/index.html +131 -0
  52. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +88 -0
  53. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +235 -0
  54. package/coverage/lcov-report/src/constants/index.html +116 -0
  55. package/coverage/lcov-report/src/constants/index.ts.html +637 -0
  56. package/coverage/lcov-report/src/constants/templates/index.html +116 -0
  57. package/coverage/lcov-report/src/constants/templates/index.ts.html +316 -0
  58. package/coverage/lcov-report/src/db/index.html +116 -0
  59. package/coverage/lcov-report/src/db/index.ts.html +115 -0
  60. package/coverage/lcov-report/src/environment.ts.html +388 -0
  61. package/coverage/lcov-report/src/index.html +131 -0
  62. package/coverage/lcov-report/src/index.ts.html +394 -0
  63. package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +139 -0
  64. package/coverage/lcov-report/src/middleware/index.html +116 -0
  65. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +145 -0
  66. package/coverage/lcov-report/src/migrations/functions/index.html +116 -0
  67. package/coverage/lcov-report/src/migrations/index.html +116 -0
  68. package/coverage/lcov-report/src/migrations/index.ts.html +271 -0
  69. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +262 -0
  70. package/coverage/lcov-report/src/sdk/accounts/index.html +131 -0
  71. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +88 -0
  72. package/coverage/lcov-report/src/sdk/index.html +116 -0
  73. package/coverage/lcov-report/src/sdk/index.ts.html +106 -0
  74. package/coverage/lcov-report/src/sdk/users/events.ts.html +601 -0
  75. package/coverage/lcov-report/src/sdk/users/index.html +146 -0
  76. package/coverage/lcov-report/src/sdk/users/index.ts.html +88 -0
  77. package/coverage/lcov-report/src/sdk/users/users.ts.html +1999 -0
  78. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +1075 -0
  79. package/coverage/lcov-report/src/tests/api/accounts.ts.html +160 -0
  80. package/coverage/lcov-report/src/tests/api/auth.ts.html +220 -0
  81. package/coverage/lcov-report/src/tests/api/base.ts.html +133 -0
  82. package/coverage/lcov-report/src/tests/api/configs.ts.html +226 -0
  83. package/coverage/lcov-report/src/tests/api/email.ts.html +148 -0
  84. package/coverage/lcov-report/src/tests/api/environment.ts.html +130 -0
  85. package/coverage/lcov-report/src/tests/api/groups.ts.html +163 -0
  86. package/coverage/lcov-report/src/tests/api/index.html +356 -0
  87. package/coverage/lcov-report/src/tests/api/index.ts.html +238 -0
  88. package/coverage/lcov-report/src/tests/api/license.ts.html +136 -0
  89. package/coverage/lcov-report/src/tests/api/migrations.ts.html +151 -0
  90. package/coverage/lcov-report/src/tests/api/restore.ts.html +127 -0
  91. package/coverage/lcov-report/src/tests/api/roles.ts.html +181 -0
  92. package/coverage/lcov-report/src/tests/api/self.ts.html +163 -0
  93. package/coverage/lcov-report/src/tests/api/status.ts.html +121 -0
  94. package/coverage/lcov-report/src/tests/api/templates.ts.html +175 -0
  95. package/coverage/lcov-report/src/tests/api/tenants.ts.html +130 -0
  96. package/coverage/lcov-report/src/tests/api/users.ts.html +514 -0
  97. package/coverage/lcov-report/src/tests/controllers.ts.html +100 -0
  98. package/coverage/lcov-report/src/tests/index.html +146 -0
  99. package/coverage/lcov-report/src/tests/index.ts.html +103 -0
  100. package/coverage/lcov-report/src/tests/mocks/email.ts.html +115 -0
  101. package/coverage/lcov-report/src/tests/mocks/index.html +131 -0
  102. package/coverage/lcov-report/src/tests/mocks/index.ts.html +106 -0
  103. package/coverage/lcov-report/src/tests/structures/configs.ts.html +313 -0
  104. package/coverage/lcov-report/src/tests/structures/groups.ts.html +118 -0
  105. package/coverage/lcov-report/src/tests/structures/index.html +161 -0
  106. package/coverage/lcov-report/src/tests/structures/index.ts.html +151 -0
  107. package/coverage/lcov-report/src/tests/structures/users.ts.html +196 -0
  108. package/coverage/lcov-report/src/utilities/appService.ts.html +208 -0
  109. package/coverage/lcov-report/src/utilities/email.ts.html +850 -0
  110. package/coverage/lcov-report/src/utilities/fileSystem.ts.html +100 -0
  111. package/coverage/lcov-report/src/utilities/index.html +206 -0
  112. package/coverage/lcov-report/src/utilities/index.ts.html +112 -0
  113. package/coverage/lcov-report/src/utilities/redis.ts.html +424 -0
  114. package/coverage/lcov-report/src/utilities/templates.ts.html +232 -0
  115. package/coverage/lcov-report/src/utilities/users.ts.html +133 -0
  116. package/coverage/lcov.info +4187 -0
  117. package/jest.config.ts +2 -3
  118. package/package.json +6 -8
  119. package/src/api/routes/global/tests/auth.spec.ts +22 -30
  120. package/src/api/routes/global/tests/configs.spec.ts +94 -114
  121. package/src/api/routes/global/tests/roles.spec.ts +14 -19
  122. package/src/api/routes/global/tests/users.spec.ts +34 -33
  123. package/src/index.ts +7 -6
  124. package/src/sdk/users/users.ts +1 -0
  125. package/src/tests/TestConfiguration.ts +11 -41
  126. package/src/tests/api/auth.ts +3 -7
  127. package/src/tests/api/configs.ts +2 -2
  128. package/src/tests/api/users.ts +2 -2
  129. package/src/tests/jestSetup.ts +2 -9
  130. package/src/tests/structures/index.ts +2 -0
  131. package/__mocks__/node-fetch.ts +0 -23
  132. package/jest-testcontainers-config.js +0 -8
  133. package/src/ddApm.ts +0 -7
  134. package/src/elasticApm.ts +0 -10
package/jest.config.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import { Config } from "@jest/types"
2
2
  import * as fs from "fs"
3
- const preset = require("ts-jest/jest-preset")
4
3
 
5
4
  const config: Config.InitialOptions = {
6
- ...preset,
7
- preset: "@trendyol/jest-testcontainers",
5
+ testEnvironment: "node",
8
6
  setupFiles: ["./src/tests/jestEnv.ts"],
9
7
  setupFilesAfterEnv: ["./src/tests/jestSetup.ts"],
10
8
  collectCoverageFrom: ["src/**/*.{js,ts}"],
@@ -20,6 +18,7 @@ if (!process.env.CI) {
20
18
  "@budibase/backend-core/(.*)": "<rootDir>/../backend-core/$1",
21
19
  "@budibase/backend-core": "<rootDir>/../backend-core/src",
22
20
  "@budibase/types": "<rootDir>/../types/src",
21
+ "^axios.*$": "<rootDir>/node_modules/axios/lib/axios.js",
23
22
  }
24
23
  // add pro sources if they exist
25
24
  if (fs.existsSync("../../../budibase-pro")) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/worker",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.3.17-alpha.1",
4
+ "version": "2.3.17",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -36,17 +36,16 @@
36
36
  "author": "Budibase",
37
37
  "license": "GPL-3.0",
38
38
  "dependencies": {
39
- "@budibase/backend-core": "2.3.17-alpha.1",
40
- "@budibase/pro": "2.3.17-alpha.0",
41
- "@budibase/string-templates": "2.3.17-alpha.1",
42
- "@budibase/types": "2.3.17-alpha.1",
39
+ "@budibase/backend-core": "^2.3.17",
40
+ "@budibase/pro": "2.3.16",
41
+ "@budibase/string-templates": "^2.3.17",
42
+ "@budibase/types": "^2.3.17",
43
43
  "@koa/router": "8.0.8",
44
44
  "@sentry/node": "6.17.7",
45
45
  "@techpass/passport-openidconnect": "0.3.2",
46
46
  "@types/global-agent": "2.1.1",
47
47
  "aws-sdk": "2.1030.0",
48
48
  "bcryptjs": "2.4.3",
49
- "dd-trace": "3.13.2",
50
49
  "dotenv": "8.6.0",
51
50
  "elastic-apm-node": "3.38.0",
52
51
  "global-agent": "3.0.0",
@@ -73,7 +72,6 @@
73
72
  "devDependencies": {
74
73
  "@swc/core": "^1.3.25",
75
74
  "@swc/jest": "^0.2.24",
76
- "@trendyol/jest-testcontainers": "^2.1.1",
77
75
  "@types/jest": "26.0.23",
78
76
  "@types/jsonwebtoken": "8.5.1",
79
77
  "@types/koa": "2.13.4",
@@ -99,5 +97,5 @@
99
97
  "typescript": "4.7.3",
100
98
  "update-dotenv": "1.1.1"
101
99
  },
102
- "gitHead": "5c22c75429f742b3e0e64c01fc3ad41b5fd55000"
100
+ "gitHead": "a57c922b91c1df8dc276588a5ad583a0c1aea52c"
103
101
  }
@@ -1,8 +1,7 @@
1
1
  jest.mock("nodemailer")
2
2
  import { TestConfiguration, mocks } from "../../../../tests"
3
3
  const sendMailMock = mocks.email.mock()
4
- import { events, tenancy } from "@budibase/backend-core"
5
- import { structures } from "@budibase/backend-core/tests"
4
+ import { events } from "@budibase/backend-core"
6
5
 
7
6
  const expectSetAuthCookie = (res: any) => {
8
7
  expect(
@@ -41,43 +40,36 @@ describe("/api/global/auth", () => {
41
40
 
42
41
  describe("POST /api/global/auth/:tenantId/reset", () => {
43
42
  it("should generate password reset email", async () => {
44
- await tenancy.doInTenant(config.tenant1User!.tenantId, async () => {
45
- const userEmail = structures.email()
46
- const { res, code } = await config.api.auth.requestPasswordReset(
47
- sendMailMock,
48
- userEmail
49
- )
50
- const user = await config.getUser(userEmail)
51
-
52
- expect(res.body).toEqual({
53
- message: "Please check your email for a reset link.",
54
- })
55
- expect(sendMailMock).toHaveBeenCalled()
43
+ const { res, code } = await config.api.auth.requestPasswordReset(
44
+ sendMailMock
45
+ )
46
+ const user = await config.getUser("test@test.com")
56
47
 
57
- expect(code).toBeDefined()
58
- expect(events.user.passwordResetRequested).toBeCalledTimes(1)
59
- expect(events.user.passwordResetRequested).toBeCalledWith(user)
48
+ expect(res.body).toEqual({
49
+ message: "Please check your email for a reset link.",
60
50
  })
51
+ expect(sendMailMock).toHaveBeenCalled()
52
+
53
+ expect(code).toBeDefined()
54
+ expect(events.user.passwordResetRequested).toBeCalledTimes(1)
55
+ expect(events.user.passwordResetRequested).toBeCalledWith(user)
61
56
  })
62
57
  })
63
58
 
64
59
  describe("POST /api/global/auth/:tenantId/reset/update", () => {
65
60
  it("should reset password", async () => {
66
- await tenancy.doInTenant(config.tenant1User!.tenantId, async () => {
67
- const userEmail = structures.email()
68
- const { code } = await config.api.auth.requestPasswordReset(
69
- sendMailMock,
70
- userEmail
71
- )
72
- const user = await config.getUser(userEmail)
73
- delete user.password
61
+ const { code } = await config.api.auth.requestPasswordReset(
62
+ sendMailMock
63
+ )
64
+ const user = await config.getUser("test@test.com")
65
+ delete user.password
74
66
 
75
- const res = await config.api.auth.updatePassword(code)
67
+ const res = await config.api.auth.updatePassword(code)
68
+
69
+ expect(res.body).toEqual({ message: "password reset successfully." })
70
+ expect(events.user.passwordReset).toBeCalledTimes(1)
71
+ expect(events.user.passwordReset).toBeCalledWith(user)
76
72
 
77
- expect(res.body).toEqual({ message: "password reset successfully." })
78
- expect(events.user.passwordReset).toBeCalledTimes(1)
79
- expect(events.user.passwordReset).toBeCalledWith(user)
80
- })
81
73
  // TODO: Login using new password
82
74
  })
83
75
  })
@@ -2,12 +2,12 @@
2
2
  jest.mock("nodemailer")
3
3
  import { TestConfiguration, structures, mocks } from "../../../../tests"
4
4
  mocks.email.mock()
5
- import { Config, context, events } from "@budibase/backend-core"
5
+ import { Config, events } from "@budibase/backend-core"
6
6
 
7
7
  describe("configs", () => {
8
8
  const config = new TestConfiguration()
9
9
 
10
- beforeEach(async () => {
10
+ beforeAll(async () => {
11
11
  await config.beforeAll()
12
12
  })
13
13
 
@@ -113,64 +113,56 @@ describe("configs", () => {
113
113
 
114
114
  describe("create", () => {
115
115
  it("should create activated OIDC config", async () => {
116
- await context.doInTenant(config.tenant1User!.tenantId, async () => {
117
- await saveOIDCConfig()
118
- expect(events.auth.SSOCreated).toBeCalledTimes(1)
119
- expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
120
- expect(events.auth.SSODeactivated).not.toBeCalled()
121
- expect(events.auth.SSOActivated).toBeCalledTimes(1)
122
- expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
123
- await config.deleteConfig(Config.OIDC)
124
- })
116
+ await saveOIDCConfig()
117
+ expect(events.auth.SSOCreated).toBeCalledTimes(1)
118
+ expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
119
+ expect(events.auth.SSODeactivated).not.toBeCalled()
120
+ expect(events.auth.SSOActivated).toBeCalledTimes(1)
121
+ expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
122
+ await config.deleteConfig(Config.OIDC)
125
123
  })
126
124
 
127
125
  it("should create deactivated OIDC config", async () => {
128
- await context.doInTenant(config.tenant1User!.tenantId, async () => {
129
- await saveOIDCConfig({ activated: false })
130
- expect(events.auth.SSOCreated).toBeCalledTimes(1)
131
- expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
132
- expect(events.auth.SSOActivated).not.toBeCalled()
133
- expect(events.auth.SSODeactivated).not.toBeCalled()
134
- await config.deleteConfig(Config.OIDC)
135
- })
126
+ await saveOIDCConfig({ activated: false })
127
+ expect(events.auth.SSOCreated).toBeCalledTimes(1)
128
+ expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
129
+ expect(events.auth.SSOActivated).not.toBeCalled()
130
+ expect(events.auth.SSODeactivated).not.toBeCalled()
131
+ await config.deleteConfig(Config.OIDC)
136
132
  })
137
133
  })
138
134
 
139
135
  describe("update", () => {
140
136
  it("should update OIDC config to deactivated", async () => {
141
- await context.doInTenant(config.tenant1User!.tenantId, async () => {
142
- const oidcConf = await saveOIDCConfig()
143
- jest.clearAllMocks()
144
- await saveOIDCConfig(
145
- { ...oidcConf.config.configs[0], activated: false },
146
- oidcConf._id,
147
- oidcConf._rev
148
- )
149
- expect(events.auth.SSOUpdated).toBeCalledTimes(1)
150
- expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
151
- expect(events.auth.SSOActivated).not.toBeCalled()
152
- expect(events.auth.SSODeactivated).toBeCalledTimes(1)
153
- expect(events.auth.SSODeactivated).toBeCalledWith(Config.OIDC)
154
- await config.deleteConfig(Config.OIDC)
155
- })
137
+ const oidcConf = await saveOIDCConfig()
138
+ jest.clearAllMocks()
139
+ await saveOIDCConfig(
140
+ { ...oidcConf.config.configs[0], activated: false },
141
+ oidcConf._id,
142
+ oidcConf._rev
143
+ )
144
+ expect(events.auth.SSOUpdated).toBeCalledTimes(1)
145
+ expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
146
+ expect(events.auth.SSOActivated).not.toBeCalled()
147
+ expect(events.auth.SSODeactivated).toBeCalledTimes(1)
148
+ expect(events.auth.SSODeactivated).toBeCalledWith(Config.OIDC)
149
+ await config.deleteConfig(Config.OIDC)
156
150
  })
157
151
 
158
152
  it("should update OIDC config to activated", async () => {
159
- await context.doInTenant(config.tenant1User!.tenantId, async () => {
160
- const oidcConf = await saveOIDCConfig({ activated: false })
161
- jest.clearAllMocks()
162
- await saveOIDCConfig(
163
- { ...oidcConf.config.configs[0], activated: true },
164
- oidcConf._id,
165
- oidcConf._rev
166
- )
167
- expect(events.auth.SSOUpdated).toBeCalledTimes(1)
168
- expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
169
- expect(events.auth.SSODeactivated).not.toBeCalled()
170
- expect(events.auth.SSOActivated).toBeCalledTimes(1)
171
- expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
172
- await config.deleteConfig(Config.OIDC)
173
- })
153
+ const oidcConf = await saveOIDCConfig({ activated: false })
154
+ jest.clearAllMocks()
155
+ await saveOIDCConfig(
156
+ { ...oidcConf.config.configs[0], activated: true },
157
+ oidcConf._id,
158
+ oidcConf._rev
159
+ )
160
+ expect(events.auth.SSOUpdated).toBeCalledTimes(1)
161
+ expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
162
+ expect(events.auth.SSODeactivated).not.toBeCalled()
163
+ expect(events.auth.SSOActivated).toBeCalledTimes(1)
164
+ expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
165
+ await config.deleteConfig(Config.OIDC)
174
166
  })
175
167
  })
176
168
  })
@@ -187,26 +179,22 @@ describe("configs", () => {
187
179
 
188
180
  describe("create", () => {
189
181
  it("should create SMTP config", async () => {
190
- await context.doInTenant(config.tenant1User!.tenantId, async () => {
191
- await config.deleteConfig(Config.SMTP)
192
- await saveSMTPConfig()
193
- expect(events.email.SMTPUpdated).not.toBeCalled()
194
- expect(events.email.SMTPCreated).toBeCalledTimes(1)
195
- await config.deleteConfig(Config.SMTP)
196
- })
182
+ await config.deleteConfig(Config.SMTP)
183
+ await saveSMTPConfig()
184
+ expect(events.email.SMTPUpdated).not.toBeCalled()
185
+ expect(events.email.SMTPCreated).toBeCalledTimes(1)
186
+ await config.deleteConfig(Config.SMTP)
197
187
  })
198
188
  })
199
189
 
200
190
  describe("update", () => {
201
191
  it("should update SMTP config", async () => {
202
- await context.doInTenant(config.tenant1User!.tenantId, async () => {
203
- const smtpConf = await saveSMTPConfig()
204
- jest.clearAllMocks()
205
- await saveSMTPConfig(smtpConf.config, smtpConf._id, smtpConf._rev)
206
- expect(events.email.SMTPCreated).not.toBeCalled()
207
- expect(events.email.SMTPUpdated).toBeCalledTimes(1)
208
- await config.deleteConfig(Config.SMTP)
209
- })
192
+ const smtpConf = await saveSMTPConfig()
193
+ jest.clearAllMocks()
194
+ await saveSMTPConfig(smtpConf.config, smtpConf._id, smtpConf._rev)
195
+ expect(events.email.SMTPCreated).not.toBeCalled()
196
+ expect(events.email.SMTPUpdated).toBeCalledTimes(1)
197
+ await config.deleteConfig(Config.SMTP)
210
198
  })
211
199
  })
212
200
  })
@@ -223,73 +211,65 @@ describe("configs", () => {
223
211
 
224
212
  describe("create", () => {
225
213
  it("should create settings config with default settings", async () => {
226
- await context.doInTenant(config.tenant1User!.tenantId, async () => {
227
- await config.deleteConfig(Config.SETTINGS)
214
+ await config.deleteConfig(Config.SETTINGS)
228
215
 
229
- await saveSettingsConfig()
216
+ await saveSettingsConfig()
230
217
 
231
- expect(events.org.nameUpdated).not.toBeCalled()
232
- expect(events.org.logoUpdated).not.toBeCalled()
233
- expect(events.org.platformURLUpdated).not.toBeCalled()
234
- })
218
+ expect(events.org.nameUpdated).not.toBeCalled()
219
+ expect(events.org.logoUpdated).not.toBeCalled()
220
+ expect(events.org.platformURLUpdated).not.toBeCalled()
235
221
  })
236
222
 
237
223
  it("should create settings config with non-default settings", async () => {
238
- await context.doInTenant(config.tenant1User!.tenantId, async () => {
239
- config.modeSelf()
240
- await config.deleteConfig(Config.SETTINGS)
241
- const conf = {
242
- company: "acme",
243
- logoUrl: "http://example.com",
244
- platformUrl: "http://example.com",
245
- }
246
-
247
- await saveSettingsConfig(conf)
248
-
249
- expect(events.org.nameUpdated).toBeCalledTimes(1)
250
- expect(events.org.logoUpdated).toBeCalledTimes(1)
251
- expect(events.org.platformURLUpdated).toBeCalledTimes(1)
252
- config.modeCloud()
253
- })
224
+ config.modeSelf()
225
+ await config.deleteConfig(Config.SETTINGS)
226
+ const conf = {
227
+ company: "acme",
228
+ logoUrl: "http://example.com",
229
+ platformUrl: "http://example.com",
230
+ }
231
+
232
+ await saveSettingsConfig(conf)
233
+
234
+ expect(events.org.nameUpdated).toBeCalledTimes(1)
235
+ expect(events.org.logoUpdated).toBeCalledTimes(1)
236
+ expect(events.org.platformURLUpdated).toBeCalledTimes(1)
237
+ config.modeCloud()
254
238
  })
255
239
  })
256
240
 
257
241
  describe("update", () => {
258
242
  it("should update settings config", async () => {
259
- await context.doInTenant(config.tenant1User!.tenantId, async () => {
260
- config.modeSelf()
261
- await config.deleteConfig(Config.SETTINGS)
262
- const settingsConfig = await saveSettingsConfig()
263
- settingsConfig.config.company = "acme"
264
- settingsConfig.config.logoUrl = "http://example.com"
265
- settingsConfig.config.platformUrl = "http://example.com"
266
-
267
- await saveSettingsConfig(
268
- settingsConfig.config,
269
- settingsConfig._id,
270
- settingsConfig._rev
271
- )
272
-
273
- expect(events.org.nameUpdated).toBeCalledTimes(1)
274
- expect(events.org.logoUpdated).toBeCalledTimes(1)
275
- expect(events.org.platformURLUpdated).toBeCalledTimes(1)
276
- config.modeCloud()
277
- })
243
+ config.modeSelf()
244
+ await config.deleteConfig(Config.SETTINGS)
245
+ const settingsConfig = await saveSettingsConfig()
246
+ settingsConfig.config.company = "acme"
247
+ settingsConfig.config.logoUrl = "http://example.com"
248
+ settingsConfig.config.platformUrl = "http://example.com"
249
+
250
+ await saveSettingsConfig(
251
+ settingsConfig.config,
252
+ settingsConfig._id,
253
+ settingsConfig._rev
254
+ )
255
+
256
+ expect(events.org.nameUpdated).toBeCalledTimes(1)
257
+ expect(events.org.logoUpdated).toBeCalledTimes(1)
258
+ expect(events.org.platformURLUpdated).toBeCalledTimes(1)
259
+ config.modeCloud()
278
260
  })
279
261
  })
280
262
  })
281
263
  })
282
264
 
283
265
  it("should return the correct checklist status based on the state of the budibase installation", async () => {
284
- await context.doInTenant(config.tenant1User!.tenantId, async () => {
285
- await config.saveSmtpConfig()
266
+ await config.saveSmtpConfig()
286
267
 
287
- const res = await config.api.configs.getConfigChecklist()
288
- const checklist = res.body
268
+ const res = await config.api.configs.getConfigChecklist()
269
+ const checklist = res.body
289
270
 
290
- expect(checklist.apps.checked).toBeFalsy()
291
- expect(checklist.smtp.checked).toBeTruthy()
292
- expect(checklist.adminUser.checked).toBeTruthy()
293
- })
271
+ expect(checklist.apps.checked).toBeFalsy()
272
+ expect(checklist.smtp.checked).toBeTruthy()
273
+ expect(checklist.adminUser.checked).toBeTruthy()
294
274
  })
295
275
  })
@@ -1,7 +1,6 @@
1
1
  import { structures, TestConfiguration } from "../../../../tests"
2
2
  import { context, db, permissions, roles } from "@budibase/backend-core"
3
3
  import { Mock } from "jest-mock"
4
- import { Database } from "@budibase/types"
5
4
 
6
5
  jest.mock("@budibase/backend-core", () => {
7
6
  const core = jest.requireActual("@budibase/backend-core")
@@ -17,13 +16,14 @@ jest.mock("@budibase/backend-core", () => {
17
16
  }
18
17
  })
19
18
 
20
- let appId: string
21
- let appDb: Database
19
+ const appDb = db.getDB("app_test")
20
+ const mockAppDB = context.getAppDB as Mock
21
+ mockAppDB.mockReturnValue(appDb)
22
22
 
23
23
  async function addAppMetadata() {
24
24
  await appDb.put({
25
25
  _id: "app_metadata",
26
- appId: appId,
26
+ appId: "app_test",
27
27
  name: "New App",
28
28
  version: "version",
29
29
  url: "url",
@@ -39,17 +39,10 @@ describe("/api/global/roles", () => {
39
39
  )
40
40
 
41
41
  beforeAll(async () => {
42
- await config.beforeAll()
43
- })
44
-
45
- beforeEach(async () => {
46
- appId = db.generateAppID()
47
- appDb = db.getDB(appId)
48
- const mockAppDB = context.getAppDB as Mock
49
- mockAppDB.mockReturnValue(appDb)
50
-
51
- await addAppMetadata()
42
+ console.debug(role)
52
43
  appDb.put(role)
44
+ await addAppMetadata()
45
+ await config.beforeAll()
53
46
  })
54
47
 
55
48
  afterAll(async () => {
@@ -64,14 +57,16 @@ describe("/api/global/roles", () => {
64
57
  it("retrieves roles", async () => {
65
58
  const res = await config.api.roles.get()
66
59
  expect(res.body).toBeDefined()
67
- expect(res.body[appId].roles.length).toEqual(5)
68
- expect(res.body[appId].roles.map((r: any) => r._id)).toContain(role._id)
60
+ expect(res.body["app_test"].roles.length).toEqual(5)
61
+ expect(res.body["app_test"].roles.map((r: any) => r._id)).toContain(
62
+ role._id
63
+ )
69
64
  })
70
65
  })
71
66
 
72
67
  describe("GET api/global/roles/:appId", () => {
73
68
  it("finds a role by appId", async () => {
74
- const res = await config.api.roles.find(appId)
69
+ const res = await config.api.roles.find("app_test")
75
70
  expect(res.body).toBeDefined()
76
71
  expect(res.body.name).toEqual("New App")
77
72
  })
@@ -84,9 +79,9 @@ describe("/api/global/roles", () => {
84
79
  app_test: "role1",
85
80
  }
86
81
  const userResponse = await config.createUser(user)
87
- const res = await config.api.roles.remove(appId)
82
+ const res = await config.api.roles.remove("app_test")
88
83
  const updatedUser = await config.api.users.getUser(userResponse._id!)
89
- expect(updatedUser.body.roles).not.toHaveProperty(appId)
84
+ expect(updatedUser.body.roles).not.toHaveProperty("app_test")
90
85
  expect(res.body.message).toEqual("App role removed from all users")
91
86
  })
92
87
  })
@@ -1,9 +1,14 @@
1
1
  import { InviteUsersResponse, User } from "@budibase/types"
2
2
 
3
3
  jest.mock("nodemailer")
4
- import { TestConfiguration, mocks, structures } from "../../../../tests"
4
+ import {
5
+ TestConfiguration,
6
+ mocks,
7
+ structures,
8
+ TENANT_1,
9
+ } from "../../../../tests"
5
10
  const sendMailMock = mocks.email.mock()
6
- import { context, events, tenancy } from "@budibase/backend-core"
11
+ import { events, tenancy } from "@budibase/backend-core"
7
12
 
8
13
  describe("/api/global/users", () => {
9
14
  const config = new TestConfiguration()
@@ -22,18 +27,16 @@ describe("/api/global/users", () => {
22
27
 
23
28
  describe("invite", () => {
24
29
  it("should be able to generate an invitation", async () => {
25
- await context.doInTenant(config.tenant1User!.tenantId, async () => {
26
- const email = structures.users.newEmail()
27
- const { code, res } = await config.api.users.sendUserInvite(
28
- sendMailMock,
29
- email
30
- )
31
-
32
- expect(res.body).toEqual({ message: "Invitation has been sent." })
33
- expect(sendMailMock).toHaveBeenCalled()
34
- expect(code).toBeDefined()
35
- expect(events.user.invited).toBeCalledTimes(1)
36
- })
30
+ const email = structures.users.newEmail()
31
+ const { code, res } = await config.api.users.sendUserInvite(
32
+ sendMailMock,
33
+ email
34
+ )
35
+
36
+ expect(res.body).toEqual({ message: "Invitation has been sent." })
37
+ expect(sendMailMock).toHaveBeenCalled()
38
+ expect(code).toBeDefined()
39
+ expect(events.user.invited).toBeCalledTimes(1)
37
40
  })
38
41
 
39
42
  it("should not be able to generate an invitation for existing user", async () => {
@@ -50,22 +53,20 @@ describe("/api/global/users", () => {
50
53
  })
51
54
 
52
55
  it("should be able to create new user from invite", async () => {
53
- await context.doInTenant(config.tenant1User!.tenantId, async () => {
54
- const email = structures.users.newEmail()
55
- const { code } = await config.api.users.sendUserInvite(
56
- sendMailMock,
57
- email
58
- )
59
-
60
- const res = await config.api.users.acceptInvite(code)
61
-
62
- expect(res.body._id).toBeDefined()
63
- const user = await config.getUser(email)
64
- expect(user).toBeDefined()
65
- expect(user._id).toEqual(res.body._id)
66
- expect(events.user.inviteAccepted).toBeCalledTimes(1)
67
- expect(events.user.inviteAccepted).toBeCalledWith(user)
68
- })
56
+ const email = structures.users.newEmail()
57
+ const { code } = await config.api.users.sendUserInvite(
58
+ sendMailMock,
59
+ email
60
+ )
61
+
62
+ const res = await config.api.users.acceptInvite(code)
63
+
64
+ expect(res.body._id).toBeDefined()
65
+ const user = await config.getUser(email)
66
+ expect(user).toBeDefined()
67
+ expect(user._id).toEqual(res.body._id)
68
+ expect(events.user.inviteAccepted).toBeCalledTimes(1)
69
+ expect(events.user.inviteAccepted).toBeCalledWith(user)
69
70
  })
70
71
  })
71
72
 
@@ -117,7 +118,7 @@ describe("/api/global/users", () => {
117
118
  const user = await config.createUser()
118
119
  jest.clearAllMocks()
119
120
 
120
- await tenancy.doInTenant(config.getTenantId(), async () => {
121
+ await tenancy.doInTenant(TENANT_1, async () => {
121
122
  const response = await config.api.users.bulkCreateUsers([user])
122
123
 
123
124
  expect(response.created?.successful.length).toBe(0)
@@ -230,7 +231,7 @@ describe("/api/global/users", () => {
230
231
  const user = await config.createUser()
231
232
  jest.clearAllMocks()
232
233
 
233
- await tenancy.doInTenant(config.getTenantId(), async () => {
234
+ await tenancy.doInTenant(TENANT_1, async () => {
234
235
  delete user._id
235
236
  const response = await config.api.users.saveUser(user, 400)
236
237
 
@@ -443,7 +444,7 @@ describe("/api/global/users", () => {
443
444
  })
444
445
 
445
446
  it("should not be able to update email address", async () => {
446
- const email = structures.email()
447
+ const email = "email@test.com"
447
448
  const user = await config.createUser(structures.users.user({ email }))
448
449
  user.email = "new@test.com"
449
450
 
package/src/index.ts CHANGED
@@ -1,13 +1,14 @@
1
- if (process.env.DD_APM_ENABLED) {
2
- require("./ddApm")
3
- }
1
+ // need to load environment first
2
+ import env from "./environment"
4
3
 
4
+ // enable APM if configured
5
5
  if (process.env.ELASTIC_APM_ENABLED) {
6
- require("./elasticApm")
6
+ const apm = require("elastic-apm-node").start({
7
+ serviceName: process.env.SERVICE,
8
+ environment: process.env.BUDIBASE_ENVIRONMENT,
9
+ })
7
10
  }
8
11
 
9
- // need to load environment first
10
- import env from "./environment"
11
12
  import { Scope } from "@sentry/node"
12
13
  import { Event } from "@sentry/types/dist/event"
13
14
  import Application from "koa"
@@ -264,6 +264,7 @@ export const save = async (
264
264
  builtUser._rev = response.rev
265
265
 
266
266
  await eventHelpers.handleSaveEvents(builtUser, dbUser)
267
+ await addTenant(tenantId, _id, email)
267
268
  await cache.user.invalidateUser(response.id)
268
269
 
269
270
  // let server know to sync user