@budibase/worker 2.1.46-alpha.4 → 2.1.46-alpha.6
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 +988 -929
- package/coverage/coverage-final.json +81 -77
- package/coverage/lcov-report/index.html +65 -65
- package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +26 -26
- package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +15 -15
- package/coverage/lcov-report/src/api/controllers/global/email.ts.html +4 -4
- package/coverage/lcov-report/src/api/controllers/global/index.html +31 -31
- package/coverage/lcov-report/src/api/controllers/global/license.ts.html +7 -7
- package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +76 -76
- package/coverage/lcov-report/src/api/controllers/global/self.ts.html +14 -14
- package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +53 -53
- package/coverage/lcov-report/src/api/controllers/global/users.ts.html +26 -26
- package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +6 -6
- package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +4 -4
- package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +3 -3
- package/coverage/lcov-report/src/api/controllers/system/index.html +1 -1
- package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +4 -4
- package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +4 -4
- package/coverage/lcov-report/src/api/controllers/system/status.ts.html +4 -4
- package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +5 -5
- package/coverage/lcov-report/src/api/index.html +1 -1
- package/coverage/lcov-report/src/api/index.ts.html +23 -23
- package/coverage/lcov-report/src/api/routes/global/auth.ts.html +11 -11
- package/coverage/lcov-report/src/api/routes/global/configs.ts.html +16 -16
- package/coverage/lcov-report/src/api/routes/global/email.ts.html +10 -10
- package/coverage/lcov-report/src/api/routes/global/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/global/license.ts.html +6 -6
- package/coverage/lcov-report/src/api/routes/global/roles.ts.html +7 -7
- package/coverage/lcov-report/src/api/routes/global/self.ts.html +8 -8
- package/coverage/lcov-report/src/api/routes/global/templates.ts.html +11 -11
- package/coverage/lcov-report/src/api/routes/global/users.ts.html +16 -16
- package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +9 -9
- package/coverage/lcov-report/src/api/routes/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/index.ts.html +19 -19
- package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +7 -7
- package/coverage/lcov-report/src/api/routes/system/environment.ts.html +6 -6
- package/coverage/lcov-report/src/api/routes/system/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +7 -7
- package/coverage/lcov-report/src/api/routes/system/restore.ts.html +6 -6
- package/coverage/lcov-report/src/api/routes/system/status.ts.html +6 -6
- package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +7 -7
- package/coverage/lcov-report/src/api/routes/validation/index.html +1 -1
- package/coverage/lcov-report/src/api/routes/validation/index.ts.html +2 -2
- package/coverage/lcov-report/src/api/routes/validation/users.ts.html +13 -13
- package/coverage/lcov-report/src/constants/index.html +9 -9
- package/coverage/lcov-report/src/constants/index.ts.html +73 -49
- package/coverage/lcov-report/src/constants/templates/index.html +19 -19
- package/coverage/lcov-report/src/constants/templates/index.ts.html +39 -39
- package/coverage/lcov-report/src/db/index.html +1 -1
- package/coverage/lcov-report/src/db/index.ts.html +8 -8
- package/coverage/lcov-report/src/environment.ts.html +16 -16
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.ts.html +38 -38
- package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +4 -4
- package/coverage/lcov-report/src/middleware/index.html +1 -1
- package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +3 -3
- 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 +17 -17
- package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +6 -6
- package/coverage/lcov-report/src/sdk/accounts/index.html +1 -1
- package/coverage/lcov-report/src/sdk/accounts/index.ts.html +2 -2
- package/coverage/lcov-report/src/sdk/index.html +1 -1
- package/coverage/lcov-report/src/sdk/index.ts.html +4 -4
- package/coverage/lcov-report/src/sdk/users/events.ts.html +46 -46
- package/coverage/lcov-report/src/sdk/users/index.html +15 -15
- package/coverage/lcov-report/src/sdk/users/index.ts.html +2 -2
- package/coverage/lcov-report/src/sdk/users/users.ts.html +97 -97
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +104 -80
- package/coverage/lcov-report/src/tests/api/accounts.ts.html +6 -6
- package/coverage/lcov-report/src/tests/api/auth.ts.html +7 -7
- package/coverage/lcov-report/src/tests/api/base.ts.html +4 -4
- package/coverage/lcov-report/src/tests/api/configs.ts.html +8 -8
- package/coverage/lcov-report/src/tests/api/email.ts.html +5 -5
- package/coverage/lcov-report/src/tests/api/environment.ts.html +5 -5
- package/coverage/lcov-report/src/tests/api/groups.ts.html +163 -0
- package/coverage/lcov-report/src/tests/api/index.html +71 -11
- package/coverage/lcov-report/src/tests/api/index.ts.html +61 -28
- package/coverage/lcov-report/src/tests/api/license.ts.html +136 -0
- package/coverage/lcov-report/src/tests/api/migrations.ts.html +6 -6
- package/coverage/lcov-report/src/tests/api/restore.ts.html +5 -5
- package/coverage/lcov-report/src/tests/api/roles.ts.html +181 -0
- package/coverage/lcov-report/src/tests/api/self.ts.html +6 -6
- package/coverage/lcov-report/src/tests/api/status.ts.html +5 -5
- package/coverage/lcov-report/src/tests/api/templates.ts.html +175 -0
- package/coverage/lcov-report/src/tests/api/tenants.ts.html +5 -5
- package/coverage/lcov-report/src/tests/api/users.ts.html +16 -16
- package/coverage/lcov-report/src/tests/controllers.ts.html +6 -6
- package/coverage/lcov-report/src/tests/index.html +10 -10
- package/coverage/lcov-report/src/tests/index.ts.html +9 -9
- package/coverage/lcov-report/src/tests/mocks/email.js.html +2 -2
- package/coverage/lcov-report/src/tests/mocks/index.html +1 -1
- package/coverage/lcov-report/src/tests/mocks/index.ts.html +6 -6
- package/coverage/lcov-report/src/tests/structures/configs.ts.html +8 -8
- package/coverage/lcov-report/src/tests/structures/groups.ts.html +15 -15
- package/coverage/lcov-report/src/tests/structures/index.html +16 -16
- package/coverage/lcov-report/src/tests/structures/index.ts.html +11 -11
- package/coverage/lcov-report/src/tests/structures/users.ts.html +11 -11
- package/coverage/lcov-report/src/utilities/appService.ts.html +10 -10
- package/coverage/lcov-report/src/utilities/email.ts.html +15 -15
- package/coverage/lcov-report/src/utilities/fileSystem.ts.html +4 -4
- package/coverage/lcov-report/src/utilities/index.html +1 -1
- package/coverage/lcov-report/src/utilities/index.ts.html +2 -2
- package/coverage/lcov-report/src/utilities/redis.ts.html +12 -12
- package/coverage/lcov-report/src/utilities/templates.ts.html +6 -6
- package/coverage/lcov-report/src/utilities/users.ts.html +3 -3
- package/coverage/lcov.info +1383 -1214
- package/jest.config.ts +2 -0
- package/package.json +6 -6
- 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 +66 -5
- package/src/api/routes/global/tests/templates.spec.ts +89 -9
- package/src/api/routes/global/tests/users.spec.ts +2 -2
- package/src/constants/index.ts +13 -5
- package/src/tests/TestConfiguration.ts +9 -1
- 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/mocks/index.ts +2 -2
- package/src/tests/structures/groups.ts +1 -1
- package/src/tests/structures/users.ts +1 -1
- package/tsconfig.json +0 -1
package/jest.config.ts
CHANGED
|
@@ -19,6 +19,8 @@ if (!process.env.CI) {
|
|
|
19
19
|
}
|
|
20
20
|
// add pro sources if they exist
|
|
21
21
|
if (fs.existsSync("../../../budibase-pro")) {
|
|
22
|
+
config.moduleNameMapper["@budibase/pro/(.*)"] =
|
|
23
|
+
"<rootDir>/../../../budibase-pro/packages/pro/$1"
|
|
22
24
|
config.moduleNameMapper["@budibase/pro"] =
|
|
23
25
|
"<rootDir>/../../../budibase-pro/packages/pro/src"
|
|
24
26
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.1.46-alpha.
|
|
4
|
+
"version": "2.1.46-alpha.6",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"author": "Budibase",
|
|
37
37
|
"license": "GPL-3.0",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@budibase/backend-core": "2.1.46-alpha.
|
|
40
|
-
"@budibase/pro": "2.1.46-alpha.
|
|
41
|
-
"@budibase/string-templates": "2.1.46-alpha.
|
|
42
|
-
"@budibase/types": "2.1.46-alpha.
|
|
39
|
+
"@budibase/backend-core": "2.1.46-alpha.6",
|
|
40
|
+
"@budibase/pro": "2.1.46-alpha.5",
|
|
41
|
+
"@budibase/string-templates": "2.1.46-alpha.6",
|
|
42
|
+
"@budibase/types": "2.1.46-alpha.6",
|
|
43
43
|
"@koa/router": "8.0.8",
|
|
44
44
|
"@sentry/node": "6.17.7",
|
|
45
45
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"typescript": "4.7.3",
|
|
95
95
|
"update-dotenv": "1.1.1"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "694c0013a8e7380f5c8953a2be61a515e5fbf820"
|
|
98
98
|
}
|
|
@@ -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,11 +1,47 @@
|
|
|
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"
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
jest.mock("@budibase/backend-core", () => {
|
|
6
|
+
const core = jest.requireActual("@budibase/backend-core")
|
|
7
|
+
return {
|
|
8
|
+
...core,
|
|
9
|
+
db: {
|
|
10
|
+
...core.db,
|
|
11
|
+
},
|
|
12
|
+
context: {
|
|
13
|
+
...core.context,
|
|
14
|
+
getAppDB: jest.fn(),
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const appDb = db.getDB("app_test")
|
|
20
|
+
const mockAppDB = context.getAppDB as Mock
|
|
21
|
+
mockAppDB.mockReturnValue(appDb)
|
|
22
|
+
|
|
23
|
+
async function addAppMetadata() {
|
|
24
|
+
await appDb.put({
|
|
25
|
+
_id: "app_metadata",
|
|
26
|
+
appId: "app_test",
|
|
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 () => {
|
|
42
|
+
console.debug(role)
|
|
43
|
+
appDb.put(role)
|
|
44
|
+
await addAppMetadata()
|
|
9
45
|
await config.beforeAll()
|
|
10
46
|
})
|
|
11
47
|
|
|
@@ -18,10 +54,35 @@ describe("/api/global/roles", () => {
|
|
|
18
54
|
})
|
|
19
55
|
|
|
20
56
|
describe("GET /api/global/roles", () => {
|
|
21
|
-
it("retrieves roles", () => {
|
|
57
|
+
it("retrieves roles", async () => {
|
|
58
|
+
const res = await config.api.roles.get()
|
|
59
|
+
expect(res.body).toBeDefined()
|
|
60
|
+
expect(res.body["app_test"].roles.length).toEqual(5)
|
|
61
|
+
expect(res.body["app_test"].roles.map((r: any) => r._id)).toContain(
|
|
62
|
+
role._id
|
|
63
|
+
)
|
|
64
|
+
})
|
|
22
65
|
})
|
|
23
66
|
|
|
24
|
-
describe("GET
|
|
67
|
+
describe("GET api/global/roles/:appId", () => {
|
|
68
|
+
it("finds a role by appId", async () => {
|
|
69
|
+
const res = await config.api.roles.find("app_test")
|
|
70
|
+
expect(res.body).toBeDefined()
|
|
71
|
+
expect(res.body.name).toEqual("New App")
|
|
72
|
+
})
|
|
73
|
+
})
|
|
25
74
|
|
|
26
|
-
describe("DELETE /api/global/roles/:appId", () => {
|
|
75
|
+
describe("DELETE /api/global/roles/:appId", () => {
|
|
76
|
+
it("removes an app role", async () => {
|
|
77
|
+
let user = structures.users.user()
|
|
78
|
+
user.roles = {
|
|
79
|
+
app_test: "role1",
|
|
80
|
+
}
|
|
81
|
+
const userResponse = await config.createUser(user)
|
|
82
|
+
const res = await config.api.roles.remove("app_test")
|
|
83
|
+
const updatedUser = await config.api.users.getUser(userResponse._id!)
|
|
84
|
+
expect(updatedUser.body.roles).not.toHaveProperty("app_test")
|
|
85
|
+
expect(res.body.message).toEqual("App role removed from all users")
|
|
86
|
+
})
|
|
87
|
+
})
|
|
27
88
|
})
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addBaseTemplates,
|
|
3
|
+
EmailTemplates,
|
|
4
|
+
getTemplates,
|
|
5
|
+
} from "../../../../constants/templates"
|
|
6
|
+
import {
|
|
7
|
+
EmailTemplatePurpose,
|
|
8
|
+
TemplateMetadata,
|
|
9
|
+
TemplateMetadataNames,
|
|
10
|
+
TemplateType,
|
|
11
|
+
} from "../../../../constants"
|
|
1
12
|
import { TestConfiguration } from "../../../../tests"
|
|
13
|
+
import { join } from "path"
|
|
14
|
+
import { readStaticFile } from "../../../../../src/utilities/fileSystem"
|
|
2
15
|
|
|
3
16
|
// TODO
|
|
4
17
|
|
|
@@ -18,18 +31,85 @@ describe("/api/global/template", () => {
|
|
|
18
31
|
})
|
|
19
32
|
|
|
20
33
|
describe("GET /api/global/template/definitions", () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
describe("POST /api/global/template", () => {})
|
|
34
|
+
describe("retrieves definitions", () => {
|
|
35
|
+
it("checks description definitions", async () => {
|
|
36
|
+
let result = await config.api.templates.definitions()
|
|
25
37
|
|
|
26
|
-
|
|
38
|
+
expect(result.body.info[EmailTemplatePurpose.BASE].description).toEqual(
|
|
39
|
+
TemplateMetadata[TemplateType.EMAIL][0].description
|
|
40
|
+
)
|
|
41
|
+
expect(
|
|
42
|
+
result.body.info[EmailTemplatePurpose.PASSWORD_RECOVERY].description
|
|
43
|
+
).toEqual(TemplateMetadata[TemplateType.EMAIL][1].description)
|
|
44
|
+
expect(
|
|
45
|
+
result.body.info[EmailTemplatePurpose.WELCOME].description
|
|
46
|
+
).toEqual(TemplateMetadata[TemplateType.EMAIL][2].description)
|
|
47
|
+
expect(
|
|
48
|
+
result.body.info[EmailTemplatePurpose.INVITATION].description
|
|
49
|
+
).toEqual(TemplateMetadata[TemplateType.EMAIL][3].description)
|
|
50
|
+
expect(
|
|
51
|
+
result.body.info[EmailTemplatePurpose.CUSTOM].description
|
|
52
|
+
).toEqual(TemplateMetadata[TemplateType.EMAIL][4].description)
|
|
53
|
+
})
|
|
27
54
|
|
|
28
|
-
|
|
55
|
+
it("checks description bindings", async () => {
|
|
56
|
+
let result = await config.api.templates.definitions()
|
|
29
57
|
|
|
30
|
-
|
|
58
|
+
expect(result.body.bindings[EmailTemplatePurpose.BASE]).toEqual(
|
|
59
|
+
TemplateMetadata[TemplateType.EMAIL][0].bindings
|
|
60
|
+
)
|
|
61
|
+
expect(
|
|
62
|
+
result.body.bindings[EmailTemplatePurpose.PASSWORD_RECOVERY]
|
|
63
|
+
).toEqual(TemplateMetadata[TemplateType.EMAIL][1].bindings)
|
|
64
|
+
expect(result.body.bindings[EmailTemplatePurpose.WELCOME]).toEqual(
|
|
65
|
+
TemplateMetadata[TemplateType.EMAIL][2].bindings
|
|
66
|
+
)
|
|
67
|
+
expect(result.body.bindings[EmailTemplatePurpose.INVITATION]).toEqual(
|
|
68
|
+
TemplateMetadata[TemplateType.EMAIL][3].bindings
|
|
69
|
+
)
|
|
70
|
+
expect(result.body.bindings[EmailTemplatePurpose.CUSTOM]).toEqual(
|
|
71
|
+
TemplateMetadata[TemplateType.EMAIL][4].bindings
|
|
72
|
+
)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
})
|
|
31
76
|
|
|
32
|
-
describe("
|
|
77
|
+
describe("POST /api/global/template", () => {
|
|
78
|
+
it("adds a new template", async () => {
|
|
79
|
+
let purpose = "base"
|
|
80
|
+
let contents = "Test contents"
|
|
81
|
+
let updatedTemplate = {
|
|
82
|
+
contents: contents,
|
|
83
|
+
purpose: purpose,
|
|
84
|
+
type: "email",
|
|
85
|
+
}
|
|
86
|
+
await config.api.templates.saveTemplate(updatedTemplate)
|
|
87
|
+
let res = await config.api.templates.getTemplate()
|
|
88
|
+
let newTemplate = res.body.find((t: any) => (t.purpose = purpose))
|
|
89
|
+
expect(newTemplate.contents).toEqual(contents)
|
|
90
|
+
})
|
|
91
|
+
})
|
|
33
92
|
|
|
34
|
-
describe("
|
|
93
|
+
describe("GET /api/global/template", () => {
|
|
94
|
+
it("fetches templates", async () => {
|
|
95
|
+
let res = await config.api.templates.getTemplate()
|
|
96
|
+
expect(
|
|
97
|
+
res.body.find((t: any) => t.purpose === EmailTemplatePurpose.BASE)
|
|
98
|
+
).toBeDefined()
|
|
99
|
+
expect(
|
|
100
|
+
res.body.find((t: any) => t.purpose === EmailTemplatePurpose.CUSTOM)
|
|
101
|
+
).toBeDefined()
|
|
102
|
+
expect(
|
|
103
|
+
res.body.find((t: any) => t.purpose === EmailTemplatePurpose.INVITATION)
|
|
104
|
+
).toBeDefined()
|
|
105
|
+
expect(
|
|
106
|
+
res.body.find(
|
|
107
|
+
(t: any) => t.purpose === EmailTemplatePurpose.PASSWORD_RECOVERY
|
|
108
|
+
)
|
|
109
|
+
).toBeDefined()
|
|
110
|
+
expect(
|
|
111
|
+
res.body.find((t: any) => t.purpose === EmailTemplatePurpose.WELCOME)
|
|
112
|
+
).toBeDefined()
|
|
113
|
+
})
|
|
114
|
+
})
|
|
35
115
|
})
|
|
@@ -116,7 +116,7 @@ describe("/api/global/users", () => {
|
|
|
116
116
|
|
|
117
117
|
it("should ignore users existing in other tenants", async () => {
|
|
118
118
|
const user = await config.createUser()
|
|
119
|
-
jest.
|
|
119
|
+
jest.clearAllMocks()
|
|
120
120
|
|
|
121
121
|
await tenancy.doInTenant(TENANT_1, async () => {
|
|
122
122
|
const response = await config.api.users.bulkCreateUsers([user])
|
|
@@ -229,7 +229,7 @@ describe("/api/global/users", () => {
|
|
|
229
229
|
|
|
230
230
|
it("should not be able to create user that exists in other tenant", async () => {
|
|
231
231
|
const user = await config.createUser()
|
|
232
|
-
jest.
|
|
232
|
+
jest.clearAllMocks()
|
|
233
233
|
|
|
234
234
|
await tenancy.doInTenant(TENANT_1, async () => {
|
|
235
235
|
delete user._id
|
package/src/constants/index.ts
CHANGED
|
@@ -27,6 +27,14 @@ export enum EmailTemplatePurpose {
|
|
|
27
27
|
CUSTOM = "custom",
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
export enum TemplateMetadataNames {
|
|
31
|
+
BASE = "Base format",
|
|
32
|
+
PASSWORD_RECOVERY = "Password recovery",
|
|
33
|
+
WELCOME = "User welcome",
|
|
34
|
+
INVITATION = "User invitation",
|
|
35
|
+
CUSTOM = "Custom",
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
export enum InternalTemplateBinding {
|
|
31
39
|
PLATFORM_URL = "platformUrl",
|
|
32
40
|
COMPANY = "company",
|
|
@@ -93,7 +101,7 @@ export const TemplateBindings = {
|
|
|
93
101
|
export const TemplateMetadata = {
|
|
94
102
|
[TemplateType.EMAIL]: [
|
|
95
103
|
{
|
|
96
|
-
name:
|
|
104
|
+
name: TemplateMetadataNames.BASE,
|
|
97
105
|
description:
|
|
98
106
|
"This is the base template, all others are based on it. The {{ body }} will be replaced with another email template.",
|
|
99
107
|
category: "miscellaneous",
|
|
@@ -110,7 +118,7 @@ export const TemplateMetadata = {
|
|
|
110
118
|
],
|
|
111
119
|
},
|
|
112
120
|
{
|
|
113
|
-
name:
|
|
121
|
+
name: TemplateMetadataNames.PASSWORD_RECOVERY,
|
|
114
122
|
description:
|
|
115
123
|
"When a user requests a password reset they will receive an email built with this template.",
|
|
116
124
|
category: "user management",
|
|
@@ -129,7 +137,7 @@ export const TemplateMetadata = {
|
|
|
129
137
|
],
|
|
130
138
|
},
|
|
131
139
|
{
|
|
132
|
-
name:
|
|
140
|
+
name: TemplateMetadataNames.WELCOME,
|
|
133
141
|
description:
|
|
134
142
|
"When a new user is added they will be sent a welcome email using this template.",
|
|
135
143
|
category: "user management",
|
|
@@ -137,7 +145,7 @@ export const TemplateMetadata = {
|
|
|
137
145
|
bindings: [],
|
|
138
146
|
},
|
|
139
147
|
{
|
|
140
|
-
name:
|
|
148
|
+
name: TemplateMetadataNames.INVITATION,
|
|
141
149
|
description:
|
|
142
150
|
"When inviting a user via the email on-boarding this template will be used.",
|
|
143
151
|
category: "user management",
|
|
@@ -156,7 +164,7 @@ export const TemplateMetadata = {
|
|
|
156
164
|
],
|
|
157
165
|
},
|
|
158
166
|
{
|
|
159
|
-
name:
|
|
167
|
+
name: TemplateMetadataNames.CUSTOM,
|
|
160
168
|
description:
|
|
161
169
|
"A custom template, this is currently used for SMTP email actions in automations.",
|
|
162
170
|
category: "automations",
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import "./mocks"
|
|
1
|
+
import mocks from "./mocks"
|
|
2
|
+
|
|
3
|
+
// init the licensing mock
|
|
4
|
+
import * as pro from "@budibase/pro"
|
|
5
|
+
mocks.licenses.init(pro)
|
|
6
|
+
|
|
7
|
+
// use unlimited license by default
|
|
8
|
+
mocks.licenses.useUnlimited()
|
|
9
|
+
|
|
2
10
|
import * as dbConfig from "../db"
|
|
3
11
|
dbConfig.init()
|
|
4
12
|
import env from "../environment"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { UserGroup } from "@budibase/types"
|
|
2
|
+
import TestConfiguration from "../TestConfiguration"
|
|
3
|
+
import { TestAPI } from "./base"
|
|
4
|
+
|
|
5
|
+
export class GroupsAPI extends TestAPI {
|
|
6
|
+
constructor(config: TestConfiguration) {
|
|
7
|
+
super(config)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
saveGroup = (group: UserGroup) => {
|
|
11
|
+
return this.request
|
|
12
|
+
.post(`/api/global/groups`)
|
|
13
|
+
.send(group)
|
|
14
|
+
.set(this.config.defaultHeaders())
|
|
15
|
+
.expect("Content-Type", /json/)
|
|
16
|
+
.expect(200)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
deleteGroup = (id: string, rev: string) => {
|
|
20
|
+
return this.request
|
|
21
|
+
.delete(`/api/global/groups/${id}/${rev}`)
|
|
22
|
+
.set(this.config.defaultHeaders())
|
|
23
|
+
.expect("Content-Type", /json/)
|
|
24
|
+
.expect(200)
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/tests/api/index.ts
CHANGED
|
@@ -10,7 +10,10 @@ import { MigrationAPI } from "./migrations"
|
|
|
10
10
|
import { StatusAPI } from "./status"
|
|
11
11
|
import { RestoreAPI } from "./restore"
|
|
12
12
|
import { TenantAPI } from "./tenants"
|
|
13
|
-
|
|
13
|
+
import { GroupsAPI } from "./groups"
|
|
14
|
+
import { RolesAPI } from "./roles"
|
|
15
|
+
import { TemplatesAPI } from "./templates"
|
|
16
|
+
import { LicenseAPI } from "./license"
|
|
14
17
|
export default class API {
|
|
15
18
|
accounts: AccountAPI
|
|
16
19
|
auth: AuthAPI
|
|
@@ -23,6 +26,10 @@ export default class API {
|
|
|
23
26
|
status: StatusAPI
|
|
24
27
|
restore: RestoreAPI
|
|
25
28
|
tenants: TenantAPI
|
|
29
|
+
groups: GroupsAPI
|
|
30
|
+
roles: RolesAPI
|
|
31
|
+
templates: TemplatesAPI
|
|
32
|
+
license: LicenseAPI
|
|
26
33
|
|
|
27
34
|
constructor(config: TestConfiguration) {
|
|
28
35
|
this.accounts = new AccountAPI(config)
|
|
@@ -36,5 +43,9 @@ export default class API {
|
|
|
36
43
|
this.status = new StatusAPI(config)
|
|
37
44
|
this.restore = new RestoreAPI(config)
|
|
38
45
|
this.tenants = new TenantAPI(config)
|
|
46
|
+
this.groups = new GroupsAPI(config)
|
|
47
|
+
this.roles = new RolesAPI(config)
|
|
48
|
+
this.templates = new TemplatesAPI(config)
|
|
49
|
+
this.license = new LicenseAPI(config)
|
|
39
50
|
}
|
|
40
51
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import TestConfiguration from "../TestConfiguration"
|
|
2
|
+
import { TestAPI } from "./base"
|
|
3
|
+
|
|
4
|
+
export class LicenseAPI extends TestAPI {
|
|
5
|
+
constructor(config: TestConfiguration) {
|
|
6
|
+
super(config)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
activate = async (licenseKey: string) => {
|
|
10
|
+
return this.request
|
|
11
|
+
.post("/api/global/license/activate")
|
|
12
|
+
.send({ licenseKey: licenseKey })
|
|
13
|
+
.set(this.config.defaultHeaders())
|
|
14
|
+
.expect("Content-Type", /json/)
|
|
15
|
+
.expect(200)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import TestConfiguration from "../TestConfiguration"
|
|
2
|
+
import { TestAPI, TestAPIOpts } from "./base"
|
|
3
|
+
|
|
4
|
+
export class RolesAPI extends TestAPI {
|
|
5
|
+
constructor(config: TestConfiguration) {
|
|
6
|
+
super(config)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get = (opts?: TestAPIOpts) => {
|
|
10
|
+
return this.request
|
|
11
|
+
.get(`/api/global/roles`)
|
|
12
|
+
.set(this.config.defaultHeaders())
|
|
13
|
+
.expect("Content-Type", /json/)
|
|
14
|
+
.expect(opts?.status ? opts.status : 200)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
find = (appId: string, opts?: TestAPIOpts) => {
|
|
18
|
+
return this.request
|
|
19
|
+
.get(`/api/global/roles/${appId}`)
|
|
20
|
+
.set(this.config.defaultHeaders())
|
|
21
|
+
.expect("Content-Type", /json/)
|
|
22
|
+
.expect(opts?.status ? opts.status : 200)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
remove = (appId: string, opts?: TestAPIOpts) => {
|
|
26
|
+
return this.request
|
|
27
|
+
.delete(`/api/global/roles/${appId}`)
|
|
28
|
+
.set(this.config.defaultHeaders())
|
|
29
|
+
.expect("Content-Type", /json/)
|
|
30
|
+
.expect(opts?.status ? opts.status : 200)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import TestConfiguration from "../TestConfiguration"
|
|
2
|
+
import { TestAPI, TestAPIOpts } from "./base"
|
|
3
|
+
|
|
4
|
+
export class TemplatesAPI extends TestAPI {
|
|
5
|
+
constructor(config: TestConfiguration) {
|
|
6
|
+
super(config)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
definitions = (opts?: TestAPIOpts) => {
|
|
10
|
+
return this.request
|
|
11
|
+
.get(`/api/global/template/definitions`)
|
|
12
|
+
.set(opts?.headers ? opts.headers : this.config.defaultHeaders())
|
|
13
|
+
.expect(opts?.status ? opts.status : 200)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getTemplate = (opts?: TestAPIOpts) => {
|
|
17
|
+
return this.request
|
|
18
|
+
.get(`/api/global/template`)
|
|
19
|
+
.set(opts?.headers ? opts.headers : this.config.defaultHeaders())
|
|
20
|
+
.expect(opts?.status ? opts.status : 200)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
saveTemplate = (data: any, opts?: TestAPIOpts) => {
|
|
24
|
+
return this.request
|
|
25
|
+
.post(`/api/global/template`)
|
|
26
|
+
.send(data)
|
|
27
|
+
.set(opts?.headers ? opts.headers : this.config.defaultHeaders())
|
|
28
|
+
.expect(opts?.status ? opts.status : 200)
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/tests/mocks/index.ts
CHANGED