import * as request from 'supertest'
-import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests'
-
-import { UserCreate, UserRole } from '../../index'
-import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type'
-import { ServerInfo, userLogin } from '..'
+import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests'
import { UserAdminFlag } from '../../models/users/user-flag.model'
import { UserRegister } from '../../models/users/user-register.model'
+import { UserRole } from '../../models/users/user-role'
+import { ServerInfo } from '../server/servers'
+import { userLogin } from './login'
+import { UserUpdateMe } from '../../models/users'
+import { omit } from 'lodash'
-type CreateUserArgs = { url: string,
- accessToken: string,
- username: string,
- password: string,
- videoQuota?: number,
- videoQuotaDaily?: number,
- role?: UserRole,
- adminFlags?: UserAdminFlag,
+type CreateUserArgs = {
+ url: string
+ accessToken: string
+ username: string
+ password: string
+ videoQuota?: number
+ videoQuotaDaily?: number
+ role?: UserRole
+ adminFlags?: UserAdminFlag
specialStatus?: number
}
function createUser (parameters: CreateUserArgs) {
}
function registerUserWithChannel (options: {
- url: string,
- user: { username: string, password: string, displayName?: string },
+ url: string
+ user: { username: string, password: string, displayName?: string }
channel: { name: string, displayName: string }
}) {
const path = '/api/v1/users/register'
.expect(expectedStatus)
}
-function updateMyUser (options: {
- url: string
- accessToken: string
- currentPassword?: string
- newPassword?: string
- nsfwPolicy?: NSFWPolicyType
- email?: string
- autoPlayVideo?: boolean
- displayName?: string
- description?: string
- videosHistoryEnabled?: boolean
-}) {
+function updateMyUser (options: { url: string, accessToken: string } & UserUpdateMe) {
const path = '/api/v1/users/me'
- const toSend = {}
- if (options.currentPassword !== undefined && options.currentPassword !== null) toSend['currentPassword'] = options.currentPassword
- if (options.newPassword !== undefined && options.newPassword !== null) toSend['password'] = options.newPassword
- if (options.nsfwPolicy !== undefined && options.nsfwPolicy !== null) toSend['nsfwPolicy'] = options.nsfwPolicy
- if (options.autoPlayVideo !== undefined && options.autoPlayVideo !== null) toSend['autoPlayVideo'] = options.autoPlayVideo
- if (options.email !== undefined && options.email !== null) toSend['email'] = options.email
- if (options.description !== undefined && options.description !== null) toSend['description'] = options.description
- if (options.displayName !== undefined && options.displayName !== null) toSend['displayName'] = options.displayName
- if (options.videosHistoryEnabled !== undefined && options.videosHistoryEnabled !== null) {
- toSend['videosHistoryEnabled'] = options.videosHistoryEnabled
- }
+ const toSend: UserUpdateMe = omit(options, 'url', 'accessToken')
return makePutBodyRequest({
url: options.url,
}
function updateMyAvatar (options: {
- url: string,
- accessToken: string,
+ url: string
+ accessToken: string
fixture: string
}) {
const path = '/api/v1/users/me/avatar/pick'
function updateUser (options: {
url: string
- userId: number,
- accessToken: string,
- email?: string,
- emailVerified?: boolean,
- videoQuota?: number,
- videoQuotaDaily?: number,
- password?: string,
- adminFlags?: UserAdminFlag,
+ userId: number
+ accessToken: string
+ email?: string
+ emailVerified?: boolean
+ videoQuota?: number
+ videoQuotaDaily?: number
+ password?: string
+ adminFlags?: UserAdminFlag
role?: UserRole
}) {
const path = '/api/v1/users/' + options.userId