@budibase/worker 2.2.26 → 2.2.27-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.
- package/Dockerfile +1 -1
- package/__mocks__/node-fetch.ts +23 -0
- package/coverage/clover.xml +1423 -1379
- package/coverage/coverage-final.json +83 -77
- package/coverage/lcov-report/index.html +140 -140
- package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +52 -52
- package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +167 -224
- package/coverage/lcov-report/src/api/controllers/global/email.ts.html +4 -4
- package/coverage/lcov-report/src/api/controllers/global/events.ts.html +136 -0
- package/coverage/lcov-report/src/api/controllers/global/index.html +83 -68
- package/coverage/lcov-report/src/api/controllers/global/license.ts.html +16 -16
- package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +69 -69
- package/coverage/lcov-report/src/api/controllers/global/self.ts.html +20 -20
- package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +54 -54
- package/coverage/lcov-report/src/api/controllers/global/users.ts.html +83 -44
- package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +9 -9
- package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +5 -5
- package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +4 -4
- package/coverage/lcov-report/src/api/controllers/system/index.html +11 -11
- package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +5 -5
- package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +4 -4
- package/coverage/lcov-report/src/api/controllers/system/status.ts.html +5 -5
- package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +7 -7
- package/coverage/lcov-report/src/api/index.html +1 -1
- package/coverage/lcov-report/src/api/index.ts.html +42 -30
- package/coverage/lcov-report/src/api/routes/global/auth.ts.html +14 -14
- package/coverage/lcov-report/src/api/routes/global/configs.ts.html +25 -25
- package/coverage/lcov-report/src/api/routes/global/email.ts.html +13 -13
- package/coverage/lcov-report/src/api/routes/global/events.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/global/index.html +37 -22
- package/coverage/lcov-report/src/api/routes/global/license.ts.html +9 -9
- package/coverage/lcov-report/src/api/routes/global/roles.ts.html +10 -10
- package/coverage/lcov-report/src/api/routes/global/self.ts.html +11 -11
- package/coverage/lcov-report/src/api/routes/global/templates.ts.html +14 -14
- package/coverage/lcov-report/src/api/routes/global/users.ts.html +62 -20
- package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +12 -12
- package/coverage/lcov-report/src/api/routes/index.html +7 -7
- package/coverage/lcov-report/src/api/routes/index.ts.html +29 -23
- package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +10 -10
- package/coverage/lcov-report/src/api/routes/system/environment.ts.html +9 -9
- package/coverage/lcov-report/src/api/routes/system/index.html +15 -15
- package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +10 -10
- package/coverage/lcov-report/src/api/routes/system/restore.ts.html +9 -9
- package/coverage/lcov-report/src/api/routes/system/status.ts.html +9 -9
- package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +10 -10
- package/coverage/lcov-report/src/api/routes/validation/index.html +3 -3
- package/coverage/lcov-report/src/api/routes/validation/index.ts.html +2 -2
- package/coverage/lcov-report/src/api/routes/validation/users.ts.html +14 -14
- package/coverage/lcov-report/src/constants/index.html +17 -17
- package/coverage/lcov-report/src/constants/index.ts.html +77 -53
- package/coverage/lcov-report/src/constants/templates/index.html +18 -18
- package/coverage/lcov-report/src/constants/templates/index.ts.html +42 -42
- package/coverage/lcov-report/src/db/index.html +17 -17
- package/coverage/lcov-report/src/db/index.ts.html +18 -18
- package/coverage/lcov-report/src/environment.ts.html +45 -30
- package/coverage/lcov-report/src/index.html +27 -27
- package/coverage/lcov-report/src/index.ts.html +55 -55
- package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +5 -5
- package/coverage/lcov-report/src/middleware/index.html +1 -1
- package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +9 -9
- package/coverage/lcov-report/src/migrations/functions/index.html +11 -11
- package/coverage/lcov-report/src/migrations/index.html +15 -15
- package/coverage/lcov-report/src/migrations/index.ts.html +27 -27
- package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +13 -13
- package/coverage/lcov-report/src/sdk/accounts/index.html +13 -13
- package/coverage/lcov-report/src/sdk/accounts/index.ts.html +2 -2
- package/coverage/lcov-report/src/sdk/index.html +5 -5
- package/coverage/lcov-report/src/sdk/index.ts.html +6 -6
- package/coverage/lcov-report/src/sdk/users/events.ts.html +82 -58
- package/coverage/lcov-report/src/sdk/users/index.html +28 -28
- package/coverage/lcov-report/src/sdk/users/index.ts.html +2 -2
- package/coverage/lcov-report/src/sdk/users/users.ts.html +174 -120
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +221 -107
- package/coverage/lcov-report/src/tests/api/accounts.ts.html +7 -7
- package/coverage/lcov-report/src/tests/api/auth.ts.html +25 -13
- package/coverage/lcov-report/src/tests/api/base.ts.html +5 -5
- package/coverage/lcov-report/src/tests/api/configs.ts.html +11 -11
- package/coverage/lcov-report/src/tests/api/email.ts.html +6 -6
- package/coverage/lcov-report/src/tests/api/environment.ts.html +6 -6
- package/coverage/lcov-report/src/tests/api/groups.ts.html +163 -0
- package/coverage/lcov-report/src/tests/api/index.html +91 -31
- package/coverage/lcov-report/src/tests/api/index.ts.html +62 -29
- package/coverage/lcov-report/src/tests/api/license.ts.html +136 -0
- package/coverage/lcov-report/src/tests/api/migrations.ts.html +8 -8
- package/coverage/lcov-report/src/tests/api/restore.ts.html +7 -7
- package/coverage/lcov-report/src/tests/api/roles.ts.html +181 -0
- package/coverage/lcov-report/src/tests/api/self.ts.html +7 -7
- package/coverage/lcov-report/src/tests/api/status.ts.html +6 -6
- package/coverage/lcov-report/src/tests/api/templates.ts.html +175 -0
- package/coverage/lcov-report/src/tests/api/tenants.ts.html +10 -10
- package/coverage/lcov-report/src/tests/api/users.ts.html +30 -27
- package/coverage/lcov-report/src/tests/controllers.ts.html +14 -14
- package/coverage/lcov-report/src/tests/index.html +34 -34
- package/coverage/lcov-report/src/tests/index.ts.html +19 -55
- package/coverage/lcov-report/src/tests/mocks/{email.js.html → email.ts.html} +5 -5
- package/coverage/lcov-report/src/tests/mocks/index.html +6 -6
- package/coverage/lcov-report/src/tests/mocks/index.ts.html +10 -10
- package/coverage/lcov-report/src/tests/structures/configs.ts.html +11 -11
- package/coverage/lcov-report/src/tests/structures/groups.ts.html +15 -15
- package/coverage/lcov-report/src/tests/structures/index.html +26 -26
- package/coverage/lcov-report/src/tests/structures/index.ts.html +16 -22
- package/coverage/lcov-report/src/tests/structures/users.ts.html +16 -16
- package/coverage/lcov-report/src/utilities/appService.ts.html +45 -18
- package/coverage/lcov-report/src/utilities/email.ts.html +28 -28
- package/coverage/lcov-report/src/utilities/fileSystem.ts.html +4 -4
- package/coverage/lcov-report/src/utilities/index.html +27 -27
- package/coverage/lcov-report/src/utilities/index.ts.html +2 -2
- package/coverage/lcov-report/src/utilities/redis.ts.html +20 -20
- package/coverage/lcov-report/src/utilities/templates.ts.html +6 -6
- package/coverage/lcov-report/src/utilities/users.ts.html +7 -7
- package/coverage/lcov.info +2826 -2609
- package/jest-testcontainers-config.js +8 -0
- package/jest.config.ts +10 -4
- package/package.json +11 -7
- package/scripts/dev/manage.js +2 -2
- package/src/api/controllers/global/auth.ts +1 -1
- package/src/api/controllers/global/configs.ts +112 -131
- package/src/api/controllers/global/events.ts +17 -0
- package/src/api/controllers/global/users.ts +14 -1
- package/src/api/index.ts +4 -0
- package/src/api/routes/global/auth.ts +1 -1
- package/src/api/routes/global/configs.ts +7 -7
- package/src/api/routes/global/email.ts +1 -1
- package/src/api/routes/global/events.ts +8 -0
- package/src/api/routes/global/license.ts +1 -1
- package/src/api/routes/global/roles.ts +1 -1
- package/src/api/routes/global/self.ts +1 -1
- package/src/api/routes/global/templates.ts +1 -1
- package/src/api/routes/global/tests/auth.spec.ts +30 -22
- package/src/api/routes/global/tests/configs.spec.ts +114 -94
- package/src/api/routes/global/tests/groups.spec.ts +58 -0
- package/src/api/routes/global/tests/license.spec.ts +0 -2
- package/src/api/routes/global/tests/roles.spec.ts +71 -5
- package/src/api/routes/global/tests/templates.spec.ts +81 -9
- package/src/api/routes/global/tests/users.spec.ts +35 -36
- package/src/api/routes/global/users.ts +15 -1
- package/src/api/routes/global/workspaces.ts +1 -1
- package/src/api/routes/index.ts +2 -0
- package/src/api/routes/system/accounts.ts +1 -1
- package/src/api/routes/system/environment.ts +1 -1
- package/src/api/routes/system/migrations.ts +1 -1
- package/src/api/routes/system/restore.ts +1 -1
- package/src/api/routes/system/status.ts +1 -1
- package/src/api/routes/system/tenants.ts +1 -1
- package/src/api/routes/system/tests/environment.spec.ts +1 -1
- package/src/constants/index.ts +13 -5
- package/src/db/index.ts +1 -1
- package/src/environment.ts +6 -1
- package/src/index.ts +5 -5
- package/src/middleware/cloudRestricted.ts +1 -1
- package/src/sdk/users/events.ts +8 -0
- package/src/sdk/users/users.ts +23 -5
- package/src/tests/TestConfiguration.ts +52 -14
- package/src/tests/api/auth.ts +7 -3
- package/src/tests/api/configs.ts +2 -2
- package/src/tests/api/groups.ts +26 -0
- package/src/tests/api/index.ts +12 -1
- package/src/tests/api/license.ts +17 -0
- package/src/tests/api/roles.ts +32 -0
- package/src/tests/api/templates.ts +30 -0
- package/src/tests/api/users.ts +4 -3
- package/src/tests/index.ts +6 -18
- package/src/tests/jestEnv.ts +11 -0
- package/src/tests/jestSetup.ts +8 -15
- package/src/tests/mocks/{email.js → email.ts} +1 -1
- package/src/tests/mocks/index.ts +4 -4
- package/src/tests/structures/configs.ts +2 -2
- package/src/tests/structures/groups.ts +1 -1
- package/src/tests/structures/index.ts +3 -5
- package/src/tests/structures/users.ts +1 -1
- package/src/utilities/appService.ts +12 -3
- package/tsconfig.json +2 -2
|
@@ -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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
expect(res.body).toEqual({
|
|
53
|
+
message: "Please check your email for a reset link.",
|
|
54
|
+
})
|
|
55
|
+
expect(sendMailMock).toHaveBeenCalled()
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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.
|
|
226
|
+
await context.doInTenant(config.tenant1User!.tenantId, async () => {
|
|
227
|
+
await config.deleteConfig(Config.SETTINGS)
|
|
215
228
|
|
|
216
|
-
|
|
229
|
+
await saveSettingsConfig()
|
|
217
230
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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.
|
|
284
|
+
await context.doInTenant(config.tenant1User!.tenantId, async () => {
|
|
285
|
+
await config.saveSmtpConfig()
|
|
267
286
|
|
|
268
|
-
|
|
269
|
-
|
|
287
|
+
const res = await config.api.configs.getConfigChecklist()
|
|
288
|
+
const checklist = res.body
|
|
270
289
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
290
|
+
expect(checklist.apps.checked).toBeFalsy()
|
|
291
|
+
expect(checklist.smtp.checked).toBeTruthy()
|
|
292
|
+
expect(checklist.adminUser.checked).toBeTruthy()
|
|
293
|
+
})
|
|
274
294
|
})
|
|
275
295
|
})
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { events } from "@budibase/backend-core"
|
|
2
|
+
import { structures, TestConfiguration, mocks } from "../../../../tests"
|
|
3
|
+
|
|
4
|
+
describe("/api/global/groups", () => {
|
|
5
|
+
const config = new TestConfiguration()
|
|
6
|
+
|
|
7
|
+
beforeAll(async () => {
|
|
8
|
+
await config.beforeAll()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
afterAll(async () => {
|
|
12
|
+
await config.afterAll()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
mocks.licenses.useGroups()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
describe("create", () => {
|
|
20
|
+
it("should be able to create a new group", async () => {
|
|
21
|
+
const group = structures.groups.UserGroup()
|
|
22
|
+
await config.api.groups.saveGroup(group)
|
|
23
|
+
expect(events.group.created).toBeCalledTimes(1)
|
|
24
|
+
expect(events.group.updated).not.toBeCalled()
|
|
25
|
+
expect(events.group.permissionsEdited).not.toBeCalled()
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
describe("update", () => {
|
|
30
|
+
it("should be able to update a basic group", async () => {
|
|
31
|
+
const group = structures.groups.UserGroup()
|
|
32
|
+
let oldGroup = await config.api.groups.saveGroup(group)
|
|
33
|
+
|
|
34
|
+
let updatedGroup = {
|
|
35
|
+
...oldGroup.body,
|
|
36
|
+
...group,
|
|
37
|
+
name: "New Name",
|
|
38
|
+
}
|
|
39
|
+
await config.api.groups.saveGroup(updatedGroup)
|
|
40
|
+
|
|
41
|
+
expect(events.group.updated).toBeCalledTimes(1)
|
|
42
|
+
expect(events.group.permissionsEdited).not.toBeCalled()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe("destroy", () => {
|
|
46
|
+
it("should be able to delete a basic group", async () => {
|
|
47
|
+
const group = structures.groups.UserGroup()
|
|
48
|
+
let oldGroup = await config.api.groups.saveGroup(group)
|
|
49
|
+
await config.api.groups.deleteGroup(
|
|
50
|
+
oldGroup.body._id,
|
|
51
|
+
oldGroup.body._rev
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
expect(events.group.deleted).toBeCalledTimes(1)
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
})
|
|
@@ -1,14 +1,57 @@
|
|
|
1
|
-
import { TestConfiguration } from "../../../../tests"
|
|
1
|
+
import { structures, TestConfiguration } from "../../../../tests"
|
|
2
|
+
import { context, db, permissions, roles } from "@budibase/backend-core"
|
|
3
|
+
import { Mock } from "jest-mock"
|
|
4
|
+
import { Database } from "@budibase/types"
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
jest.mock("@budibase/backend-core", () => {
|
|
7
|
+
const core = jest.requireActual("@budibase/backend-core")
|
|
8
|
+
return {
|
|
9
|
+
...core,
|
|
10
|
+
db: {
|
|
11
|
+
...core.db,
|
|
12
|
+
},
|
|
13
|
+
context: {
|
|
14
|
+
...core.context,
|
|
15
|
+
getAppDB: jest.fn(),
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
let appId: string
|
|
21
|
+
let appDb: Database
|
|
22
|
+
|
|
23
|
+
async function addAppMetadata() {
|
|
24
|
+
await appDb.put({
|
|
25
|
+
_id: "app_metadata",
|
|
26
|
+
appId: appId,
|
|
27
|
+
name: "New App",
|
|
28
|
+
version: "version",
|
|
29
|
+
url: "url",
|
|
30
|
+
})
|
|
31
|
+
}
|
|
4
32
|
|
|
5
33
|
describe("/api/global/roles", () => {
|
|
6
34
|
const config = new TestConfiguration()
|
|
35
|
+
const role = new roles.Role(
|
|
36
|
+
db.generateRoleID("newRole"),
|
|
37
|
+
roles.BUILTIN_ROLE_IDS.BASIC,
|
|
38
|
+
permissions.BuiltinPermissionID.READ_ONLY
|
|
39
|
+
)
|
|
7
40
|
|
|
8
41
|
beforeAll(async () => {
|
|
9
42
|
await config.beforeAll()
|
|
10
43
|
})
|
|
11
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
|
+
|
|
12
55
|
afterAll(async () => {
|
|
13
56
|
await config.afterAll()
|
|
14
57
|
})
|
|
@@ -18,10 +61,33 @@ describe("/api/global/roles", () => {
|
|
|
18
61
|
})
|
|
19
62
|
|
|
20
63
|
describe("GET /api/global/roles", () => {
|
|
21
|
-
it("retrieves roles", () => {
|
|
64
|
+
it("retrieves roles", async () => {
|
|
65
|
+
const res = await config.api.roles.get()
|
|
66
|
+
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)
|
|
69
|
+
})
|
|
22
70
|
})
|
|
23
71
|
|
|
24
|
-
describe("GET
|
|
72
|
+
describe("GET api/global/roles/:appId", () => {
|
|
73
|
+
it("finds a role by appId", async () => {
|
|
74
|
+
const res = await config.api.roles.find(appId)
|
|
75
|
+
expect(res.body).toBeDefined()
|
|
76
|
+
expect(res.body.name).toEqual("New App")
|
|
77
|
+
})
|
|
78
|
+
})
|
|
25
79
|
|
|
26
|
-
describe("DELETE /api/global/roles/:appId", () => {
|
|
80
|
+
describe("DELETE /api/global/roles/:appId", () => {
|
|
81
|
+
it("removes an app role", async () => {
|
|
82
|
+
let user = structures.users.user()
|
|
83
|
+
user.roles = {
|
|
84
|
+
app_test: "role1",
|
|
85
|
+
}
|
|
86
|
+
const userResponse = await config.createUser(user)
|
|
87
|
+
const res = await config.api.roles.remove(appId)
|
|
88
|
+
const updatedUser = await config.api.users.getUser(userResponse._id!)
|
|
89
|
+
expect(updatedUser.body.roles).not.toHaveProperty(appId)
|
|
90
|
+
expect(res.body.message).toEqual("App role removed from all users")
|
|
91
|
+
})
|
|
92
|
+
})
|
|
27
93
|
})
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EmailTemplatePurpose,
|
|
3
|
+
TemplateMetadata,
|
|
4
|
+
TemplateType,
|
|
5
|
+
} from "../../../../constants"
|
|
1
6
|
import { TestConfiguration } from "../../../../tests"
|
|
2
7
|
|
|
3
8
|
// TODO
|
|
@@ -18,18 +23,85 @@ describe("/api/global/template", () => {
|
|
|
18
23
|
})
|
|
19
24
|
|
|
20
25
|
describe("GET /api/global/template/definitions", () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
describe("POST /api/global/template", () => {})
|
|
26
|
+
describe("retrieves definitions", () => {
|
|
27
|
+
it("checks description definitions", async () => {
|
|
28
|
+
let result = await config.api.templates.definitions()
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
expect(result.body.info[EmailTemplatePurpose.BASE].description).toEqual(
|
|
31
|
+
TemplateMetadata[TemplateType.EMAIL][0].description
|
|
32
|
+
)
|
|
33
|
+
expect(
|
|
34
|
+
result.body.info[EmailTemplatePurpose.PASSWORD_RECOVERY].description
|
|
35
|
+
).toEqual(TemplateMetadata[TemplateType.EMAIL][1].description)
|
|
36
|
+
expect(
|
|
37
|
+
result.body.info[EmailTemplatePurpose.WELCOME].description
|
|
38
|
+
).toEqual(TemplateMetadata[TemplateType.EMAIL][2].description)
|
|
39
|
+
expect(
|
|
40
|
+
result.body.info[EmailTemplatePurpose.INVITATION].description
|
|
41
|
+
).toEqual(TemplateMetadata[TemplateType.EMAIL][3].description)
|
|
42
|
+
expect(
|
|
43
|
+
result.body.info[EmailTemplatePurpose.CUSTOM].description
|
|
44
|
+
).toEqual(TemplateMetadata[TemplateType.EMAIL][4].description)
|
|
45
|
+
})
|
|
27
46
|
|
|
28
|
-
|
|
47
|
+
it("checks description bindings", async () => {
|
|
48
|
+
let result = await config.api.templates.definitions()
|
|
29
49
|
|
|
30
|
-
|
|
50
|
+
expect(result.body.bindings[EmailTemplatePurpose.BASE]).toEqual(
|
|
51
|
+
TemplateMetadata[TemplateType.EMAIL][0].bindings
|
|
52
|
+
)
|
|
53
|
+
expect(
|
|
54
|
+
result.body.bindings[EmailTemplatePurpose.PASSWORD_RECOVERY]
|
|
55
|
+
).toEqual(TemplateMetadata[TemplateType.EMAIL][1].bindings)
|
|
56
|
+
expect(result.body.bindings[EmailTemplatePurpose.WELCOME]).toEqual(
|
|
57
|
+
TemplateMetadata[TemplateType.EMAIL][2].bindings
|
|
58
|
+
)
|
|
59
|
+
expect(result.body.bindings[EmailTemplatePurpose.INVITATION]).toEqual(
|
|
60
|
+
TemplateMetadata[TemplateType.EMAIL][3].bindings
|
|
61
|
+
)
|
|
62
|
+
expect(result.body.bindings[EmailTemplatePurpose.CUSTOM]).toEqual(
|
|
63
|
+
TemplateMetadata[TemplateType.EMAIL][4].bindings
|
|
64
|
+
)
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
})
|
|
31
68
|
|
|
32
|
-
describe("
|
|
69
|
+
describe("POST /api/global/template", () => {
|
|
70
|
+
it("adds a new template", async () => {
|
|
71
|
+
let purpose = "base"
|
|
72
|
+
let contents = "Test contents"
|
|
73
|
+
let updatedTemplate = {
|
|
74
|
+
contents: contents,
|
|
75
|
+
purpose: purpose,
|
|
76
|
+
type: "email",
|
|
77
|
+
}
|
|
78
|
+
await config.api.templates.saveTemplate(updatedTemplate)
|
|
79
|
+
let res = await config.api.templates.getTemplate()
|
|
80
|
+
let newTemplate = res.body.find((t: any) => (t.purpose = purpose))
|
|
81
|
+
expect(newTemplate.contents).toEqual(contents)
|
|
82
|
+
})
|
|
83
|
+
})
|
|
33
84
|
|
|
34
|
-
describe("
|
|
85
|
+
describe("GET /api/global/template", () => {
|
|
86
|
+
it("fetches templates", async () => {
|
|
87
|
+
let res = await config.api.templates.getTemplate()
|
|
88
|
+
expect(
|
|
89
|
+
res.body.find((t: any) => t.purpose === EmailTemplatePurpose.BASE)
|
|
90
|
+
).toBeDefined()
|
|
91
|
+
expect(
|
|
92
|
+
res.body.find((t: any) => t.purpose === EmailTemplatePurpose.CUSTOM)
|
|
93
|
+
).toBeDefined()
|
|
94
|
+
expect(
|
|
95
|
+
res.body.find((t: any) => t.purpose === EmailTemplatePurpose.INVITATION)
|
|
96
|
+
).toBeDefined()
|
|
97
|
+
expect(
|
|
98
|
+
res.body.find(
|
|
99
|
+
(t: any) => t.purpose === EmailTemplatePurpose.PASSWORD_RECOVERY
|
|
100
|
+
)
|
|
101
|
+
).toBeDefined()
|
|
102
|
+
expect(
|
|
103
|
+
res.body.find((t: any) => t.purpose === EmailTemplatePurpose.WELCOME)
|
|
104
|
+
).toBeDefined()
|
|
105
|
+
})
|
|
106
|
+
})
|
|
35
107
|
})
|