diff options
author | Chocobozzz <me@florianbigard.com> | 2021-05-27 16:12:41 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-05-27 16:12:41 +0200 |
commit | 8f608a4cb22ab232cfab20665050764b38bac9c7 (patch) | |
tree | 6a6785aae79bf5939ad7b7a50a1bd8031268d2b4 /shared/extra-utils/users | |
parent | 030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2 (diff) | |
parent | c215e627b575d2c4085ccb222f4ca8d0237b7552 (diff) | |
download | PeerTube-8f608a4cb22ab232cfab20665050764b38bac9c7.tar.gz PeerTube-8f608a4cb22ab232cfab20665050764b38bac9c7.tar.zst PeerTube-8f608a4cb22ab232cfab20665050764b38bac9c7.zip |
Merge branch 'develop' into shorter-URLs-channels-accounts
Diffstat (limited to 'shared/extra-utils/users')
-rw-r--r-- | shared/extra-utils/users/users.ts | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.ts index 6040dd9c0..0f15962ad 100644 --- a/shared/extra-utils/users/users.ts +++ b/shared/extra-utils/users/users.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { omit } from 'lodash' | 1 | import { omit } from 'lodash' |
2 | import * as request from 'supertest' | 2 | import * as request from 'supertest' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | import { UserUpdateMe } from '../../models/users' | 4 | import { UserUpdateMe } from '../../models/users' |
4 | import { UserAdminFlag } from '../../models/users/user-flag.model' | 5 | import { UserAdminFlag } from '../../models/users/user-flag.model' |
5 | import { UserRegister } from '../../models/users/user-register.model' | 6 | import { UserRegister } from '../../models/users/user-register.model' |
@@ -7,9 +8,8 @@ import { UserRole } from '../../models/users/user-role' | |||
7 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateImageRequest } from '../requests/requests' | 8 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateImageRequest } from '../requests/requests' |
8 | import { ServerInfo } from '../server/servers' | 9 | import { ServerInfo } from '../server/servers' |
9 | import { userLogin } from './login' | 10 | import { userLogin } from './login' |
10 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
11 | 11 | ||
12 | type CreateUserArgs = { | 12 | function createUser (parameters: { |
13 | url: string | 13 | url: string |
14 | accessToken: string | 14 | accessToken: string |
15 | username: string | 15 | username: string |
@@ -19,8 +19,7 @@ type CreateUserArgs = { | |||
19 | role?: UserRole | 19 | role?: UserRole |
20 | adminFlags?: UserAdminFlag | 20 | adminFlags?: UserAdminFlag |
21 | specialStatus?: number | 21 | specialStatus?: number |
22 | } | 22 | }) { |
23 | function createUser (parameters: CreateUserArgs) { | ||
24 | const { | 23 | const { |
25 | url, | 24 | url, |
26 | accessToken, | 25 | accessToken, |
@@ -52,6 +51,21 @@ function createUser (parameters: CreateUserArgs) { | |||
52 | .expect(specialStatus) | 51 | .expect(specialStatus) |
53 | } | 52 | } |
54 | 53 | ||
54 | async function generateUser (server: ServerInfo, username: string) { | ||
55 | const password = 'my super password' | ||
56 | const resCreate = await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) | ||
57 | |||
58 | const token = await userLogin(server, { username, password }) | ||
59 | |||
60 | const resMe = await getMyUserInformation(server.url, token) | ||
61 | |||
62 | return { | ||
63 | token, | ||
64 | userId: resCreate.body.user.id, | ||
65 | userChannelId: resMe.body.videoChannels[0].id | ||
66 | } | ||
67 | } | ||
68 | |||
55 | async function generateUserAccessToken (server: ServerInfo, username: string) { | 69 | async function generateUserAccessToken (server: ServerInfo, username: string) { |
56 | const password = 'my super password' | 70 | const password = 'my super password' |
57 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) | 71 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
@@ -393,6 +407,7 @@ export { | |||
393 | resetPassword, | 407 | resetPassword, |
394 | renewUserScopedTokens, | 408 | renewUserScopedTokens, |
395 | updateMyAvatar, | 409 | updateMyAvatar, |
410 | generateUser, | ||
396 | askSendVerifyEmail, | 411 | askSendVerifyEmail, |
397 | generateUserAccessToken, | 412 | generateUserAccessToken, |
398 | verifyEmail, | 413 | verifyEmail, |