@budibase/worker 2.3.16 → 2.3.17-alpha.1

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