diff options
Diffstat (limited to 'shared/extra-utils/users/users.ts')
-rw-r--r-- | shared/extra-utils/users/users.ts | 50 |
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 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' | 2 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' |
3 | 3 | ||
4 | import { UserRole } from '../../index' | 4 | import { UserCreate, UserRole } from '../../index' |
5 | import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type' | 5 | import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type' |
6 | import { ServerInfo, userLogin } from '..' | 6 | import { ServerInfo, userLogin } from '..' |
7 | import { UserAdminFlag } from '../../models/users/user-flag.model' | 7 | import { UserAdminFlag } from '../../models/users/user-flag.model' |
8 | import { UserRegister } from '../../models/users/user-register.model' | ||
8 | 9 | ||
9 | type CreateUserArgs = { url: string, | 10 | type 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 | ||
74 | function 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 | |||
73 | function getMyUserInformation (url: string, accessToken: string, specialStatus = 200) { | 99 | function 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) { | |||
138 | function getUsersListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string, search?: string) { | 164 | function 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 | ||
296 | function verifyEmail (url: string, userId: number, verificationString: string, statusCodeExpected = 204) { | 326 | function 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, |