@budibase/worker 1.2.58-alpha.4 → 1.2.58
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/package.json +6 -7
- package/scripts/jestSetup.js +0 -6
- package/scripts/load/users.js +97 -0
- package/src/api/controllers/global/auth.ts +1 -14
- package/src/api/controllers/global/users.ts +8 -6
- package/src/api/{index.ts → index.js} +16 -12
- package/src/api/routes/global/configs.js +0 -1
- package/src/api/routes/index.js +0 -2
- package/src/api/routes/{global/tests/auth.spec.ts → tests/auth.spec.js} +56 -32
- package/src/api/routes/{global/tests/configs.spec.ts → tests/configs.spec.js} +47 -76
- package/src/api/routes/{global/tests/email.spec.ts → tests/email.spec.js} +15 -7
- package/src/api/routes/{global/tests/realEmail.spec.ts → tests/realEmail.spec.js} +21 -20
- package/src/api/routes/{global/tests/self.spec.ts → tests/self.spec.js} +18 -10
- package/src/api/routes/tests/users.spec.js +390 -0
- package/src/{environment.ts → environment.js} +9 -10
- package/src/index.ts +4 -6
- package/src/sdk/index.ts +0 -1
- package/src/sdk/users/users.ts +77 -217
- package/src/tests/TestConfiguration.js +231 -0
- package/src/tests/index.js +12 -0
- package/src/tests/mocks/index.js +5 -0
- package/src/tests/structures/index.js +14 -0
- package/src/tests/structures/users.ts +4 -12
- package/src/utilities/redis.js +0 -1
- package/src/api/controllers/system/accounts.ts +0 -21
- package/src/api/routes/global/tests/users.spec.ts +0 -464
- package/src/api/routes/system/accounts.ts +0 -19
- package/src/api/routes/system/tests/accounts.spec.ts +0 -57
- package/src/sdk/accounts/accounts.ts +0 -53
- package/src/sdk/accounts/index.ts +0 -1
- package/src/tests/TestConfiguration.ts +0 -273
- package/src/tests/api/accounts.ts +0 -28
- package/src/tests/api/auth.ts +0 -48
- package/src/tests/api/configs.ts +0 -40
- package/src/tests/api/email.ts +0 -24
- package/src/tests/api/index.ts +0 -25
- package/src/tests/api/self.ts +0 -21
- package/src/tests/api/users.ts +0 -95
- package/src/tests/index.ts +0 -14
- package/src/tests/mocks/index.ts +0 -7
- package/src/tests/structures/accounts.ts +0 -24
- package/src/tests/structures/index.ts +0 -20
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// mock the email system
|
|
2
2
|
jest.mock("nodemailer")
|
|
3
|
-
|
|
3
|
+
const { config, structures, mocks, request } = require("../../../tests")
|
|
4
4
|
mocks.email.mock()
|
|
5
|
-
|
|
5
|
+
const { Configs } = require("@budibase/backend-core/constants")
|
|
6
|
+
const { events } = require("@budibase/backend-core")
|
|
6
7
|
|
|
7
8
|
describe("configs", () => {
|
|
8
|
-
const config = new TestConfiguration()
|
|
9
|
-
const api = new API(config)
|
|
10
9
|
|
|
11
10
|
beforeAll(async () => {
|
|
12
11
|
await config.beforeAll()
|
|
@@ -21,33 +20,35 @@ describe("configs", () => {
|
|
|
21
20
|
})
|
|
22
21
|
|
|
23
22
|
describe("post /api/global/configs", () => {
|
|
24
|
-
|
|
23
|
+
|
|
24
|
+
const saveConfig = async (conf, _id, _rev) => {
|
|
25
25
|
const data = {
|
|
26
26
|
...conf,
|
|
27
27
|
_id,
|
|
28
|
-
_rev
|
|
28
|
+
_rev
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const res = await
|
|
31
|
+
const res = await request
|
|
32
|
+
.post(`/api/global/configs`)
|
|
33
|
+
.send(data)
|
|
34
|
+
.set(config.defaultHeaders())
|
|
35
|
+
.expect("Content-Type", /json/)
|
|
36
|
+
.expect(200)
|
|
32
37
|
|
|
33
38
|
return {
|
|
34
39
|
...data,
|
|
35
|
-
...res.body
|
|
40
|
+
...res.body
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
describe("google", () => {
|
|
40
|
-
const saveGoogleConfig = async (
|
|
41
|
-
conf?: any,
|
|
42
|
-
_id?: string,
|
|
43
|
-
_rev?: string
|
|
44
|
-
) => {
|
|
45
|
+
const saveGoogleConfig = async (conf, _id, _rev) => {
|
|
45
46
|
const googleConfig = structures.configs.google(conf)
|
|
46
47
|
return saveConfig(googleConfig, _id, _rev)
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
+
|
|
49
50
|
describe("create", () => {
|
|
50
|
-
it("should create activated google config", async () => {
|
|
51
|
+
it ("should create activated google config", async () => {
|
|
51
52
|
await saveGoogleConfig()
|
|
52
53
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
53
54
|
expect(events.auth.SSOCreated).toBeCalledWith(Configs.GOOGLE)
|
|
@@ -57,7 +58,7 @@ describe("configs", () => {
|
|
|
57
58
|
await config.deleteConfig(Configs.GOOGLE)
|
|
58
59
|
})
|
|
59
60
|
|
|
60
|
-
it("should create deactivated google config", async () => {
|
|
61
|
+
it ("should create deactivated google config", async () => {
|
|
61
62
|
await saveGoogleConfig({ activated: false })
|
|
62
63
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
63
64
|
expect(events.auth.SSOCreated).toBeCalledWith(Configs.GOOGLE)
|
|
@@ -68,14 +69,10 @@ describe("configs", () => {
|
|
|
68
69
|
})
|
|
69
70
|
|
|
70
71
|
describe("update", () => {
|
|
71
|
-
it("should update google config to deactivated", async () => {
|
|
72
|
+
it ("should update google config to deactivated", async () => {
|
|
72
73
|
const googleConf = await saveGoogleConfig()
|
|
73
74
|
jest.clearAllMocks()
|
|
74
|
-
await saveGoogleConfig(
|
|
75
|
-
{ ...googleConf.config, activated: false },
|
|
76
|
-
googleConf._id,
|
|
77
|
-
googleConf._rev
|
|
78
|
-
)
|
|
75
|
+
await saveGoogleConfig({ ...googleConf.config, activated: false }, googleConf._id, googleConf._rev)
|
|
79
76
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
80
77
|
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.GOOGLE)
|
|
81
78
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
@@ -84,14 +81,10 @@ describe("configs", () => {
|
|
|
84
81
|
await config.deleteConfig(Configs.GOOGLE)
|
|
85
82
|
})
|
|
86
83
|
|
|
87
|
-
it("should update google config to activated", async () => {
|
|
84
|
+
it ("should update google config to activated", async () => {
|
|
88
85
|
const googleConf = await saveGoogleConfig({ activated: false })
|
|
89
86
|
jest.clearAllMocks()
|
|
90
|
-
await saveGoogleConfig(
|
|
91
|
-
{ ...googleConf.config, activated: true },
|
|
92
|
-
googleConf._id,
|
|
93
|
-
googleConf._rev
|
|
94
|
-
)
|
|
87
|
+
await saveGoogleConfig({ ...googleConf.config, activated: true}, googleConf._id, googleConf._rev)
|
|
95
88
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
96
89
|
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.GOOGLE)
|
|
97
90
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
@@ -99,21 +92,17 @@ describe("configs", () => {
|
|
|
99
92
|
expect(events.auth.SSOActivated).toBeCalledWith(Configs.GOOGLE)
|
|
100
93
|
await config.deleteConfig(Configs.GOOGLE)
|
|
101
94
|
})
|
|
102
|
-
})
|
|
95
|
+
})
|
|
103
96
|
})
|
|
104
97
|
|
|
105
98
|
describe("oidc", () => {
|
|
106
|
-
const saveOIDCConfig = async (
|
|
107
|
-
conf?: any,
|
|
108
|
-
_id?: string,
|
|
109
|
-
_rev?: string
|
|
110
|
-
) => {
|
|
99
|
+
const saveOIDCConfig = async (conf, _id, _rev) => {
|
|
111
100
|
const oidcConfig = structures.configs.oidc(conf)
|
|
112
101
|
return saveConfig(oidcConfig, _id, _rev)
|
|
113
102
|
}
|
|
114
103
|
|
|
115
104
|
describe("create", () => {
|
|
116
|
-
it("should create activated OIDC config", async () => {
|
|
105
|
+
it ("should create activated OIDC config", async () => {
|
|
117
106
|
await saveOIDCConfig()
|
|
118
107
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
119
108
|
expect(events.auth.SSOCreated).toBeCalledWith(Configs.OIDC)
|
|
@@ -123,7 +112,7 @@ describe("configs", () => {
|
|
|
123
112
|
await config.deleteConfig(Configs.OIDC)
|
|
124
113
|
})
|
|
125
114
|
|
|
126
|
-
it("should create deactivated OIDC config", async () => {
|
|
115
|
+
it ("should create deactivated OIDC config", async () => {
|
|
127
116
|
await saveOIDCConfig({ activated: false })
|
|
128
117
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
129
118
|
expect(events.auth.SSOCreated).toBeCalledWith(Configs.OIDC)
|
|
@@ -134,14 +123,10 @@ describe("configs", () => {
|
|
|
134
123
|
})
|
|
135
124
|
|
|
136
125
|
describe("update", () => {
|
|
137
|
-
it("should update OIDC config to deactivated", async () => {
|
|
126
|
+
it ("should update OIDC config to deactivated", async () => {
|
|
138
127
|
const oidcConf = await saveOIDCConfig()
|
|
139
128
|
jest.clearAllMocks()
|
|
140
|
-
await saveOIDCConfig(
|
|
141
|
-
{ ...oidcConf.config.configs[0], activated: false },
|
|
142
|
-
oidcConf._id,
|
|
143
|
-
oidcConf._rev
|
|
144
|
-
)
|
|
129
|
+
await saveOIDCConfig({ ...oidcConf.config.configs[0], activated: false }, oidcConf._id, oidcConf._rev)
|
|
145
130
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
146
131
|
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.OIDC)
|
|
147
132
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
@@ -150,14 +135,10 @@ describe("configs", () => {
|
|
|
150
135
|
await config.deleteConfig(Configs.OIDC)
|
|
151
136
|
})
|
|
152
137
|
|
|
153
|
-
it("should update OIDC config to activated", async () => {
|
|
138
|
+
it ("should update OIDC config to activated", async () => {
|
|
154
139
|
const oidcConf = await saveOIDCConfig({ activated: false })
|
|
155
140
|
jest.clearAllMocks()
|
|
156
|
-
await saveOIDCConfig(
|
|
157
|
-
{ ...oidcConf.config.configs[0], activated: true },
|
|
158
|
-
oidcConf._id,
|
|
159
|
-
oidcConf._rev
|
|
160
|
-
)
|
|
141
|
+
await saveOIDCConfig({ ...oidcConf.config.configs[0], activated: true}, oidcConf._id, oidcConf._rev)
|
|
161
142
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
162
143
|
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.OIDC)
|
|
163
144
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
@@ -166,20 +147,17 @@ describe("configs", () => {
|
|
|
166
147
|
await config.deleteConfig(Configs.OIDC)
|
|
167
148
|
})
|
|
168
149
|
})
|
|
150
|
+
|
|
169
151
|
})
|
|
170
152
|
|
|
171
153
|
describe("smtp", () => {
|
|
172
|
-
const saveSMTPConfig = async (
|
|
173
|
-
conf?: any,
|
|
174
|
-
_id?: string,
|
|
175
|
-
_rev?: string
|
|
176
|
-
) => {
|
|
154
|
+
const saveSMTPConfig = async (conf, _id, _rev) => {
|
|
177
155
|
const smtpConfig = structures.configs.smtp(conf)
|
|
178
156
|
return saveConfig(smtpConfig, _id, _rev)
|
|
179
157
|
}
|
|
180
158
|
|
|
181
159
|
describe("create", () => {
|
|
182
|
-
it("should create SMTP config", async () => {
|
|
160
|
+
it ("should create SMTP config", async () => {
|
|
183
161
|
await config.deleteConfig(Configs.SMTP)
|
|
184
162
|
await saveSMTPConfig()
|
|
185
163
|
expect(events.email.SMTPUpdated).not.toBeCalled()
|
|
@@ -189,7 +167,7 @@ describe("configs", () => {
|
|
|
189
167
|
})
|
|
190
168
|
|
|
191
169
|
describe("update", () => {
|
|
192
|
-
it("should update SMTP config", async () => {
|
|
170
|
+
it ("should update SMTP config", async () => {
|
|
193
171
|
const smtpConf = await saveSMTPConfig()
|
|
194
172
|
jest.clearAllMocks()
|
|
195
173
|
await saveSMTPConfig(smtpConf.config, smtpConf._id, smtpConf._rev)
|
|
@@ -201,19 +179,15 @@ describe("configs", () => {
|
|
|
201
179
|
})
|
|
202
180
|
|
|
203
181
|
describe("settings", () => {
|
|
204
|
-
const saveSettingsConfig = async (
|
|
205
|
-
conf?: any,
|
|
206
|
-
_id?: string,
|
|
207
|
-
_rev?: string
|
|
208
|
-
) => {
|
|
182
|
+
const saveSettingsConfig = async (conf, _id, _rev) => {
|
|
209
183
|
const settingsConfig = structures.configs.settings(conf)
|
|
210
184
|
return saveConfig(settingsConfig, _id, _rev)
|
|
211
185
|
}
|
|
212
186
|
|
|
213
187
|
describe("create", () => {
|
|
214
|
-
it("should create settings config with default settings", async () => {
|
|
188
|
+
it ("should create settings config with default settings", async () => {
|
|
215
189
|
await config.deleteConfig(Configs.SETTINGS)
|
|
216
|
-
|
|
190
|
+
|
|
217
191
|
await saveSettingsConfig()
|
|
218
192
|
|
|
219
193
|
expect(events.org.nameUpdated).not.toBeCalled()
|
|
@@ -221,43 +195,35 @@ describe("configs", () => {
|
|
|
221
195
|
expect(events.org.platformURLUpdated).not.toBeCalled()
|
|
222
196
|
})
|
|
223
197
|
|
|
224
|
-
it("should create settings config with non-default settings", async () => {
|
|
225
|
-
config.modeSelf()
|
|
198
|
+
it ("should create settings config with non-default settings", async () => {
|
|
226
199
|
await config.deleteConfig(Configs.SETTINGS)
|
|
227
200
|
const conf = {
|
|
228
201
|
company: "acme",
|
|
229
202
|
logoUrl: "http://example.com",
|
|
230
|
-
platformUrl: "http://example.com"
|
|
203
|
+
platformUrl: "http://example.com"
|
|
231
204
|
}
|
|
232
205
|
|
|
233
206
|
await saveSettingsConfig(conf)
|
|
234
|
-
|
|
207
|
+
|
|
235
208
|
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
|
236
209
|
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
|
237
210
|
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
|
238
|
-
config.modeAccount()
|
|
239
211
|
})
|
|
240
212
|
})
|
|
241
213
|
|
|
242
214
|
describe("update", () => {
|
|
243
|
-
it("should update settings config", async () => {
|
|
244
|
-
config.modeSelf()
|
|
215
|
+
it ("should update settings config", async () => {
|
|
245
216
|
await config.deleteConfig(Configs.SETTINGS)
|
|
246
217
|
const settingsConfig = await saveSettingsConfig()
|
|
247
218
|
settingsConfig.config.company = "acme"
|
|
248
219
|
settingsConfig.config.logoUrl = "http://example.com"
|
|
249
220
|
settingsConfig.config.platformUrl = "http://example.com"
|
|
250
221
|
|
|
251
|
-
await saveSettingsConfig(
|
|
252
|
-
settingsConfig.config,
|
|
253
|
-
settingsConfig._id,
|
|
254
|
-
settingsConfig._rev
|
|
255
|
-
)
|
|
222
|
+
await saveSettingsConfig(settingsConfig.config, settingsConfig._id, settingsConfig._rev)
|
|
256
223
|
|
|
257
224
|
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
|
258
225
|
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
|
259
226
|
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
|
260
|
-
config.modeAccount()
|
|
261
227
|
})
|
|
262
228
|
})
|
|
263
229
|
})
|
|
@@ -266,7 +232,12 @@ describe("configs", () => {
|
|
|
266
232
|
it("should return the correct checklist status based on the state of the budibase installation", async () => {
|
|
267
233
|
await config.saveSmtpConfig()
|
|
268
234
|
|
|
269
|
-
const res = await
|
|
235
|
+
const res = await request
|
|
236
|
+
.get(`/api/global/configs/checklist`)
|
|
237
|
+
.set(config.defaultHeaders())
|
|
238
|
+
.expect("Content-Type", /json/)
|
|
239
|
+
.expect(200)
|
|
240
|
+
|
|
270
241
|
const checklist = res.body
|
|
271
242
|
|
|
272
243
|
expect(checklist.apps.checked).toBeFalsy()
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
jest.mock("nodemailer")
|
|
2
|
-
|
|
2
|
+
const { config, mocks, structures, request } = require("../../../tests")
|
|
3
3
|
const sendMailMock = mocks.email.mock()
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
const { EmailTemplatePurpose } = require("../../../constants")
|
|
6
|
+
|
|
7
|
+
const TENANT_ID = structures.TENANT_ID
|
|
5
8
|
|
|
6
9
|
describe("/api/global/email", () => {
|
|
7
|
-
const config = new TestConfiguration()
|
|
8
|
-
const api = new API(config)
|
|
9
10
|
|
|
10
11
|
beforeAll(async () => {
|
|
11
12
|
await config.beforeAll()
|
|
@@ -19,9 +20,16 @@ describe("/api/global/email", () => {
|
|
|
19
20
|
// initially configure settings
|
|
20
21
|
await config.saveSmtpConfig()
|
|
21
22
|
await config.saveSettingsConfig()
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const res = await request
|
|
24
|
+
.post(`/api/global/email/send`)
|
|
25
|
+
.send({
|
|
26
|
+
email: "test@test.com",
|
|
27
|
+
purpose: EmailTemplatePurpose.INVITATION,
|
|
28
|
+
tenantId: TENANT_ID,
|
|
29
|
+
})
|
|
30
|
+
.set(config.defaultHeaders())
|
|
31
|
+
.expect("Content-Type", /json/)
|
|
32
|
+
.expect(200)
|
|
25
33
|
expect(res.body.message).toBeDefined()
|
|
26
34
|
expect(sendMailMock).toHaveBeenCalled()
|
|
27
35
|
const emailCall = sendMailMock.mock.calls[0][0]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const { config, request } = require("../../../tests")
|
|
2
|
+
const { EmailTemplatePurpose } = require("../../../constants")
|
|
3
3
|
const nodemailer = require("nodemailer")
|
|
4
4
|
const fetch = require("node-fetch")
|
|
5
5
|
|
|
@@ -7,8 +7,6 @@ const fetch = require("node-fetch")
|
|
|
7
7
|
jest.setTimeout(30000)
|
|
8
8
|
|
|
9
9
|
describe("/api/global/email", () => {
|
|
10
|
-
const config = new TestConfiguration()
|
|
11
|
-
const api = new API(config)
|
|
12
10
|
|
|
13
11
|
beforeAll(async () => {
|
|
14
12
|
await config.beforeAll()
|
|
@@ -18,24 +16,27 @@ describe("/api/global/email", () => {
|
|
|
18
16
|
await config.afterAll()
|
|
19
17
|
})
|
|
20
18
|
|
|
21
|
-
async function sendRealEmail(purpose
|
|
19
|
+
async function sendRealEmail(purpose) {
|
|
22
20
|
let response, text
|
|
23
21
|
try {
|
|
24
|
-
const timeout = () =>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
errno: "ETIME",
|
|
31
|
-
}),
|
|
32
|
-
20000
|
|
33
|
-
)
|
|
34
|
-
)
|
|
22
|
+
const timeout = () => new Promise((resolve, reject) =>
|
|
23
|
+
setTimeout(() => reject({
|
|
24
|
+
status: 301,
|
|
25
|
+
errno: "ETIME"
|
|
26
|
+
}), 20000)
|
|
27
|
+
)
|
|
35
28
|
await Promise.race([config.saveEtherealSmtpConfig(), timeout()])
|
|
36
29
|
await Promise.race([config.saveSettingsConfig(), timeout()])
|
|
37
|
-
|
|
38
|
-
const res = await
|
|
30
|
+
const user = await config.getUser("test@test.com")
|
|
31
|
+
const res = await request
|
|
32
|
+
.post(`/api/global/email/send`)
|
|
33
|
+
.send({
|
|
34
|
+
email: "test@test.com",
|
|
35
|
+
purpose,
|
|
36
|
+
userId: user._id,
|
|
37
|
+
})
|
|
38
|
+
.set(config.defaultHeaders())
|
|
39
|
+
.timeout(20000)
|
|
39
40
|
// ethereal hiccup, can't test right now
|
|
40
41
|
if (res.status >= 300) {
|
|
41
42
|
return
|
|
@@ -46,7 +47,7 @@ describe("/api/global/email", () => {
|
|
|
46
47
|
expect(testUrl).toBeDefined()
|
|
47
48
|
response = await fetch(testUrl)
|
|
48
49
|
text = await response.text()
|
|
49
|
-
} catch (err
|
|
50
|
+
} catch (err) {
|
|
50
51
|
// ethereal hiccup, can't test right now
|
|
51
52
|
if (parseInt(err.status) >= 300 || (err && err.errno === "ETIME")) {
|
|
52
53
|
return
|
|
@@ -80,4 +81,4 @@ describe("/api/global/email", () => {
|
|
|
80
81
|
it("should be able to send a password recovery email", async () => {
|
|
81
82
|
await sendRealEmail(EmailTemplatePurpose.PASSWORD_RECOVERY)
|
|
82
83
|
})
|
|
83
|
-
})
|
|
84
|
+
})
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
jest.mock("nodemailer")
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const { config, request } = require("../../../tests")
|
|
3
|
+
const { events } = require("@budibase/backend-core")
|
|
4
4
|
|
|
5
5
|
describe("/api/global/self", () => {
|
|
6
|
-
const config = new TestConfiguration()
|
|
7
|
-
const api = new API(config)
|
|
8
6
|
|
|
9
7
|
beforeAll(async () => {
|
|
10
8
|
await config.beforeAll()
|
|
@@ -18,13 +16,23 @@ describe("/api/global/self", () => {
|
|
|
18
16
|
jest.clearAllMocks()
|
|
19
17
|
})
|
|
20
18
|
|
|
19
|
+
const updateSelf = async (user) => {
|
|
20
|
+
const res = await request
|
|
21
|
+
.post(`/api/global/self`)
|
|
22
|
+
.send(user)
|
|
23
|
+
.set(config.defaultHeaders())
|
|
24
|
+
.expect("Content-Type", /json/)
|
|
25
|
+
.expect(200)
|
|
26
|
+
return res
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
describe("update", () => {
|
|
30
|
+
|
|
22
31
|
it("should update self", async () => {
|
|
23
32
|
const user = await config.createUser()
|
|
24
|
-
await config.createSession(user)
|
|
25
33
|
|
|
26
34
|
delete user.password
|
|
27
|
-
const res = await
|
|
35
|
+
const res = await updateSelf(user)
|
|
28
36
|
|
|
29
37
|
expect(res.body._id).toBe(user._id)
|
|
30
38
|
expect(events.user.updated).toBeCalledTimes(1)
|
|
@@ -34,10 +42,10 @@ describe("/api/global/self", () => {
|
|
|
34
42
|
|
|
35
43
|
it("should update password", async () => {
|
|
36
44
|
const user = await config.createUser()
|
|
37
|
-
|
|
45
|
+
const password = "newPassword"
|
|
46
|
+
user.password = password
|
|
38
47
|
|
|
39
|
-
|
|
40
|
-
const res = await api.self.updateSelf(user)
|
|
48
|
+
const res = await updateSelf(user)
|
|
41
49
|
|
|
42
50
|
delete user.password
|
|
43
51
|
expect(res.body._id).toBe(user._id)
|
|
@@ -47,4 +55,4 @@ describe("/api/global/self", () => {
|
|
|
47
55
|
expect(events.user.passwordUpdated).toBeCalledWith(user)
|
|
48
56
|
})
|
|
49
57
|
})
|
|
50
|
-
})
|
|
58
|
+
})
|