aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/users/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/users/users.ts')
-rw-r--r--shared/extra-utils/users/users.ts50
1 files changed, 42 insertions, 8 deletions
diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.ts
index 2bd37b8be..1c39881d6 100644
--- a/shared/extra-utils/users/users.ts
+++ b/shared/extra-utils/users/users.ts
@@ -1,10 +1,11 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' 2import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests'
3 3
4import { UserRole } from '../../index' 4import { UserCreate, UserRole } from '../../index'
5import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type' 5import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type'
6import { ServerInfo, userLogin } from '..' 6import { ServerInfo, userLogin } from '..'
7import { UserAdminFlag } from '../../models/users/user-flag.model' 7import { UserAdminFlag } from '../../models/users/user-flag.model'
8import { UserRegister } from '../../models/users/user-register.model'
8 9
9type CreateUserArgs = { url: string, 10type CreateUserArgs = { url: string,
10 accessToken: string, 11 accessToken: string,
@@ -70,6 +71,31 @@ function registerUser (url: string, username: string, password: string, specialS
70 .expect(specialStatus) 71 .expect(specialStatus)
71} 72}
72 73
74function registerUserWithChannel (options: {
75 url: string,
76 user: { username: string, password: string, displayName?: string },
77 channel: { name: string, displayName: string }
78}) {
79 const path = '/api/v1/users/register'
80 const body: UserRegister = {
81 username: options.user.username,
82 password: options.user.password,
83 email: options.user.username + '@example.com',
84 channel: options.channel
85 }
86
87 if (options.user.displayName) {
88 Object.assign(body, { displayName: options.user.displayName })
89 }
90
91 return makePostBodyRequest({
92 url: options.url,
93 path,
94 fields: body,
95 statusCodeExpected: 204
96 })
97}
98
73function getMyUserInformation (url: string, accessToken: string, specialStatus = 200) { 99function getMyUserInformation (url: string, accessToken: string, specialStatus = 200) {
74 const path = '/api/v1/users/me' 100 const path = '/api/v1/users/me'
75 101
@@ -138,12 +164,16 @@ function getUsersList (url: string, accessToken: string) {
138function getUsersListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string, search?: string) { 164function getUsersListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string, search?: string) {
139 const path = '/api/v1/users' 165 const path = '/api/v1/users'
140 166
167 const query = {
168 start,
169 count,
170 sort,
171 search
172 }
173
141 return request(url) 174 return request(url)
142 .get(path) 175 .get(path)
143 .query({ start }) 176 .query(query)
144 .query({ count })
145 .query({ sort })
146 .query({ search })
147 .set('Accept', 'application/json') 177 .set('Accept', 'application/json')
148 .set('Authorization', 'Bearer ' + accessToken) 178 .set('Authorization', 'Bearer ' + accessToken)
149 .expect(200) 179 .expect(200)
@@ -293,13 +323,16 @@ function askSendVerifyEmail (url: string, email: string) {
293 }) 323 })
294} 324}
295 325
296function verifyEmail (url: string, userId: number, verificationString: string, statusCodeExpected = 204) { 326function verifyEmail (url: string, userId: number, verificationString: string, isPendingEmail = false, statusCodeExpected = 204) {
297 const path = '/api/v1/users/' + userId + '/verify-email' 327 const path = '/api/v1/users/' + userId + '/verify-email'
298 328
299 return makePostBodyRequest({ 329 return makePostBodyRequest({
300 url, 330 url,
301 path, 331 path,
302 fields: { verificationString }, 332 fields: {
333 verificationString,
334 isPendingEmail
335 },
303 statusCodeExpected 336 statusCodeExpected
304 }) 337 })
305} 338}
@@ -312,6 +345,7 @@ export {
312 getMyUserInformation, 345 getMyUserInformation,
313 getMyUserVideoRating, 346 getMyUserVideoRating,
314 deleteMe, 347 deleteMe,
348 registerUserWithChannel,
315 getMyUserVideoQuotaUsed, 349 getMyUserVideoQuotaUsed,
316 getUsersList, 350 getUsersList,
317 getUsersListPaginationAndSort, 351 getUsersListPaginationAndSort,