@budibase/worker 2.3.1 → 2.3.2-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.
- package/__mocks__/node-fetch.ts +23 -0
- package/coverage/clover.xml +384 -369
- package/coverage/coverage-final.json +18 -18
- package/coverage/lcov-report/index.html +56 -56
- package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +11 -11
- package/coverage/lcov-report/src/api/controllers/global/email.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/global/events.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/global/index.html +21 -21
- package/coverage/lcov-report/src/api/controllers/global/license.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +15 -15
- package/coverage/lcov-report/src/api/controllers/global/self.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/global/users.ts.html +6 -6
- package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/index.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/status.ts.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +1 -1
- package/coverage/lcov-report/src/api/index.html +1 -1
- package/coverage/lcov-report/src/api/index.ts.html +6 -6
- package/coverage/lcov-report/src/api/routes/global/auth.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/configs.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/email.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/events.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/license.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/roles.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/self.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/templates.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/users.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/index.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/environment.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/restore.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/status.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/validation/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/validation/index.ts.html +1 -1
- package/coverage/lcov-report/src/api/routes/validation/users.ts.html +1 -1
- package/coverage/lcov-report/src/constants/index.html +1 -1
- package/coverage/lcov-report/src/constants/index.ts.html +1 -1
- package/coverage/lcov-report/src/constants/templates/index.html +11 -11
- package/coverage/lcov-report/src/constants/templates/index.ts.html +10 -10
- package/coverage/lcov-report/src/db/index.html +15 -15
- package/coverage/lcov-report/src/db/index.ts.html +10 -10
- package/coverage/lcov-report/src/environment.ts.html +8 -8
- package/coverage/lcov-report/src/index.html +5 -5
- package/coverage/lcov-report/src/index.ts.html +1 -1
- package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +1 -1
- package/coverage/lcov-report/src/middleware/index.html +1 -1
- package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +1 -1
- package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
- package/coverage/lcov-report/src/migrations/index.html +1 -1
- package/coverage/lcov-report/src/migrations/index.ts.html +1 -1
- package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +1 -1
- package/coverage/lcov-report/src/sdk/accounts/index.html +1 -1
- package/coverage/lcov-report/src/sdk/accounts/index.ts.html +1 -1
- package/coverage/lcov-report/src/sdk/index.html +1 -1
- package/coverage/lcov-report/src/sdk/index.ts.html +2 -2
- package/coverage/lcov-report/src/sdk/users/events.ts.html +29 -29
- package/coverage/lcov-report/src/sdk/users/index.html +15 -15
- package/coverage/lcov-report/src/sdk/users/index.ts.html +1 -1
- package/coverage/lcov-report/src/sdk/users/users.ts.html +62 -65
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +151 -61
- package/coverage/lcov-report/src/tests/api/accounts.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/auth.ts.html +20 -8
- package/coverage/lcov-report/src/tests/api/base.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/configs.ts.html +3 -3
- package/coverage/lcov-report/src/tests/api/email.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/environment.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/groups.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/index.html +5 -5
- package/coverage/lcov-report/src/tests/api/index.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/license.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/migrations.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/restore.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/roles.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/self.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/status.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/templates.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/tenants.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/users.ts.html +3 -3
- package/coverage/lcov-report/src/tests/controllers.ts.html +2 -2
- package/coverage/lcov-report/src/tests/index.html +18 -18
- package/coverage/lcov-report/src/tests/index.ts.html +2 -2
- package/coverage/lcov-report/src/tests/mocks/email.ts.html +1 -1
- package/coverage/lcov-report/src/tests/mocks/index.html +1 -1
- package/coverage/lcov-report/src/tests/mocks/index.ts.html +1 -1
- package/coverage/lcov-report/src/tests/structures/configs.ts.html +1 -1
- package/coverage/lcov-report/src/tests/structures/groups.ts.html +1 -1
- package/coverage/lcov-report/src/tests/structures/index.html +9 -9
- package/coverage/lcov-report/src/tests/structures/index.ts.html +8 -14
- package/coverage/lcov-report/src/tests/structures/users.ts.html +5 -5
- package/coverage/lcov-report/src/utilities/appService.ts.html +7 -7
- package/coverage/lcov-report/src/utilities/email.ts.html +1 -1
- package/coverage/lcov-report/src/utilities/fileSystem.ts.html +1 -1
- package/coverage/lcov-report/src/utilities/index.html +1 -1
- package/coverage/lcov-report/src/utilities/index.ts.html +1 -1
- package/coverage/lcov-report/src/utilities/redis.ts.html +1 -1
- package/coverage/lcov-report/src/utilities/templates.ts.html +1 -1
- package/coverage/lcov-report/src/utilities/users.ts.html +6 -6
- package/coverage/lcov.info +629 -607
- package/jest-testcontainers-config.js +8 -0
- package/jest.config.ts +3 -2
- package/package.json +7 -6
- 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/roles.spec.ts +19 -14
- package/src/api/routes/global/tests/users.spec.ts +33 -34
- package/src/sdk/users/users.ts +0 -1
- package/src/tests/TestConfiguration.ts +41 -11
- package/src/tests/api/auth.ts +7 -3
- package/src/tests/api/configs.ts +2 -2
- package/src/tests/api/users.ts +2 -2
- package/src/tests/jestSetup.ts +6 -1
- package/src/tests/structures/index.ts +0 -2
|
@@ -20,22 +20,44 @@ import {
|
|
|
20
20
|
auth,
|
|
21
21
|
constants,
|
|
22
22
|
env as coreEnv,
|
|
23
|
+
DEFAULT_TENANT_ID,
|
|
23
24
|
} from "@budibase/backend-core"
|
|
24
|
-
import structures, { TENANT_ID,
|
|
25
|
+
import structures, { TENANT_ID, CSRF_TOKEN } from "./structures"
|
|
25
26
|
import { CreateUserResponse, User, AuthToken } from "@budibase/types"
|
|
26
27
|
import API from "./api"
|
|
28
|
+
import sdk from "../sdk"
|
|
27
29
|
|
|
28
30
|
enum Mode {
|
|
29
31
|
CLOUD = "cloud",
|
|
30
32
|
SELF = "self",
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
async function retry<T extends (...arg0: any[]) => any>(
|
|
36
|
+
fn: T,
|
|
37
|
+
maxTry: number = 5,
|
|
38
|
+
retryCount = 1
|
|
39
|
+
): Promise<Awaited<ReturnType<T>>> {
|
|
40
|
+
const currRetry = typeof retryCount === "number" ? retryCount : 1
|
|
41
|
+
try {
|
|
42
|
+
const result = await fn()
|
|
43
|
+
return result
|
|
44
|
+
} catch (e) {
|
|
45
|
+
console.log(`Retry ${currRetry} failed.`)
|
|
46
|
+
if (currRetry > maxTry) {
|
|
47
|
+
console.log(`All ${maxTry} retry attempts exhausted`)
|
|
48
|
+
throw e
|
|
49
|
+
}
|
|
50
|
+
return retry(fn, maxTry, currRetry + 1)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
33
54
|
class TestConfiguration {
|
|
34
55
|
server: any
|
|
35
56
|
request: any
|
|
36
57
|
api: API
|
|
37
58
|
defaultUser?: User
|
|
38
59
|
tenant1User?: User
|
|
60
|
+
#tenantId?: string
|
|
39
61
|
|
|
40
62
|
constructor(
|
|
41
63
|
opts: { openServer: boolean; mode: Mode } = {
|
|
@@ -112,13 +134,21 @@ class TestConfiguration {
|
|
|
112
134
|
// SETUP / TEARDOWN
|
|
113
135
|
|
|
114
136
|
async beforeAll() {
|
|
115
|
-
|
|
116
|
-
|
|
137
|
+
try {
|
|
138
|
+
this.#tenantId = structures.tenant.id()
|
|
117
139
|
|
|
118
|
-
|
|
119
|
-
await this.
|
|
120
|
-
await this.createSession(this.
|
|
121
|
-
|
|
140
|
+
// Running tests in parallel causes issues creating the globaldb twice. This ensures the db is properly created before starting
|
|
141
|
+
await retry(async () => await this.createDefaultUser())
|
|
142
|
+
await this.createSession(this.defaultUser!)
|
|
143
|
+
|
|
144
|
+
await tenancy.doInTenant(this.#tenantId, async () => {
|
|
145
|
+
await this.createTenant1User()
|
|
146
|
+
await this.createSession(this.tenant1User!)
|
|
147
|
+
})
|
|
148
|
+
} catch (e: any) {
|
|
149
|
+
console.log(e)
|
|
150
|
+
throw new Error(e.message)
|
|
151
|
+
}
|
|
122
152
|
}
|
|
123
153
|
|
|
124
154
|
async afterAll() {
|
|
@@ -133,6 +163,8 @@ class TestConfiguration {
|
|
|
133
163
|
// create user / new tenant
|
|
134
164
|
const res = await this.api.users.createAdminUser()
|
|
135
165
|
|
|
166
|
+
await sdk.users.addTenant(res.tenantId, res.userId, res.email)
|
|
167
|
+
|
|
136
168
|
// return the created user
|
|
137
169
|
const userRes = await this.api.users.getUser(res.userId, {
|
|
138
170
|
headers: {
|
|
@@ -152,7 +184,7 @@ class TestConfiguration {
|
|
|
152
184
|
try {
|
|
153
185
|
return tenancy.getTenantId()
|
|
154
186
|
} catch (e: any) {
|
|
155
|
-
return
|
|
187
|
+
return DEFAULT_TENANT_ID
|
|
156
188
|
}
|
|
157
189
|
}
|
|
158
190
|
|
|
@@ -203,7 +235,7 @@ class TestConfiguration {
|
|
|
203
235
|
const tenantId = this.getTenantId()
|
|
204
236
|
if (tenantId === TENANT_ID) {
|
|
205
237
|
return this.authHeaders(this.defaultUser!)
|
|
206
|
-
} else if (tenantId ===
|
|
238
|
+
} else if (tenantId === this.getTenantId()) {
|
|
207
239
|
return this.authHeaders(this.tenant1User!)
|
|
208
240
|
} else {
|
|
209
241
|
throw new Error("could not determine auth headers to use")
|
|
@@ -222,7 +254,6 @@ class TestConfiguration {
|
|
|
222
254
|
|
|
223
255
|
async createDefaultUser() {
|
|
224
256
|
const user = structures.users.adminUser({
|
|
225
|
-
email: "test@test.com",
|
|
226
257
|
password: "test",
|
|
227
258
|
})
|
|
228
259
|
this.defaultUser = await this.createUser(user)
|
|
@@ -230,7 +261,6 @@ class TestConfiguration {
|
|
|
230
261
|
|
|
231
262
|
async createTenant1User() {
|
|
232
263
|
const user = structures.users.adminUser({
|
|
233
|
-
email: "tenant1@test.com",
|
|
234
264
|
password: "test",
|
|
235
265
|
})
|
|
236
266
|
this.tenant1User = await this.createUser(user)
|
package/src/tests/api/auth.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import structures from "../structures"
|
|
1
2
|
import TestConfiguration from "../TestConfiguration"
|
|
2
3
|
import { TestAPI } from "./base"
|
|
3
4
|
|
|
@@ -24,14 +25,17 @@ export class AuthAPI extends TestAPI {
|
|
|
24
25
|
.expect(200)
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
requestPasswordReset = async (sendMailMock: any) => {
|
|
28
|
+
requestPasswordReset = async (sendMailMock: any, userEmail: string) => {
|
|
28
29
|
await this.config.saveSmtpConfig()
|
|
29
30
|
await this.config.saveSettingsConfig()
|
|
30
|
-
await this.config.createUser(
|
|
31
|
+
await this.config.createUser({
|
|
32
|
+
...structures.users.user(),
|
|
33
|
+
email: userEmail,
|
|
34
|
+
})
|
|
31
35
|
const res = await this.request
|
|
32
36
|
.post(`/api/global/auth/${this.config.getTenantId()}/reset`)
|
|
33
37
|
.send({
|
|
34
|
-
email:
|
|
38
|
+
email: userEmail,
|
|
35
39
|
})
|
|
36
40
|
.expect("Content-Type", /json/)
|
|
37
41
|
.expect(200)
|
package/src/tests/api/configs.ts
CHANGED
|
@@ -10,8 +10,8 @@ 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("Content-Type", /json/)
|
|
14
13
|
.expect(200)
|
|
14
|
+
.expect("Content-Type", /json/)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
saveConfig = (data: any) => {
|
|
@@ -19,8 +19,8 @@ export class ConfigAPI extends TestAPI {
|
|
|
19
19
|
.post(`/api/global/configs`)
|
|
20
20
|
.send(data)
|
|
21
21
|
.set(this.config.defaultHeaders())
|
|
22
|
-
.expect("Content-Type", /json/)
|
|
23
22
|
.expect(200)
|
|
23
|
+
.expect("Content-Type", /json/)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
OIDCCallback = (configId: string, preAuthRes: any) => {
|
package/src/tests/api/users.ts
CHANGED
|
@@ -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.
|
|
103
|
+
tenantId: structures.tenant.id(),
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
const res = await this.request
|
package/src/tests/jestSetup.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { mocks } from "@budibase/backend-core/tests"
|
|
1
|
+
import { mocks, testContainerUtils } from "@budibase/backend-core/tests"
|
|
2
|
+
|
|
3
|
+
import env from "../environment"
|
|
4
|
+
import { env as coreEnv } from "@budibase/backend-core"
|
|
2
5
|
|
|
3
6
|
// must explicitly enable fetch mock
|
|
4
7
|
mocks.fetch.enable()
|
|
@@ -17,3 +20,5 @@ if (!process.env.CI) {
|
|
|
17
20
|
// 100 seconds
|
|
18
21
|
jest.setTimeout(100000)
|
|
19
22
|
}
|
|
23
|
+
|
|
24
|
+
testContainerUtils.setupEnv(env, coreEnv)
|
|
@@ -5,7 +5,6 @@ import * as groups from "./groups"
|
|
|
5
5
|
import { v4 as uuid } from "uuid"
|
|
6
6
|
|
|
7
7
|
export const TENANT_ID = "default"
|
|
8
|
-
export const TENANT_1 = "tenant1"
|
|
9
8
|
export const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
|
|
10
9
|
|
|
11
10
|
const pkg = {
|
|
@@ -14,7 +13,6 @@ const pkg = {
|
|
|
14
13
|
configs,
|
|
15
14
|
users,
|
|
16
15
|
TENANT_ID,
|
|
17
|
-
TENANT_1,
|
|
18
16
|
CSRF_TOKEN,
|
|
19
17
|
groups,
|
|
20
18
|
}
|