@budibase/worker 2.3.11-alpha.0 → 2.3.11
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/coverage/clover.xml +369 -384
- 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 +65 -62
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +61 -151
- package/coverage/lcov-report/src/tests/api/accounts.ts.html +1 -1
- package/coverage/lcov-report/src/tests/api/auth.ts.html +8 -20
- 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 +14 -8
- 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 +607 -629
- package/jest.config.ts +2 -3
- package/package.json +5 -6
- package/src/api/routes/global/tests/auth.spec.ts +22 -30
- package/src/api/routes/global/tests/configs.spec.ts +94 -114
- package/src/api/routes/global/tests/roles.spec.ts +14 -19
- package/src/api/routes/global/tests/users.spec.ts +34 -33
- package/src/sdk/users/users.ts +1 -0
- package/src/tests/TestConfiguration.ts +11 -41
- package/src/tests/api/auth.ts +3 -7
- package/src/tests/api/configs.ts +2 -2
- package/src/tests/api/users.ts +2 -2
- package/src/tests/jestSetup.ts +2 -9
- package/src/tests/structures/index.ts +2 -0
- package/__mocks__/node-fetch.ts +0 -23
- package/jest-testcontainers-config.js +0 -8
|
@@ -20,44 +20,22 @@ import {
|
|
|
20
20
|
auth,
|
|
21
21
|
constants,
|
|
22
22
|
env as coreEnv,
|
|
23
|
-
DEFAULT_TENANT_ID,
|
|
24
23
|
} from "@budibase/backend-core"
|
|
25
|
-
import structures, { TENANT_ID, CSRF_TOKEN } from "./structures"
|
|
24
|
+
import structures, { TENANT_ID, TENANT_1, CSRF_TOKEN } from "./structures"
|
|
26
25
|
import { CreateUserResponse, User, AuthToken } from "@budibase/types"
|
|
27
26
|
import API from "./api"
|
|
28
|
-
import sdk from "../sdk"
|
|
29
27
|
|
|
30
28
|
enum Mode {
|
|
31
29
|
CLOUD = "cloud",
|
|
32
30
|
SELF = "self",
|
|
33
31
|
}
|
|
34
32
|
|
|
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
|
-
|
|
54
33
|
class TestConfiguration {
|
|
55
34
|
server: any
|
|
56
35
|
request: any
|
|
57
36
|
api: API
|
|
58
37
|
defaultUser?: User
|
|
59
38
|
tenant1User?: User
|
|
60
|
-
#tenantId?: string
|
|
61
39
|
|
|
62
40
|
constructor(
|
|
63
41
|
opts: { openServer: boolean; mode: Mode } = {
|
|
@@ -134,21 +112,13 @@ class TestConfiguration {
|
|
|
134
112
|
// SETUP / TEARDOWN
|
|
135
113
|
|
|
136
114
|
async beforeAll() {
|
|
137
|
-
|
|
138
|
-
|
|
115
|
+
await this.createDefaultUser()
|
|
116
|
+
await this.createSession(this.defaultUser!)
|
|
139
117
|
|
|
140
|
-
|
|
141
|
-
await
|
|
142
|
-
await this.createSession(this.
|
|
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
|
-
}
|
|
118
|
+
await tenancy.doInTenant(TENANT_1, async () => {
|
|
119
|
+
await this.createTenant1User()
|
|
120
|
+
await this.createSession(this.tenant1User!)
|
|
121
|
+
})
|
|
152
122
|
}
|
|
153
123
|
|
|
154
124
|
async afterAll() {
|
|
@@ -163,8 +133,6 @@ class TestConfiguration {
|
|
|
163
133
|
// create user / new tenant
|
|
164
134
|
const res = await this.api.users.createAdminUser()
|
|
165
135
|
|
|
166
|
-
await sdk.users.addTenant(res.tenantId, res.userId, res.email)
|
|
167
|
-
|
|
168
136
|
// return the created user
|
|
169
137
|
const userRes = await this.api.users.getUser(res.userId, {
|
|
170
138
|
headers: {
|
|
@@ -184,7 +152,7 @@ class TestConfiguration {
|
|
|
184
152
|
try {
|
|
185
153
|
return tenancy.getTenantId()
|
|
186
154
|
} catch (e: any) {
|
|
187
|
-
return
|
|
155
|
+
return TENANT_ID
|
|
188
156
|
}
|
|
189
157
|
}
|
|
190
158
|
|
|
@@ -235,7 +203,7 @@ class TestConfiguration {
|
|
|
235
203
|
const tenantId = this.getTenantId()
|
|
236
204
|
if (tenantId === TENANT_ID) {
|
|
237
205
|
return this.authHeaders(this.defaultUser!)
|
|
238
|
-
} else if (tenantId ===
|
|
206
|
+
} else if (tenantId === TENANT_1) {
|
|
239
207
|
return this.authHeaders(this.tenant1User!)
|
|
240
208
|
} else {
|
|
241
209
|
throw new Error("could not determine auth headers to use")
|
|
@@ -254,6 +222,7 @@ class TestConfiguration {
|
|
|
254
222
|
|
|
255
223
|
async createDefaultUser() {
|
|
256
224
|
const user = structures.users.adminUser({
|
|
225
|
+
email: "test@test.com",
|
|
257
226
|
password: "test",
|
|
258
227
|
})
|
|
259
228
|
this.defaultUser = await this.createUser(user)
|
|
@@ -261,6 +230,7 @@ class TestConfiguration {
|
|
|
261
230
|
|
|
262
231
|
async createTenant1User() {
|
|
263
232
|
const user = structures.users.adminUser({
|
|
233
|
+
email: "tenant1@test.com",
|
|
264
234
|
password: "test",
|
|
265
235
|
})
|
|
266
236
|
this.tenant1User = await this.createUser(user)
|
package/src/tests/api/auth.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import structures from "../structures"
|
|
2
1
|
import TestConfiguration from "../TestConfiguration"
|
|
3
2
|
import { TestAPI } from "./base"
|
|
4
3
|
|
|
@@ -25,17 +24,14 @@ export class AuthAPI extends TestAPI {
|
|
|
25
24
|
.expect(200)
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
requestPasswordReset = async (sendMailMock: any
|
|
27
|
+
requestPasswordReset = async (sendMailMock: any) => {
|
|
29
28
|
await this.config.saveSmtpConfig()
|
|
30
29
|
await this.config.saveSettingsConfig()
|
|
31
|
-
await this.config.createUser(
|
|
32
|
-
...structures.users.user(),
|
|
33
|
-
email: userEmail,
|
|
34
|
-
})
|
|
30
|
+
await this.config.createUser()
|
|
35
31
|
const res = await this.request
|
|
36
32
|
.post(`/api/global/auth/${this.config.getTenantId()}/reset`)
|
|
37
33
|
.send({
|
|
38
|
-
email:
|
|
34
|
+
email: "test@test.com",
|
|
39
35
|
})
|
|
40
36
|
.expect("Content-Type", /json/)
|
|
41
37
|
.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(200)
|
|
14
13
|
.expect("Content-Type", /json/)
|
|
14
|
+
.expect(200)
|
|
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(200)
|
|
23
22
|
.expect("Content-Type", /json/)
|
|
23
|
+
.expect(200)
|
|
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(status)
|
|
30
29
|
.expect("Content-Type", /json/)
|
|
30
|
+
.expect(status)
|
|
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.uuid(),
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
const res = await this.request
|
package/src/tests/jestSetup.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { mocks
|
|
2
|
-
|
|
3
|
-
import env from "../environment"
|
|
4
|
-
import { env as coreEnv } from "@budibase/backend-core"
|
|
1
|
+
import { mocks } from "@budibase/backend-core/tests"
|
|
5
2
|
|
|
6
3
|
// must explicitly enable fetch mock
|
|
7
4
|
mocks.fetch.enable()
|
|
@@ -18,9 +15,5 @@ if (!process.env.DEBUG) {
|
|
|
18
15
|
if (!process.env.CI) {
|
|
19
16
|
// set a longer timeout in dev for debugging
|
|
20
17
|
// 100 seconds
|
|
21
|
-
jest.setTimeout(
|
|
22
|
-
} else {
|
|
23
|
-
jest.setTimeout(10 * 1000)
|
|
18
|
+
jest.setTimeout(100000)
|
|
24
19
|
}
|
|
25
|
-
|
|
26
|
-
testContainerUtils.setupEnv(env, coreEnv)
|
|
@@ -5,6 +5,7 @@ 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"
|
|
8
9
|
export const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
|
|
9
10
|
|
|
10
11
|
const pkg = {
|
|
@@ -13,6 +14,7 @@ const pkg = {
|
|
|
13
14
|
configs,
|
|
14
15
|
users,
|
|
15
16
|
TENANT_ID,
|
|
17
|
+
TENANT_1,
|
|
16
18
|
CSRF_TOKEN,
|
|
17
19
|
groups,
|
|
18
20
|
}
|
package/__mocks__/node-fetch.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import fs from "fs"
|
|
2
|
-
module FetchMock {
|
|
3
|
-
const fetch = jest.requireActual("node-fetch")
|
|
4
|
-
|
|
5
|
-
const func = async (url: any, opts: any) => {
|
|
6
|
-
if (url.includes("http://someconfigurl")) {
|
|
7
|
-
return {
|
|
8
|
-
ok: true,
|
|
9
|
-
json: () => ({
|
|
10
|
-
issuer: "test",
|
|
11
|
-
authorization_endpoint: "http://localhost/auth",
|
|
12
|
-
token_endpoint: "http://localhost/token",
|
|
13
|
-
userinfo_endpoint: "http://localhost/userinfo",
|
|
14
|
-
}),
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return fetch(url, opts)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
func.Headers = fetch.Headers
|
|
21
|
-
|
|
22
|
-
module.exports = func
|
|
23
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const { join } = require("path")
|
|
2
|
-
require("dotenv").config({
|
|
3
|
-
path: join(__dirname, "..", "..", "hosting", ".env"),
|
|
4
|
-
})
|
|
5
|
-
|
|
6
|
-
const jestTestcontainersConfigGenerator = require("../../jestTestcontainersConfigGenerator")
|
|
7
|
-
|
|
8
|
-
module.exports = jestTestcontainersConfigGenerator()
|