@budibase/worker 2.3.20 → 2.3.21-alpha.0

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 (180) hide show
  1. package/__mocks__/node-fetch.ts +23 -0
  2. package/jest-testcontainers-config.js +8 -0
  3. package/jest.config.ts +14 -18
  4. package/package.json +12 -8
  5. package/scripts/dev/manage.js +1 -0
  6. package/scripts/test.sh +12 -0
  7. package/src/api/controllers/global/auth.ts +109 -111
  8. package/src/api/controllers/global/configs.ts +150 -142
  9. package/src/api/controllers/global/self.ts +28 -44
  10. package/src/api/controllers/global/users.ts +211 -32
  11. package/src/api/controllers/system/accounts.ts +7 -5
  12. package/src/api/controllers/system/tenants.ts +4 -8
  13. package/src/api/index.ts +4 -20
  14. package/src/api/routes/global/auth.ts +10 -7
  15. package/src/api/routes/global/configs.ts +6 -12
  16. package/src/api/routes/global/tests/auditLogs.spec.ts +111 -0
  17. package/src/api/routes/global/tests/auth.spec.ts +217 -18
  18. package/src/api/routes/global/tests/configs.spec.ts +93 -65
  19. package/src/api/routes/global/tests/realEmail.spec.ts +1 -0
  20. package/src/api/routes/global/tests/roles.spec.ts +20 -14
  21. package/src/api/routes/global/tests/self.spec.ts +3 -4
  22. package/src/api/routes/global/tests/users.spec.ts +29 -28
  23. package/src/api/routes/global/users.ts +19 -14
  24. package/src/api/routes/index.ts +3 -0
  25. package/src/api/routes/system/tenants.ts +1 -1
  26. package/src/api/routes/system/tests/accounts.spec.ts +4 -4
  27. package/src/api/routes/system/tests/migrations.spec.ts +2 -2
  28. package/src/api/routes/system/tests/restore.spec.ts +2 -2
  29. package/src/api/routes/system/tests/status.spec.ts +5 -5
  30. package/src/db/index.ts +8 -2
  31. package/src/ddApm.ts +7 -0
  32. package/src/elasticApm.ts +10 -0
  33. package/src/environment.ts +4 -0
  34. package/src/index.ts +29 -8
  35. package/src/middleware/tests/tenancy.spec.ts +4 -4
  36. package/src/migrations/functions/globalInfoSyncUsers.ts +4 -3
  37. package/src/sdk/accounts/index.ts +2 -1
  38. package/src/sdk/accounts/{accounts.ts → metadata.ts} +0 -1
  39. package/src/sdk/auth/auth.ts +86 -0
  40. package/src/sdk/auth/index.ts +1 -0
  41. package/src/sdk/tenants/index.ts +1 -0
  42. package/src/sdk/tenants/tenants.ts +76 -0
  43. package/src/sdk/users/events.ts +4 -0
  44. package/src/sdk/users/index.ts +1 -0
  45. package/src/sdk/users/tests/users.spec.ts +76 -0
  46. package/src/sdk/users/users.ts +86 -53
  47. package/src/tests/TestConfiguration.ts +41 -62
  48. package/src/tests/api/auditLogs.ts +26 -0
  49. package/src/tests/api/auth.ts +44 -14
  50. package/src/tests/api/base.ts +2 -1
  51. package/src/tests/api/configs.ts +9 -1
  52. package/src/tests/api/email.ts +1 -0
  53. package/src/tests/api/index.ts +3 -0
  54. package/src/tests/api/restore.ts +1 -0
  55. package/src/tests/api/users.ts +2 -2
  56. package/src/tests/jestEnv.ts +2 -1
  57. package/src/tests/jestSetup.ts +10 -6
  58. package/src/tests/logging.ts +34 -0
  59. package/src/tests/structures/configs.ts +20 -13
  60. package/src/tests/structures/index.ts +0 -4
  61. package/src/utilities/email.ts +22 -68
  62. package/src/utilities/redis.ts +42 -2
  63. package/src/utilities/templates.ts +4 -9
  64. package/coverage/clover.xml +0 -2199
  65. package/coverage/coverage-final.json +0 -84
  66. package/coverage/lcov-report/base.css +0 -224
  67. package/coverage/lcov-report/block-navigation.js +0 -87
  68. package/coverage/lcov-report/favicon.png +0 -0
  69. package/coverage/lcov-report/index.html +0 -431
  70. package/coverage/lcov-report/prettify.css +0 -1
  71. package/coverage/lcov-report/prettify.js +0 -2
  72. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  73. package/coverage/lcov-report/sorter.js +0 -196
  74. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +0 -934
  75. package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +0 -1348
  76. package/coverage/lcov-report/src/api/controllers/global/email.ts.html +0 -196
  77. package/coverage/lcov-report/src/api/controllers/global/events.ts.html +0 -136
  78. package/coverage/lcov-report/src/api/controllers/global/index.html +0 -251
  79. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +0 -187
  80. package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +0 -283
  81. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +0 -577
  82. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +0 -316
  83. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +0 -838
  84. package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +0 -244
  85. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +0 -148
  86. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +0 -124
  87. package/coverage/lcov-report/src/api/controllers/system/index.html +0 -191
  88. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +0 -124
  89. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +0 -124
  90. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +0 -133
  91. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +0 -154
  92. package/coverage/lcov-report/src/api/index.html +0 -116
  93. package/coverage/lcov-report/src/api/index.ts.html +0 -595
  94. package/coverage/lcov-report/src/api/routes/global/auth.ts.html +0 -349
  95. package/coverage/lcov-report/src/api/routes/global/configs.ts.html +0 -457
  96. package/coverage/lcov-report/src/api/routes/global/email.ts.html +0 -193
  97. package/coverage/lcov-report/src/api/routes/global/events.ts.html +0 -109
  98. package/coverage/lcov-report/src/api/routes/global/index.html +0 -251
  99. package/coverage/lcov-report/src/api/routes/global/license.ts.html +0 -124
  100. package/coverage/lcov-report/src/api/routes/global/roles.ts.html +0 -133
  101. package/coverage/lcov-report/src/api/routes/global/self.ts.html +0 -139
  102. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +0 -196
  103. package/coverage/lcov-report/src/api/routes/global/users.ts.html +0 -475
  104. package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +0 -196
  105. package/coverage/lcov-report/src/api/routes/index.html +0 -116
  106. package/coverage/lcov-report/src/api/routes/index.ts.html +0 -202
  107. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +0 -142
  108. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +0 -109
  109. package/coverage/lcov-report/src/api/routes/system/index.html +0 -191
  110. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +0 -142
  111. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +0 -109
  112. package/coverage/lcov-report/src/api/routes/system/status.ts.html +0 -109
  113. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +0 -124
  114. package/coverage/lcov-report/src/api/routes/validation/index.html +0 -131
  115. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +0 -88
  116. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +0 -235
  117. package/coverage/lcov-report/src/constants/index.html +0 -116
  118. package/coverage/lcov-report/src/constants/index.ts.html +0 -637
  119. package/coverage/lcov-report/src/constants/templates/index.html +0 -116
  120. package/coverage/lcov-report/src/constants/templates/index.ts.html +0 -316
  121. package/coverage/lcov-report/src/db/index.html +0 -116
  122. package/coverage/lcov-report/src/db/index.ts.html +0 -115
  123. package/coverage/lcov-report/src/environment.ts.html +0 -388
  124. package/coverage/lcov-report/src/index.html +0 -131
  125. package/coverage/lcov-report/src/index.ts.html +0 -394
  126. package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +0 -139
  127. package/coverage/lcov-report/src/middleware/index.html +0 -116
  128. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +0 -145
  129. package/coverage/lcov-report/src/migrations/functions/index.html +0 -116
  130. package/coverage/lcov-report/src/migrations/index.html +0 -116
  131. package/coverage/lcov-report/src/migrations/index.ts.html +0 -271
  132. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +0 -262
  133. package/coverage/lcov-report/src/sdk/accounts/index.html +0 -131
  134. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +0 -88
  135. package/coverage/lcov-report/src/sdk/index.html +0 -116
  136. package/coverage/lcov-report/src/sdk/index.ts.html +0 -106
  137. package/coverage/lcov-report/src/sdk/users/events.ts.html +0 -601
  138. package/coverage/lcov-report/src/sdk/users/index.html +0 -146
  139. package/coverage/lcov-report/src/sdk/users/index.ts.html +0 -88
  140. package/coverage/lcov-report/src/sdk/users/users.ts.html +0 -1999
  141. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +0 -1075
  142. package/coverage/lcov-report/src/tests/api/accounts.ts.html +0 -160
  143. package/coverage/lcov-report/src/tests/api/auth.ts.html +0 -220
  144. package/coverage/lcov-report/src/tests/api/base.ts.html +0 -133
  145. package/coverage/lcov-report/src/tests/api/configs.ts.html +0 -226
  146. package/coverage/lcov-report/src/tests/api/email.ts.html +0 -148
  147. package/coverage/lcov-report/src/tests/api/environment.ts.html +0 -130
  148. package/coverage/lcov-report/src/tests/api/groups.ts.html +0 -163
  149. package/coverage/lcov-report/src/tests/api/index.html +0 -356
  150. package/coverage/lcov-report/src/tests/api/index.ts.html +0 -238
  151. package/coverage/lcov-report/src/tests/api/license.ts.html +0 -136
  152. package/coverage/lcov-report/src/tests/api/migrations.ts.html +0 -151
  153. package/coverage/lcov-report/src/tests/api/restore.ts.html +0 -127
  154. package/coverage/lcov-report/src/tests/api/roles.ts.html +0 -181
  155. package/coverage/lcov-report/src/tests/api/self.ts.html +0 -163
  156. package/coverage/lcov-report/src/tests/api/status.ts.html +0 -121
  157. package/coverage/lcov-report/src/tests/api/templates.ts.html +0 -175
  158. package/coverage/lcov-report/src/tests/api/tenants.ts.html +0 -130
  159. package/coverage/lcov-report/src/tests/api/users.ts.html +0 -514
  160. package/coverage/lcov-report/src/tests/controllers.ts.html +0 -100
  161. package/coverage/lcov-report/src/tests/index.html +0 -146
  162. package/coverage/lcov-report/src/tests/index.ts.html +0 -103
  163. package/coverage/lcov-report/src/tests/mocks/email.ts.html +0 -115
  164. package/coverage/lcov-report/src/tests/mocks/index.html +0 -131
  165. package/coverage/lcov-report/src/tests/mocks/index.ts.html +0 -106
  166. package/coverage/lcov-report/src/tests/structures/configs.ts.html +0 -313
  167. package/coverage/lcov-report/src/tests/structures/groups.ts.html +0 -118
  168. package/coverage/lcov-report/src/tests/structures/index.html +0 -161
  169. package/coverage/lcov-report/src/tests/structures/index.ts.html +0 -151
  170. package/coverage/lcov-report/src/tests/structures/users.ts.html +0 -196
  171. package/coverage/lcov-report/src/utilities/appService.ts.html +0 -208
  172. package/coverage/lcov-report/src/utilities/email.ts.html +0 -850
  173. package/coverage/lcov-report/src/utilities/fileSystem.ts.html +0 -100
  174. package/coverage/lcov-report/src/utilities/index.html +0 -206
  175. package/coverage/lcov-report/src/utilities/index.ts.html +0 -112
  176. package/coverage/lcov-report/src/utilities/redis.ts.html +0 -424
  177. package/coverage/lcov-report/src/utilities/templates.ts.html +0 -232
  178. package/coverage/lcov-report/src/utilities/users.ts.html +0 -133
  179. package/coverage/lcov.info +0 -4187
  180. package/src/tests/structures/users.ts +0 -37
@@ -15,39 +15,29 @@ const supertest = require("supertest")
15
15
  import { Config } from "../constants"
16
16
  import {
17
17
  users,
18
- tenancy,
18
+ context,
19
19
  sessions,
20
20
  auth,
21
21
  constants,
22
22
  env as coreEnv,
23
23
  } from "@budibase/backend-core"
24
- import structures, { TENANT_ID, TENANT_1, CSRF_TOKEN } from "./structures"
25
- import { CreateUserResponse, User, AuthToken } from "@budibase/types"
24
+ import structures, { CSRF_TOKEN } from "./structures"
25
+ import { SaveUserResponse, User, AuthToken } from "@budibase/types"
26
26
  import API from "./api"
27
27
 
28
- enum Mode {
29
- CLOUD = "cloud",
30
- SELF = "self",
31
- }
32
-
33
28
  class TestConfiguration {
34
29
  server: any
35
30
  request: any
36
31
  api: API
37
- defaultUser?: User
38
- tenant1User?: User
32
+ tenantId: string
33
+ user?: User
34
+ userPassword = "test"
39
35
 
40
- constructor(
41
- opts: { openServer: boolean; mode: Mode } = {
42
- openServer: true,
43
- mode: Mode.CLOUD,
44
- }
45
- ) {
46
- if (opts.mode === Mode.CLOUD) {
47
- this.modeCloud()
48
- } else if (opts.mode === Mode.SELF) {
49
- this.modeSelf()
50
- }
36
+ constructor(opts: { openServer: boolean } = { openServer: true }) {
37
+ // default to cloud hosting
38
+ this.cloudHosted()
39
+
40
+ this.tenantId = structures.tenant.id()
51
41
 
52
42
  if (opts.openServer) {
53
43
  env.PORT = "0" // random port
@@ -63,26 +53,19 @@ class TestConfiguration {
63
53
  return this.request
64
54
  }
65
55
 
66
- // MODES
67
-
68
- setMultiTenancy = (value: boolean) => {
69
- env._set("MULTI_TENANCY", value)
70
- coreEnv._set("MULTI_TENANCY", value)
71
- }
56
+ // HOSTING
72
57
 
73
58
  setSelfHosted = (value: boolean) => {
74
59
  env._set("SELF_HOSTED", value)
75
60
  coreEnv._set("SELF_HOSTED", value)
76
61
  }
77
62
 
78
- modeCloud = () => {
63
+ cloudHosted = () => {
79
64
  this.setSelfHosted(false)
80
- this.setMultiTenancy(true)
81
65
  }
82
66
 
83
- modeSelf = () => {
67
+ selfHosted = () => {
84
68
  this.setSelfHosted(true)
85
- this.setMultiTenancy(false)
86
69
  }
87
70
 
88
71
  // UTILS
@@ -103,7 +86,7 @@ class TestConfiguration {
103
86
  if (params) {
104
87
  request.params = params
105
88
  }
106
- await tenancy.doInTenant(this.getTenantId(), () => {
89
+ await context.doInTenant(this.getTenantId(), () => {
107
90
  return controlFunc(request)
108
91
  })
109
92
  return request.body
@@ -112,13 +95,13 @@ class TestConfiguration {
112
95
  // SETUP / TEARDOWN
113
96
 
114
97
  async beforeAll() {
115
- await this.createDefaultUser()
116
- await this.createSession(this.defaultUser!)
117
-
118
- await tenancy.doInTenant(TENANT_1, async () => {
119
- await this.createTenant1User()
120
- await this.createSession(this.tenant1User!)
121
- })
98
+ try {
99
+ await this.createDefaultUser()
100
+ await this.createSession(this.user!)
101
+ } catch (e: any) {
102
+ console.error(e)
103
+ throw new Error(e.message)
104
+ }
122
105
  }
123
106
 
124
107
  async afterAll() {
@@ -129,6 +112,12 @@ class TestConfiguration {
129
112
 
130
113
  // TENANCY
131
114
 
115
+ doInTenant(task: any) {
116
+ return context.doInTenant(this.tenantId, () => {
117
+ return task()
118
+ })
119
+ }
120
+
132
121
  createTenant = async (): Promise<User> => {
133
122
  // create user / new tenant
134
123
  const res = await this.api.users.createAdminUser()
@@ -150,9 +139,9 @@ class TestConfiguration {
150
139
 
151
140
  getTenantId() {
152
141
  try {
153
- return tenancy.getTenantId()
154
- } catch (e: any) {
155
- return TENANT_ID
142
+ return context.getTenantId()
143
+ } catch (e) {
144
+ return this.tenantId!
156
145
  }
157
146
  }
158
147
 
@@ -200,14 +189,11 @@ class TestConfiguration {
200
189
  }
201
190
 
202
191
  defaultHeaders() {
203
- const tenantId = this.getTenantId()
204
- if (tenantId === TENANT_ID) {
205
- return this.authHeaders(this.defaultUser!)
206
- } else if (tenantId === TENANT_1) {
207
- return this.authHeaders(this.tenant1User!)
208
- } else {
209
- throw new Error("could not determine auth headers to use")
210
- }
192
+ return this.authHeaders(this.user!)
193
+ }
194
+
195
+ tenantIdHeaders() {
196
+ return { [constants.Header.TENANT_ID]: this.tenantId }
211
197
  }
212
198
 
213
199
  internalAPIHeaders() {
@@ -222,22 +208,15 @@ class TestConfiguration {
222
208
 
223
209
  async createDefaultUser() {
224
210
  const user = structures.users.adminUser({
225
- email: "test@test.com",
226
- password: "test",
211
+ password: this.userPassword,
227
212
  })
228
- this.defaultUser = await this.createUser(user)
229
- }
230
-
231
- async createTenant1User() {
232
- const user = structures.users.adminUser({
233
- email: "tenant1@test.com",
234
- password: "test",
213
+ await context.doInTenant(this.tenantId!, async () => {
214
+ this.user = await this.createUser(user)
235
215
  })
236
- this.tenant1User = await this.createUser(user)
237
216
  }
238
217
 
239
218
  async getUser(email: string): Promise<User> {
240
- return tenancy.doInTenant(this.getTenantId(), () => {
219
+ return context.doInTenant(this.getTenantId(), () => {
241
220
  return users.getGlobalUserByEmail(email)
242
221
  })
243
222
  }
@@ -247,7 +226,7 @@ class TestConfiguration {
247
226
  user = structures.users.user()
248
227
  }
249
228
  const response = await this._req(user, null, controllers.users.save)
250
- const body = response as CreateUserResponse
229
+ const body = response as SaveUserResponse
251
230
  return this.getUser(body.email)
252
231
  }
253
232
 
@@ -0,0 +1,26 @@
1
+ import { AuditLogSearchParams, SearchAuditLogsResponse } from "@budibase/types"
2
+ import TestConfiguration from "../TestConfiguration"
3
+ import { TestAPI } from "./base"
4
+
5
+ export class AuditLogAPI extends TestAPI {
6
+ constructor(config: TestConfiguration) {
7
+ super(config)
8
+ }
9
+
10
+ search = async (search: AuditLogSearchParams) => {
11
+ const res = await this.request
12
+ .post("/api/global/auditlogs/search")
13
+ .send(search)
14
+ .set(this.config.defaultHeaders())
15
+ .expect("Content-Type", /json/)
16
+ .expect(200)
17
+ return res.body as SearchAuditLogsResponse
18
+ }
19
+
20
+ download = (search: AuditLogSearchParams) => {
21
+ const query = encodeURIComponent(JSON.stringify(search))
22
+ return this.request
23
+ .get(`/api/global/auditlogs/download?query=${query}`)
24
+ .set(this.config.defaultHeaders())
25
+ }
26
+ }
@@ -1,20 +1,39 @@
1
1
  import TestConfiguration from "../TestConfiguration"
2
- import { TestAPI } from "./base"
2
+ import { TestAPI, TestAPIOpts } from "./base"
3
3
 
4
4
  export class AuthAPI extends TestAPI {
5
5
  constructor(config: TestConfiguration) {
6
6
  super(config)
7
7
  }
8
8
 
9
- updatePassword = (code: string) => {
9
+ updatePassword = (
10
+ resetCode: string,
11
+ password: string,
12
+ opts?: TestAPIOpts
13
+ ) => {
10
14
  return this.request
11
15
  .post(`/api/global/auth/${this.config.getTenantId()}/reset/update`)
12
16
  .send({
13
- password: "newpassword",
14
- resetCode: code,
17
+ password,
18
+ resetCode,
15
19
  })
16
20
  .expect("Content-Type", /json/)
17
- .expect(200)
21
+ .expect(opts?.status ? opts.status : 200)
22
+ }
23
+
24
+ login = (
25
+ tenantId: string,
26
+ email: string,
27
+ password: string,
28
+ opts?: TestAPIOpts
29
+ ) => {
30
+ return this.request
31
+ .post(`/api/global/auth/${tenantId}/login`)
32
+ .send({
33
+ username: email,
34
+ password: password,
35
+ })
36
+ .expect(opts?.status ? opts.status : 200)
18
37
  }
19
38
 
20
39
  logout = () => {
@@ -24,22 +43,33 @@ export class AuthAPI extends TestAPI {
24
43
  .expect(200)
25
44
  }
26
45
 
27
- requestPasswordReset = async (sendMailMock: any) => {
46
+ requestPasswordReset = async (
47
+ sendMailMock: any,
48
+ email: string,
49
+ opts?: TestAPIOpts
50
+ ) => {
28
51
  await this.config.saveSmtpConfig()
29
52
  await this.config.saveSettingsConfig()
30
- await this.config.createUser()
53
+
31
54
  const res = await this.request
32
55
  .post(`/api/global/auth/${this.config.getTenantId()}/reset`)
33
56
  .send({
34
- email: "test@test.com",
57
+ email: email,
35
58
  })
36
59
  .expect("Content-Type", /json/)
37
- .expect(200)
38
- const emailCall = sendMailMock.mock.calls[0][0]
39
- const parts = emailCall.html.split(
40
- `http://localhost:10000/builder/auth/reset?code=`
41
- )
42
- const code = parts[1].split('"')[0].split("&")[0]
60
+ .expect(opts?.status ? opts.status : 200)
61
+
62
+ let code: string | undefined
63
+ if (res.status === 200) {
64
+ if (sendMailMock.mock.calls.length) {
65
+ const emailCall = sendMailMock.mock.calls[0][0]
66
+ const parts = emailCall.html.split(
67
+ `http://localhost:10000/builder/auth/reset?code=`
68
+ )
69
+ code = parts[1].split('"')[0].split("&")[0]
70
+ }
71
+ }
72
+
43
73
  return { code, res }
44
74
  }
45
75
  }
@@ -1,4 +1,5 @@
1
1
  import TestConfiguration from "../TestConfiguration"
2
+ import { SuperTest, Test } from "supertest"
2
3
 
3
4
  export interface TestAPIOpts {
4
5
  headers?: any
@@ -7,7 +8,7 @@ export interface TestAPIOpts {
7
8
 
8
9
  export abstract class TestAPI {
9
10
  config: TestConfiguration
10
- request: any
11
+ request: SuperTest<Test>
11
12
 
12
13
  protected constructor(config: TestConfiguration) {
13
14
  this.config = config
@@ -10,8 +10,16 @@ export class ConfigAPI extends TestAPI {
10
10
  return this.request
11
11
  .get(`/api/global/configs/checklist`)
12
12
  .set(this.config.defaultHeaders())
13
+ .expect(200)
13
14
  .expect("Content-Type", /json/)
15
+ }
16
+
17
+ getPublicSettings = () => {
18
+ return this.request
19
+ .get(`/api/global/configs/public`)
20
+ .set(this.config.defaultHeaders())
14
21
  .expect(200)
22
+ .expect("Content-Type", /json/)
15
23
  }
16
24
 
17
25
  saveConfig = (data: any) => {
@@ -19,8 +27,8 @@ export class ConfigAPI extends TestAPI {
19
27
  .post(`/api/global/configs`)
20
28
  .send(data)
21
29
  .set(this.config.defaultHeaders())
22
- .expect("Content-Type", /json/)
23
30
  .expect(200)
31
+ .expect("Content-Type", /json/)
24
32
  }
25
33
 
26
34
  OIDCCallback = (configId: string, preAuthRes: any) => {
@@ -13,6 +13,7 @@ export class EmailAPI extends TestAPI {
13
13
  email: "test@test.com",
14
14
  purpose,
15
15
  tenantId: this.config.getTenantId(),
16
+ userId: this.config.user?._id!,
16
17
  })
17
18
  .set(this.config.defaultHeaders())
18
19
  .expect("Content-Type", /json/)
@@ -14,6 +14,7 @@ import { GroupsAPI } from "./groups"
14
14
  import { RolesAPI } from "./roles"
15
15
  import { TemplatesAPI } from "./templates"
16
16
  import { LicenseAPI } from "./license"
17
+ import { AuditLogAPI } from "./auditLogs"
17
18
  export default class API {
18
19
  accounts: AccountAPI
19
20
  auth: AuthAPI
@@ -30,6 +31,7 @@ export default class API {
30
31
  roles: RolesAPI
31
32
  templates: TemplatesAPI
32
33
  license: LicenseAPI
34
+ auditLogs: AuditLogAPI
33
35
 
34
36
  constructor(config: TestConfiguration) {
35
37
  this.accounts = new AccountAPI(config)
@@ -47,5 +49,6 @@ export default class API {
47
49
  this.roles = new RolesAPI(config)
48
50
  this.templates = new TemplatesAPI(config)
49
51
  this.license = new LicenseAPI(config)
52
+ this.auditLogs = new AuditLogAPI(config)
50
53
  }
51
54
  }
@@ -9,6 +9,7 @@ export class RestoreAPI extends TestAPI {
9
9
  restored = (opts?: TestAPIOpts) => {
10
10
  return this.request
11
11
  .post(`/api/system/restored`)
12
+ .set(this.config.tenantIdHeaders())
12
13
  .expect(opts?.status ? opts.status : 200)
13
14
  }
14
15
  }
@@ -26,8 +26,8 @@ export class UserAPI extends TestAPI {
26
26
  email,
27
27
  })
28
28
  .set(this.config.defaultHeaders())
29
- .expect("Content-Type", /json/)
30
29
  .expect(status)
30
+ .expect("Content-Type", /json/)
31
31
 
32
32
  if (status !== 200) {
33
33
  return { code: undefined, res }
@@ -100,7 +100,7 @@ export class UserAPI extends TestAPI {
100
100
  request = {
101
101
  email: structures.email(),
102
102
  password: generator.string(),
103
- tenantId: structures.uuid(),
103
+ tenantId: structures.tenant.id(),
104
104
  }
105
105
  }
106
106
  const res = await this.request
@@ -1,7 +1,8 @@
1
1
  process.env.SELF_HOSTED = "0"
2
2
  process.env.NODE_ENV = "jest"
3
3
  process.env.JWT_SECRET = "test-jwtsecret"
4
- process.env.LOG_LEVEL = "silent"
4
+ process.env.LOG_LEVEL = process.env.LOG_LEVEL || "error"
5
+ process.env.ENABLE_4XX_HTTP_LOGGING = "0"
5
6
  process.env.MULTI_TENANCY = "1"
6
7
  process.env.MINIO_URL = "http://localhost"
7
8
  process.env.MINIO_ACCESS_KEY = "test"
@@ -1,4 +1,8 @@
1
- import { mocks } from "@budibase/backend-core/tests"
1
+ import "./logging"
2
+
3
+ import { mocks, testContainerUtils } from "@budibase/backend-core/tests"
4
+ import env from "../environment"
5
+ import { env as coreEnv } from "@budibase/backend-core"
2
6
 
3
7
  // must explicitly enable fetch mock
4
8
  mocks.fetch.enable()
@@ -8,12 +12,12 @@ mocks.fetch.enable()
8
12
  const tk = require("timekeeper")
9
13
  tk.freeze(mocks.date.MOCK_DATE)
10
14
 
11
- if (!process.env.DEBUG) {
12
- global.console.log = jest.fn() // console.log are ignored in tests
13
- }
14
-
15
15
  if (!process.env.CI) {
16
16
  // set a longer timeout in dev for debugging
17
17
  // 100 seconds
18
- jest.setTimeout(100000)
18
+ jest.setTimeout(100 * 1000)
19
+ } else {
20
+ jest.setTimeout(10 * 1000)
19
21
  }
22
+
23
+ testContainerUtils.setupEnv(env, coreEnv)
@@ -0,0 +1,34 @@
1
+ export enum LogLevel {
2
+ TRACE = "trace",
3
+ DEBUG = "debug",
4
+ INFO = "info",
5
+ WARN = "warn",
6
+ ERROR = "error",
7
+ }
8
+
9
+ const LOG_INDEX: { [key in LogLevel]: number } = {
10
+ [LogLevel.TRACE]: 1,
11
+ [LogLevel.DEBUG]: 2,
12
+ [LogLevel.INFO]: 3,
13
+ [LogLevel.WARN]: 4,
14
+ [LogLevel.ERROR]: 5,
15
+ }
16
+
17
+ const setIndex = LOG_INDEX[process.env.LOG_LEVEL as LogLevel]
18
+
19
+ if (setIndex > LOG_INDEX.trace) {
20
+ global.console.trace = jest.fn()
21
+ }
22
+
23
+ if (setIndex > LOG_INDEX.debug) {
24
+ global.console.debug = jest.fn()
25
+ }
26
+
27
+ if (setIndex > LOG_INDEX.info) {
28
+ global.console.info = jest.fn()
29
+ global.console.log = jest.fn()
30
+ }
31
+
32
+ if (setIndex > LOG_INDEX.warn) {
33
+ global.console.warn = jest.fn()
34
+ }
@@ -1,9 +1,15 @@
1
- import { Config } from "../../constants"
2
1
  import { utils } from "@budibase/backend-core"
2
+ import {
3
+ SettingsConfig,
4
+ ConfigType,
5
+ SMTPConfig,
6
+ GoogleConfig,
7
+ OIDCConfig,
8
+ } from "@budibase/types"
3
9
 
4
- export function oidc(conf?: any) {
10
+ export function oidc(conf?: any): OIDCConfig {
5
11
  return {
6
- type: Config.OIDC,
12
+ type: ConfigType.OIDC,
7
13
  config: {
8
14
  configs: [
9
15
  {
@@ -21,9 +27,9 @@ export function oidc(conf?: any) {
21
27
  }
22
28
  }
23
29
 
24
- export function google(conf?: any) {
30
+ export function google(conf?: any): GoogleConfig {
25
31
  return {
26
- type: Config.GOOGLE,
32
+ type: ConfigType.GOOGLE,
27
33
  config: {
28
34
  clientID: "clientId",
29
35
  clientSecret: "clientSecret",
@@ -33,9 +39,9 @@ export function google(conf?: any) {
33
39
  }
34
40
  }
35
41
 
36
- export function smtp(conf?: any) {
42
+ export function smtp(conf?: any): SMTPConfig {
37
43
  return {
38
- type: Config.SMTP,
44
+ type: ConfigType.SMTP,
39
45
  config: {
40
46
  port: 12345,
41
47
  host: "smtptesthost.com",
@@ -47,25 +53,26 @@ export function smtp(conf?: any) {
47
53
  }
48
54
  }
49
55
 
50
- export function smtpEthereal() {
56
+ export function smtpEthereal(): SMTPConfig {
51
57
  return {
52
- type: Config.SMTP,
58
+ type: ConfigType.SMTP,
53
59
  config: {
54
60
  port: 587,
55
61
  host: "smtp.ethereal.email",
62
+ from: "testfrom@test.com",
56
63
  secure: false,
57
64
  auth: {
58
- user: "don.bahringer@ethereal.email",
59
- pass: "yCKSH8rWyUPbnhGYk9",
65
+ user: "wyatt.zulauf29@ethereal.email",
66
+ pass: "tEwDtHBWWxusVWAPfa",
60
67
  },
61
68
  connectionTimeout: 1000, // must be less than the jest default of 5000
62
69
  },
63
70
  }
64
71
  }
65
72
 
66
- export function settings(conf?: any) {
73
+ export function settings(conf?: any): SettingsConfig {
67
74
  return {
68
- type: Config.SETTINGS,
75
+ type: ConfigType.SETTINGS,
69
76
  config: {
70
77
  platformUrl: "http://localhost:10000",
71
78
  logoUrl: "",
@@ -1,20 +1,16 @@
1
1
  import { structures } from "@budibase/backend-core/tests"
2
2
  import * as configs from "./configs"
3
- import * as users from "./users"
4
3
  import * as groups from "./groups"
5
4
  import { v4 as uuid } from "uuid"
6
5
 
7
6
  export const TENANT_ID = "default"
8
- export const TENANT_1 = "tenant1"
9
7
  export const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
10
8
 
11
9
  const pkg = {
12
10
  ...structures,
13
11
  uuid,
14
12
  configs,
15
- users,
16
13
  TENANT_ID,
17
- TENANT_1,
18
14
  CSRF_TOKEN,
19
15
  groups,
20
16
  }