From a1bb73f9b591686b2ddfeb3291f305dae9f7fc6c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 7 May 2021 11:53:46 +0200 Subject: Refactor a little bit live tests --- shared/extra-utils/users/users.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'shared/extra-utils/users') 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 @@ import { omit } from 'lodash' import * as request from 'supertest' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' import { UserUpdateMe } from '../../models/users' import { UserAdminFlag } from '../../models/users/user-flag.model' import { UserRegister } from '../../models/users/user-register.model' @@ -7,9 +8,8 @@ import { UserRole } from '../../models/users/user-role' import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateImageRequest } from '../requests/requests' import { ServerInfo } from '../server/servers' import { userLogin } from './login' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' -type CreateUserArgs = { +function createUser (parameters: { url: string accessToken: string username: string @@ -19,8 +19,7 @@ type CreateUserArgs = { role?: UserRole adminFlags?: UserAdminFlag specialStatus?: number -} -function createUser (parameters: CreateUserArgs) { +}) { const { url, accessToken, @@ -52,6 +51,21 @@ function createUser (parameters: CreateUserArgs) { .expect(specialStatus) } +async function generateUser (server: ServerInfo, username: string) { + const password = 'my super password' + const resCreate = await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) + + const token = await userLogin(server, { username, password }) + + const resMe = await getMyUserInformation(server.url, token) + + return { + token, + userId: resCreate.body.user.id, + userChannelId: resMe.body.videoChannels[0].id + } +} + async function generateUserAccessToken (server: ServerInfo, username: string) { const password = 'my super password' await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) @@ -393,6 +407,7 @@ export { resetPassword, renewUserScopedTokens, updateMyAvatar, + generateUser, askSendVerifyEmail, generateUserAccessToken, verifyEmail, -- cgit v1.2.3