@budibase/worker 2.2.9 → 2.2.10-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.
Files changed (134) hide show
  1. package/coverage/clover.xml +1291 -1238
  2. package/coverage/coverage-final.json +81 -77
  3. package/coverage/lcov-report/index.html +73 -73
  4. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +26 -26
  5. package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +155 -212
  6. package/coverage/lcov-report/src/api/controllers/global/email.ts.html +4 -4
  7. package/coverage/lcov-report/src/api/controllers/global/index.html +39 -39
  8. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +7 -7
  9. package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +76 -76
  10. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +14 -14
  11. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +53 -53
  12. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +27 -27
  13. package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +6 -6
  14. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +4 -4
  15. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +3 -3
  16. package/coverage/lcov-report/src/api/controllers/system/index.html +1 -1
  17. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +4 -4
  18. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +4 -4
  19. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +4 -4
  20. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +5 -5
  21. package/coverage/lcov-report/src/api/index.html +1 -1
  22. package/coverage/lcov-report/src/api/index.ts.html +23 -23
  23. package/coverage/lcov-report/src/api/routes/global/auth.ts.html +11 -11
  24. package/coverage/lcov-report/src/api/routes/global/configs.ts.html +16 -16
  25. package/coverage/lcov-report/src/api/routes/global/email.ts.html +10 -10
  26. package/coverage/lcov-report/src/api/routes/global/index.html +1 -1
  27. package/coverage/lcov-report/src/api/routes/global/license.ts.html +7 -7
  28. package/coverage/lcov-report/src/api/routes/global/roles.ts.html +7 -7
  29. package/coverage/lcov-report/src/api/routes/global/self.ts.html +8 -8
  30. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +11 -11
  31. package/coverage/lcov-report/src/api/routes/global/users.ts.html +16 -16
  32. package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +9 -9
  33. package/coverage/lcov-report/src/api/routes/index.html +1 -1
  34. package/coverage/lcov-report/src/api/routes/index.ts.html +19 -19
  35. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +7 -7
  36. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +6 -6
  37. package/coverage/lcov-report/src/api/routes/system/index.html +1 -1
  38. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +7 -7
  39. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +6 -6
  40. package/coverage/lcov-report/src/api/routes/system/status.ts.html +6 -6
  41. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +7 -7
  42. package/coverage/lcov-report/src/api/routes/validation/index.html +1 -1
  43. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +2 -2
  44. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +13 -13
  45. package/coverage/lcov-report/src/constants/index.html +9 -9
  46. package/coverage/lcov-report/src/constants/index.ts.html +73 -49
  47. package/coverage/lcov-report/src/constants/templates/index.html +19 -19
  48. package/coverage/lcov-report/src/constants/templates/index.ts.html +39 -39
  49. package/coverage/lcov-report/src/db/index.html +1 -1
  50. package/coverage/lcov-report/src/db/index.ts.html +8 -8
  51. package/coverage/lcov-report/src/environment.ts.html +37 -22
  52. package/coverage/lcov-report/src/index.html +15 -15
  53. package/coverage/lcov-report/src/index.ts.html +40 -43
  54. package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +4 -4
  55. package/coverage/lcov-report/src/middleware/index.html +1 -1
  56. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +3 -3
  57. package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
  58. package/coverage/lcov-report/src/migrations/index.html +1 -1
  59. package/coverage/lcov-report/src/migrations/index.ts.html +17 -17
  60. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +6 -6
  61. package/coverage/lcov-report/src/sdk/accounts/index.html +1 -1
  62. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +2 -2
  63. package/coverage/lcov-report/src/sdk/index.html +1 -1
  64. package/coverage/lcov-report/src/sdk/index.ts.html +4 -4
  65. package/coverage/lcov-report/src/sdk/users/events.ts.html +46 -46
  66. package/coverage/lcov-report/src/sdk/users/index.html +15 -15
  67. package/coverage/lcov-report/src/sdk/users/index.ts.html +2 -2
  68. package/coverage/lcov-report/src/sdk/users/users.ts.html +148 -97
  69. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +104 -80
  70. package/coverage/lcov-report/src/tests/api/accounts.ts.html +6 -6
  71. package/coverage/lcov-report/src/tests/api/auth.ts.html +7 -7
  72. package/coverage/lcov-report/src/tests/api/base.ts.html +4 -4
  73. package/coverage/lcov-report/src/tests/api/configs.ts.html +8 -8
  74. package/coverage/lcov-report/src/tests/api/email.ts.html +5 -5
  75. package/coverage/lcov-report/src/tests/api/environment.ts.html +5 -5
  76. package/coverage/lcov-report/src/tests/api/groups.ts.html +163 -0
  77. package/coverage/lcov-report/src/tests/api/index.html +71 -11
  78. package/coverage/lcov-report/src/tests/api/index.ts.html +61 -28
  79. package/coverage/lcov-report/src/tests/api/license.ts.html +136 -0
  80. package/coverage/lcov-report/src/tests/api/migrations.ts.html +6 -6
  81. package/coverage/lcov-report/src/tests/api/restore.ts.html +5 -5
  82. package/coverage/lcov-report/src/tests/api/roles.ts.html +181 -0
  83. package/coverage/lcov-report/src/tests/api/self.ts.html +6 -6
  84. package/coverage/lcov-report/src/tests/api/status.ts.html +5 -5
  85. package/coverage/lcov-report/src/tests/api/templates.ts.html +175 -0
  86. package/coverage/lcov-report/src/tests/api/tenants.ts.html +5 -5
  87. package/coverage/lcov-report/src/tests/api/users.ts.html +16 -16
  88. package/coverage/lcov-report/src/tests/controllers.ts.html +6 -6
  89. package/coverage/lcov-report/src/tests/index.html +10 -10
  90. package/coverage/lcov-report/src/tests/index.ts.html +9 -9
  91. package/coverage/lcov-report/src/tests/mocks/{email.js.html → email.ts.html} +5 -5
  92. package/coverage/lcov-report/src/tests/mocks/index.html +2 -2
  93. package/coverage/lcov-report/src/tests/mocks/index.ts.html +7 -7
  94. package/coverage/lcov-report/src/tests/structures/configs.ts.html +10 -10
  95. package/coverage/lcov-report/src/tests/structures/groups.ts.html +15 -15
  96. package/coverage/lcov-report/src/tests/structures/index.html +16 -16
  97. package/coverage/lcov-report/src/tests/structures/index.ts.html +11 -11
  98. package/coverage/lcov-report/src/tests/structures/users.ts.html +11 -11
  99. package/coverage/lcov-report/src/utilities/appService.ts.html +10 -10
  100. package/coverage/lcov-report/src/utilities/email.ts.html +15 -15
  101. package/coverage/lcov-report/src/utilities/fileSystem.ts.html +4 -4
  102. package/coverage/lcov-report/src/utilities/index.html +1 -1
  103. package/coverage/lcov-report/src/utilities/index.ts.html +2 -2
  104. package/coverage/lcov-report/src/utilities/redis.ts.html +12 -12
  105. package/coverage/lcov-report/src/utilities/templates.ts.html +6 -6
  106. package/coverage/lcov-report/src/utilities/users.ts.html +3 -3
  107. package/coverage/lcov.info +1949 -1779
  108. package/jest.config.ts +2 -0
  109. package/package.json +8 -7
  110. package/src/api/controllers/global/configs.ts +112 -131
  111. package/src/api/controllers/global/users.ts +1 -1
  112. package/src/api/routes/global/license.ts +1 -1
  113. package/src/api/routes/global/tests/groups.spec.ts +58 -0
  114. package/src/api/routes/global/tests/license.spec.ts +0 -2
  115. package/src/api/routes/global/tests/roles.spec.ts +66 -5
  116. package/src/api/routes/global/tests/templates.spec.ts +89 -9
  117. package/src/api/routes/global/tests/users.spec.ts +2 -2
  118. package/src/constants/index.ts +13 -5
  119. package/src/environment.ts +5 -0
  120. package/src/index.ts +1 -2
  121. package/src/sdk/users/users.ts +18 -1
  122. package/src/tests/TestConfiguration.ts +9 -1
  123. package/src/tests/api/groups.ts +26 -0
  124. package/src/tests/api/index.ts +12 -1
  125. package/src/tests/api/license.ts +17 -0
  126. package/src/tests/api/roles.ts +32 -0
  127. package/src/tests/api/templates.ts +30 -0
  128. package/src/tests/jestSetup.ts +3 -1
  129. package/src/tests/mocks/{email.js → email.ts} +1 -1
  130. package/src/tests/mocks/index.ts +3 -3
  131. package/src/tests/structures/configs.ts +2 -2
  132. package/src/tests/structures/groups.ts +1 -1
  133. package/src/tests/structures/users.ts +1 -1
  134. package/tsconfig.json +0 -1
@@ -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
- it("retrieves definitions", () => {})
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
- describe("GET /api/global/template", () => {})
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
- describe("GET /api/global/template/:type", () => {})
55
+ it("checks description bindings", async () => {
56
+ let result = await config.api.templates.definitions()
29
57
 
30
- describe("GET /api/global/template/:ownerId", () => {})
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("GET /api/global/template/:id", () => {})
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("DELETE /api/global/template/:id/:rev", () => {})
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.resetAllMocks()
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.resetAllMocks()
232
+ jest.clearAllMocks()
233
233
 
234
234
  await tenancy.doInTenant(TENANT_1, async () => {
235
235
  delete user._id
@@ -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: "Base format",
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: "Password recovery",
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: "User welcome",
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: "User invitation",
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: "Custom",
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",
@@ -91,6 +91,11 @@ for (let [key, value] of Object.entries(environment)) {
91
91
  // @ts-ignore
92
92
  environment[key] = 0
93
93
  }
94
+ // handle the edge case of "false" to disable an environment variable
95
+ if (value === "false") {
96
+ // @ts-ignore
97
+ environment[key] = 0
98
+ }
94
99
  }
95
100
 
96
101
  export = environment
package/src/index.ts CHANGED
@@ -24,7 +24,7 @@ import * as redis from "./utilities/redis"
24
24
  const Sentry = require("@sentry/node")
25
25
  const koaSession = require("koa-session")
26
26
  const logger = require("koa-pino-logger")
27
- const destroyable = require("server-destroy")
27
+ import destroyable from "server-destroy"
28
28
 
29
29
  // this will setup http and https proxies form env variables
30
30
  bootstrap()
@@ -79,7 +79,6 @@ server.on("close", async () => {
79
79
 
80
80
  const shutdown = () => {
81
81
  server.close()
82
- // @ts-ignore
83
82
  server.destroy()
84
83
  }
85
84
 
@@ -25,6 +25,7 @@ import {
25
25
  InviteUsersRequest,
26
26
  InviteUsersResponse,
27
27
  MigrationType,
28
+ PlatformUser,
28
29
  PlatformUserByEmail,
29
30
  RowResponse,
30
31
  SearchUsersRequest,
@@ -153,10 +154,26 @@ const buildUser = async (
153
154
  return fullUser
154
155
  }
155
156
 
157
+ // lookup, could be email or userId, either will return a doc
158
+ export const getPlatformUser = async (
159
+ identifier: string
160
+ ): Promise<PlatformUser | null> => {
161
+ // use the view here and allow to find anyone regardless of casing
162
+ // Use lowercase to ensure email login is case insensitive
163
+ const response = dbUtils.queryPlatformView(
164
+ ViewName.PLATFORM_USERS_LOWERCASE,
165
+ {
166
+ keys: [identifier.toLowerCase()],
167
+ include_docs: true,
168
+ }
169
+ ) as Promise<PlatformUser>
170
+ return response
171
+ }
172
+
156
173
  const validateUniqueUser = async (email: string, tenantId: string) => {
157
174
  // check budibase users in other tenants
158
175
  if (env.MULTI_TENANCY) {
159
- const tenantUser = await tenancy.getTenantUser(email)
176
+ const tenantUser = await getPlatformUser(email)
160
177
  if (tenantUser != null && tenantUser.tenantId !== tenantId) {
161
178
  throw `Unavailable`
162
179
  }
@@ -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
+ }
@@ -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
+ }
@@ -22,7 +22,9 @@ mocks.fetch.enable()
22
22
  const tk = require("timekeeper")
23
23
  tk.freeze(mocks.date.MOCK_DATE)
24
24
 
25
- global.console.log = jest.fn() // console.log are ignored in tests
25
+ if (!process.env.DEBUG) {
26
+ global.console.log = jest.fn() // console.log are ignored in tests
27
+ }
26
28
 
27
29
  if (!process.env.CI) {
28
30
  // set a longer timeout in dev for debugging
@@ -1,4 +1,4 @@
1
- exports.mock = () => {
1
+ export function mock() {
2
2
  // mock the email system
3
3
  const sendMailMock = jest.fn()
4
4
  const nodemailer = require("nodemailer")
@@ -1,7 +1,7 @@
1
- const email = require("./email")
2
- import { mocks as coreMocks } from "@budibase/backend-core/tests"
1
+ import * as email from "./email"
2
+ import { mocks } from "@budibase/backend-core/tests"
3
3
 
4
4
  export = {
5
5
  email,
6
- ...coreMocks,
6
+ ...mocks,
7
7
  }
@@ -1,5 +1,5 @@
1
- const { Config } = require("../../constants")
2
- const { utils } = require("@budibase/backend-core")
1
+ import { Config } from "../../constants"
2
+ import { utils } from "@budibase/backend-core"
3
3
 
4
4
  export function oidc(conf?: any) {
5
5
  return {
@@ -4,7 +4,7 @@ export const UserGroup = () => {
4
4
  color: "var(--spectrum-global-color-blue-600)",
5
5
  icon: "UserGroup",
6
6
  name: "New group",
7
- roles: {},
7
+ roles: { app_uuid1: "ADMIN", app_uuid2: "POWER" },
8
8
  users: [],
9
9
  }
10
10
  return group
@@ -10,7 +10,7 @@ export const user = (userProps?: any): User => {
10
10
  return {
11
11
  email: newEmail(),
12
12
  password: "test",
13
- roles: {},
13
+ roles: { app_test: "admin" },
14
14
  ...userProps,
15
15
  }
16
16
  }
package/tsconfig.json CHANGED
@@ -25,7 +25,6 @@
25
25
  "package.json"
26
26
  ],
27
27
  "exclude": [
28
- "node_modules",
29
28
  "dist"
30
29
  ]
31
30
  }