diff options
Diffstat (limited to 'server/tests/utils')
-rw-r--r-- | server/tests/utils/miscs/email.ts | 25 | ||||
-rw-r--r-- | server/tests/utils/users/users.ts | 26 |
2 files changed, 50 insertions, 1 deletions
diff --git a/server/tests/utils/miscs/email.ts b/server/tests/utils/miscs/email.ts new file mode 100644 index 000000000..21accd09d --- /dev/null +++ b/server/tests/utils/miscs/email.ts | |||
@@ -0,0 +1,25 @@ | |||
1 | import * as MailDev from 'maildev' | ||
2 | |||
3 | function mockSmtpServer (emailsCollection: object[]) { | ||
4 | const maildev = new MailDev({ | ||
5 | ip: '127.0.0.1', | ||
6 | smtp: 1025, | ||
7 | disableWeb: true, | ||
8 | silent: true | ||
9 | }) | ||
10 | maildev.on('new', email => emailsCollection.push(email)) | ||
11 | |||
12 | return new Promise((res, rej) => { | ||
13 | maildev.listen(err => { | ||
14 | if (err) return rej(err) | ||
15 | |||
16 | return res() | ||
17 | }) | ||
18 | }) | ||
19 | } | ||
20 | |||
21 | // --------------------------------------------------------------------------- | ||
22 | |||
23 | export { | ||
24 | mockSmtpServer | ||
25 | } | ||
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index 25351e2c7..9e33e6796 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { isAbsolute, join } from 'path' | 1 | import { isAbsolute, join } from 'path' |
2 | import * as request from 'supertest' | 2 | import * as request from 'supertest' |
3 | import { makePostUploadRequest, makePutBodyRequest } from '../' | 3 | import { makePostBodyRequest, makePostUploadRequest, makePutBodyRequest } from '../' |
4 | 4 | ||
5 | import { UserRole } from '../../../../shared/index' | 5 | import { UserRole } from '../../../../shared/index' |
6 | 6 | ||
@@ -196,6 +196,28 @@ function updateUser (options: { | |||
196 | }) | 196 | }) |
197 | } | 197 | } |
198 | 198 | ||
199 | function askResetPassword (url: string, email: string) { | ||
200 | const path = '/api/v1/users/ask-reset-password' | ||
201 | |||
202 | return makePostBodyRequest({ | ||
203 | url, | ||
204 | path, | ||
205 | fields: { email }, | ||
206 | statusCodeExpected: 204 | ||
207 | }) | ||
208 | } | ||
209 | |||
210 | function resetPassword (url: string, userId: number, verificationString: string, password: string, statusCodeExpected = 204) { | ||
211 | const path = '/api/v1/users/' + userId + '/reset-password' | ||
212 | |||
213 | return makePostBodyRequest({ | ||
214 | url, | ||
215 | path, | ||
216 | fields: { password, verificationString }, | ||
217 | statusCodeExpected | ||
218 | }) | ||
219 | } | ||
220 | |||
199 | // --------------------------------------------------------------------------- | 221 | // --------------------------------------------------------------------------- |
200 | 222 | ||
201 | export { | 223 | export { |
@@ -210,5 +232,7 @@ export { | |||
210 | updateUser, | 232 | updateUser, |
211 | updateMyUser, | 233 | updateMyUser, |
212 | getUserInformation, | 234 | getUserInformation, |
235 | askResetPassword, | ||
236 | resetPassword, | ||
213 | updateMyAvatar | 237 | updateMyAvatar |
214 | } | 238 | } |