@budibase/worker 2.3.17-alpha.3 → 2.3.17-alpha.5

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 (43) hide show
  1. package/package.json +8 -7
  2. package/scripts/dev/manage.js +1 -0
  3. package/src/api/controllers/global/auth.ts +77 -70
  4. package/src/api/controllers/global/self.ts +28 -44
  5. package/src/api/controllers/global/users.ts +65 -25
  6. package/src/api/controllers/system/accounts.ts +7 -5
  7. package/src/api/controllers/system/tenants.ts +4 -8
  8. package/src/api/index.ts +4 -20
  9. package/src/api/routes/global/auth.ts +10 -7
  10. package/src/api/routes/global/tests/auth.spec.ts +234 -33
  11. package/src/api/routes/global/tests/configs.spec.ts +93 -113
  12. package/src/api/routes/global/tests/roles.spec.ts +3 -2
  13. package/src/api/routes/global/tests/self.spec.ts +3 -4
  14. package/src/api/routes/global/tests/users.spec.ts +44 -46
  15. package/src/api/routes/system/tenants.ts +1 -1
  16. package/src/api/routes/system/tests/accounts.spec.ts +4 -4
  17. package/src/api/routes/system/tests/migrations.spec.ts +2 -2
  18. package/src/api/routes/system/tests/restore.spec.ts +2 -2
  19. package/src/api/routes/system/tests/status.spec.ts +5 -5
  20. package/src/environment.ts +15 -1
  21. package/src/index.ts +6 -0
  22. package/src/middleware/tests/tenancy.spec.ts +4 -4
  23. package/src/migrations/functions/globalInfoSyncUsers.ts +4 -3
  24. package/src/sdk/accounts/index.ts +2 -1
  25. package/src/sdk/accounts/{accounts.ts → metadata.ts} +0 -1
  26. package/src/sdk/auth/auth.ts +86 -0
  27. package/src/sdk/auth/index.ts +1 -0
  28. package/src/sdk/tenants/index.ts +1 -0
  29. package/src/sdk/tenants/tenants.ts +76 -0
  30. package/src/sdk/users/events.ts +4 -0
  31. package/src/sdk/users/index.ts +1 -0
  32. package/src/sdk/users/tests/users.spec.ts +52 -0
  33. package/src/sdk/users/users.ts +53 -46
  34. package/src/tests/TestConfiguration.ts +38 -89
  35. package/src/tests/api/auth.ts +42 -18
  36. package/src/tests/api/base.ts +2 -1
  37. package/src/tests/api/restore.ts +1 -0
  38. package/src/tests/jestEnv.ts +2 -1
  39. package/src/tests/jestSetup.ts +2 -5
  40. package/src/tests/logging.ts +34 -0
  41. package/src/tests/structures/index.ts +0 -2
  42. package/src/utilities/email.ts +3 -3
  43. package/src/tests/structures/users.ts +0 -37
@@ -2,7 +2,7 @@
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()
@@ -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.selfHosted()
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.cloudHosted()
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.selfHosted()
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.cloudHosted()
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
  })
@@ -32,6 +32,7 @@ async function addAppMetadata() {
32
32
 
33
33
  describe("/api/global/roles", () => {
34
34
  const config = new TestConfiguration()
35
+
35
36
  const role = new roles.Role(
36
37
  db.generateRoleID("newRole"),
37
38
  roles.BUILTIN_ROLE_IDS.BASIC,
@@ -43,13 +44,13 @@ describe("/api/global/roles", () => {
43
44
  })
44
45
 
45
46
  beforeEach(async () => {
46
- appId = db.generateAppID()
47
+ appId = db.generateAppID(config.tenantId)
47
48
  appDb = db.getDB(appId)
48
49
  const mockAppDB = context.getAppDB as Mock
49
50
  mockAppDB.mockReturnValue(appDb)
50
51
 
51
52
  await addAppMetadata()
52
- appDb.put(role)
53
+ await appDb.put(role)
53
54
  })
54
55
 
55
56
  afterAll(async () => {
@@ -30,7 +30,7 @@ describe("/api/global/self", () => {
30
30
  user.dayPassRecordedAt = mocks.date.MOCK_DATE.toISOString()
31
31
  expect(res.body._id).toBe(user._id)
32
32
  expect(events.user.updated).toBeCalledTimes(1)
33
- expect(events.user.updated).toBeCalledWith(user)
33
+ expect(events.user.updated).toBeCalledWith(dbUser)
34
34
  expect(events.user.passwordUpdated).not.toBeCalled()
35
35
  })
36
36
 
@@ -44,12 +44,11 @@ describe("/api/global/self", () => {
44
44
  const dbUser = await config.getUser(user.email)
45
45
  user._rev = dbUser._rev
46
46
  user.dayPassRecordedAt = mocks.date.MOCK_DATE.toISOString()
47
- delete user.password
48
47
  expect(res.body._id).toBe(user._id)
49
48
  expect(events.user.updated).toBeCalledTimes(1)
50
- expect(events.user.updated).toBeCalledWith(user)
49
+ expect(events.user.updated).toBeCalledWith(dbUser)
51
50
  expect(events.user.passwordUpdated).toBeCalledTimes(1)
52
- expect(events.user.passwordUpdated).toBeCalledWith(user)
51
+ expect(events.user.passwordUpdated).toBeCalledWith(dbUser)
53
52
  })
54
53
  })
55
54
  })
@@ -3,7 +3,9 @@ import { InviteUsersResponse, User } from "@budibase/types"
3
3
  jest.mock("nodemailer")
4
4
  import { TestConfiguration, mocks, structures } from "../../../../tests"
5
5
  const sendMailMock = mocks.email.mock()
6
- import { context, events, tenancy } from "@budibase/backend-core"
6
+ import { events, tenancy, accounts as _accounts } from "@budibase/backend-core"
7
+
8
+ const accounts = jest.mocked(_accounts)
7
9
 
8
10
  describe("/api/global/users", () => {
9
11
  const config = new TestConfiguration()
@@ -20,26 +22,24 @@ describe("/api/global/users", () => {
20
22
  jest.clearAllMocks()
21
23
  })
22
24
 
23
- describe("invite", () => {
25
+ describe("POST /api/global/users/invite", () => {
24
26
  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
- })
27
+ const email = structures.users.newEmail()
28
+ const { code, res } = await config.api.users.sendUserInvite(
29
+ sendMailMock,
30
+ email
31
+ )
32
+
33
+ expect(res.body).toEqual({ message: "Invitation has been sent." })
34
+ expect(sendMailMock).toHaveBeenCalled()
35
+ expect(code).toBeDefined()
36
+ expect(events.user.invited).toBeCalledTimes(1)
37
37
  })
38
38
 
39
39
  it("should not be able to generate an invitation for existing user", async () => {
40
40
  const { code, res } = await config.api.users.sendUserInvite(
41
41
  sendMailMock,
42
- config.defaultUser!.email,
42
+ config.user!.email,
43
43
  400
44
44
  )
45
45
 
@@ -50,26 +50,24 @@ describe("/api/global/users", () => {
50
50
  })
51
51
 
52
52
  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
- })
53
+ const email = structures.users.newEmail()
54
+ const { code } = await config.api.users.sendUserInvite(
55
+ sendMailMock,
56
+ email
57
+ )
58
+
59
+ const res = await config.api.users.acceptInvite(code)
60
+
61
+ expect(res.body._id).toBeDefined()
62
+ const user = await config.getUser(email)
63
+ expect(user).toBeDefined()
64
+ expect(user._id).toEqual(res.body._id)
65
+ expect(events.user.inviteAccepted).toBeCalledTimes(1)
66
+ expect(events.user.inviteAccepted).toBeCalledWith(user)
69
67
  })
70
68
  })
71
69
 
72
- describe("inviteMultiple", () => {
70
+ describe("POST /api/global/users/multi/invite", () => {
73
71
  it("should be able to generate an invitation", async () => {
74
72
  const newUserInvite = () => ({
75
73
  email: structures.users.newEmail(),
@@ -87,7 +85,7 @@ describe("/api/global/users", () => {
87
85
  })
88
86
 
89
87
  it("should not be able to generate an invitation for existing user", async () => {
90
- const request = [{ email: config.defaultUser!.email, userInfo: {} }]
88
+ const request = [{ email: config.user!.email, userInfo: {} }]
91
89
 
92
90
  const res = await config.api.users.sendMultiUserInvite(request)
93
91
 
@@ -100,7 +98,7 @@ describe("/api/global/users", () => {
100
98
  })
101
99
  })
102
100
 
103
- describe("bulk (create)", () => {
101
+ describe("POST /api/global/users/bulk", () => {
104
102
  it("should ignore users existing in the same tenant", async () => {
105
103
  const user = await config.createUser()
106
104
  jest.clearAllMocks()
@@ -163,7 +161,7 @@ describe("/api/global/users", () => {
163
161
  })
164
162
  })
165
163
 
166
- describe("create", () => {
164
+ describe("POST /api/global/users", () => {
167
165
  it("should be able to create a basic user", async () => {
168
166
  const user = structures.users.user()
169
167
 
@@ -242,7 +240,7 @@ describe("/api/global/users", () => {
242
240
  it("should not be able to create user with the same email as an account", async () => {
243
241
  const user = structures.users.user()
244
242
  const account = structures.accounts.cloudAccount()
245
- mocks.accounts.getAccount.mockReturnValueOnce(account)
243
+ accounts.getAccount.mockReturnValueOnce(Promise.resolve(account))
246
244
 
247
245
  const response = await config.api.users.saveUser(user, 400)
248
246
 
@@ -283,7 +281,7 @@ describe("/api/global/users", () => {
283
281
  })
284
282
  })
285
283
 
286
- describe("update", () => {
284
+ describe("POST /api/global/users (update)", () => {
287
285
  it("should be able to update a basic user", async () => {
288
286
  const user = await config.createUser()
289
287
  jest.clearAllMocks()
@@ -298,7 +296,7 @@ describe("/api/global/users", () => {
298
296
  })
299
297
 
300
298
  it("should not allow a user to update their own admin/builder status", async () => {
301
- const user = (await config.api.users.getUser(config.defaultUser?._id!))
299
+ const user = (await config.api.users.getUser(config.user?._id!))
302
300
  .body as User
303
301
  await config.api.users.saveUser({
304
302
  ...user,
@@ -468,9 +466,9 @@ describe("/api/global/users", () => {
468
466
  })
469
467
  })
470
468
 
471
- describe("bulk (delete)", () => {
469
+ describe("POST /api/global/users/bulk (delete)", () => {
472
470
  it("should not be able to bulk delete current user", async () => {
473
- const user = await config.defaultUser!
471
+ const user = await config.user!
474
472
 
475
473
  const response = await config.api.users.bulkDeleteUsers([user._id!], 400)
476
474
 
@@ -482,7 +480,7 @@ describe("/api/global/users", () => {
482
480
  const user = await config.createUser()
483
481
  const account = structures.accounts.cloudAccount()
484
482
  account.budibaseUserId = user._id!
485
- mocks.accounts.getAccountByTenantId.mockReturnValue(account)
483
+ accounts.getAccountByTenantId.mockReturnValue(Promise.resolve(account))
486
484
 
487
485
  const response = await config.api.users.bulkDeleteUsers([user._id!])
488
486
 
@@ -497,7 +495,7 @@ describe("/api/global/users", () => {
497
495
 
498
496
  it("should be able to bulk delete users", async () => {
499
497
  const account = structures.accounts.cloudAccount()
500
- mocks.accounts.getAccountByTenantId.mockReturnValue(account)
498
+ accounts.getAccountByTenantId.mockReturnValue(Promise.resolve(account))
501
499
 
502
500
  const builder = structures.users.builderUser()
503
501
  const admin = structures.users.adminUser()
@@ -521,7 +519,7 @@ describe("/api/global/users", () => {
521
519
  })
522
520
  })
523
521
 
524
- describe("destroy", () => {
522
+ describe("DELETE /api/global/users/:userId", () => {
525
523
  it("should be able to destroy a basic user", async () => {
526
524
  const user = await config.createUser()
527
525
  jest.clearAllMocks()
@@ -558,7 +556,7 @@ describe("/api/global/users", () => {
558
556
  it("should not be able to destroy account owner", async () => {
559
557
  const user = await config.createUser()
560
558
  const account = structures.accounts.cloudAccount()
561
- mocks.accounts.getAccount.mockReturnValueOnce(account)
559
+ accounts.getAccount.mockReturnValueOnce(Promise.resolve(account))
562
560
 
563
561
  const response = await config.api.users.deleteUser(user._id!, 400)
564
562
 
@@ -566,10 +564,10 @@ describe("/api/global/users", () => {
566
564
  })
567
565
 
568
566
  it("should not be able to destroy account owner as account owner", async () => {
569
- const user = await config.defaultUser!
567
+ const user = await config.user!
570
568
  const account = structures.accounts.cloudAccount()
571
569
  account.email = user.email
572
- mocks.accounts.getAccount.mockReturnValueOnce(account)
570
+ accounts.getAccount.mockReturnValueOnce(Promise.resolve(account))
573
571
 
574
572
  const response = await config.api.users.deleteUser(user._id!, 400)
575
573
 
@@ -7,7 +7,7 @@ const router: Router = new Router()
7
7
  router.delete(
8
8
  "/api/system/tenants/:tenantId",
9
9
  middleware.adminOnly,
10
- controller.delete
10
+ controller.destroy
11
11
  )
12
12
 
13
13
  export default router
@@ -1,4 +1,4 @@
1
- import sdk from "../../../../sdk"
1
+ import * as accounts from "../../../../sdk/accounts"
2
2
  import { TestConfiguration, structures } from "../../../../tests"
3
3
  import { v4 as uuid } from "uuid"
4
4
 
@@ -24,8 +24,8 @@ describe("accounts", () => {
24
24
 
25
25
  const response = await config.api.accounts.saveMetadata(account)
26
26
 
27
- const id = sdk.accounts.formatAccountMetadataId(account.accountId)
28
- const metadata = await sdk.accounts.getMetadata(id)
27
+ const id = accounts.metadata.formatAccountMetadataId(account.accountId)
28
+ const metadata = await accounts.metadata.getMetadata(id)
29
29
  expect(response).toStrictEqual(metadata)
30
30
  })
31
31
  })
@@ -37,7 +37,7 @@ describe("accounts", () => {
37
37
 
38
38
  await config.api.accounts.destroyMetadata(account.accountId)
39
39
 
40
- const deleted = await sdk.accounts.getMetadata(account.accountId)
40
+ const deleted = await accounts.metadata.getMetadata(account.accountId)
41
41
  expect(deleted).toBe(undefined)
42
42
  })
43
43
 
@@ -30,7 +30,7 @@ describe("/api/system/migrations", () => {
30
30
  headers: {},
31
31
  status: 403,
32
32
  })
33
- expect(res.text).toBe("Unauthorized - no public worker access")
33
+ expect(res.body).toEqual({ message: "Unauthorized", status: 403 })
34
34
  expect(migrateFn).toBeCalledTimes(0)
35
35
  })
36
36
 
@@ -47,7 +47,7 @@ describe("/api/system/migrations", () => {
47
47
  headers: {},
48
48
  status: 403,
49
49
  })
50
- expect(res.text).toBe("Unauthorized - no public worker access")
50
+ expect(res.body).toEqual({ message: "Unauthorized", status: 403 })
51
51
  })
52
52
 
53
53
  it("returns definitions", async () => {
@@ -25,12 +25,12 @@ describe("/api/system/restore", () => {
25
25
  })
26
26
 
27
27
  it("restores in self host", async () => {
28
- config.modeSelf()
28
+ config.selfHosted()
29
29
  const res = await config.api.restore.restored()
30
30
  expect(res.body).toEqual({
31
31
  message: "System prepared after restore.",
32
32
  })
33
- config.modeCloud()
33
+ config.cloudHosted()
34
34
  })
35
35
  })
36
36
  })
@@ -1,6 +1,6 @@
1
1
  import { TestConfiguration } from "../../../../tests"
2
- import { accounts } from "@budibase/backend-core"
3
- import { mocks } from "@budibase/backend-core/tests"
2
+ import { accounts as _accounts } from "@budibase/backend-core"
3
+ const accounts = jest.mocked(_accounts)
4
4
 
5
5
  describe("/api/system/status", () => {
6
6
  const config = new TestConfiguration()
@@ -19,7 +19,7 @@ describe("/api/system/status", () => {
19
19
 
20
20
  describe("GET /api/system/status", () => {
21
21
  it("returns status in self host", async () => {
22
- config.modeSelf()
22
+ config.selfHosted()
23
23
  const res = await config.api.status.getStatus()
24
24
  expect(res.body).toEqual({
25
25
  health: {
@@ -27,7 +27,7 @@ describe("/api/system/status", () => {
27
27
  },
28
28
  })
29
29
  expect(accounts.getStatus).toBeCalledTimes(0)
30
- config.modeCloud()
30
+ config.cloudHosted()
31
31
  })
32
32
 
33
33
  it("returns status in cloud", async () => {
@@ -37,7 +37,7 @@ describe("/api/system/status", () => {
37
37
  },
38
38
  }
39
39
 
40
- mocks.accounts.getStatus.mockReturnValueOnce(value)
40
+ accounts.getStatus.mockReturnValueOnce(Promise.resolve(value))
41
41
 
42
42
  const res = await config.api.status.getStatus()
43
43