aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/utils
diff options
context:
space:
mode:
Diffstat (limited to 'shared/utils')
-rw-r--r--shared/utils/users/users.ts33
-rw-r--r--shared/utils/videos/video-blacklist.ts51
2 files changed, 43 insertions, 41 deletions
diff --git a/shared/utils/users/users.ts b/shared/utils/users/users.ts
index e3c14a4a3..2bd37b8be 100644
--- a/shared/utils/users/users.ts
+++ b/shared/utils/users/users.ts
@@ -4,22 +4,37 @@ import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '..
4import { UserRole } from '../../index' 4import { 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'
7 8
8function createUser ( 9type CreateUserArgs = { url: string,
9 url: string,
10 accessToken: string, 10 accessToken: string,
11 username: string, 11 username: string,
12 password: string, 12 password: string,
13 videoQuota = 1000000, 13 videoQuota?: number,
14 videoQuotaDaily = -1, 14 videoQuotaDaily?: number,
15 role: UserRole = UserRole.USER, 15 role?: UserRole,
16 specialStatus = 200 16 adminFlags?: UserAdminFlag,
17) { 17 specialStatus?: number
18}
19function createUser (parameters: CreateUserArgs) {
20 const {
21 url,
22 accessToken,
23 username,
24 adminFlags,
25 password = 'password',
26 videoQuota = 1000000,
27 videoQuotaDaily = -1,
28 role = UserRole.USER,
29 specialStatus = 200
30 } = parameters
31
18 const path = '/api/v1/users' 32 const path = '/api/v1/users'
19 const body = { 33 const body = {
20 username, 34 username,
21 password, 35 password,
22 role, 36 role,
37 adminFlags,
23 email: username + '@example.com', 38 email: username + '@example.com',
24 videoQuota, 39 videoQuota,
25 videoQuotaDaily 40 videoQuotaDaily
@@ -35,7 +50,7 @@ function createUser (
35 50
36async function generateUserAccessToken (server: ServerInfo, username: string) { 51async function generateUserAccessToken (server: ServerInfo, username: string) {
37 const password = 'my super password' 52 const password = 'my super password'
38 await createUser(server.url, server.accessToken, username, password) 53 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
39 54
40 return userLogin(server, { username, password }) 55 return userLogin(server, { username, password })
41} 56}
@@ -222,6 +237,7 @@ function updateUser (options: {
222 videoQuota?: number, 237 videoQuota?: number,
223 videoQuotaDaily?: number, 238 videoQuotaDaily?: number,
224 password?: string, 239 password?: string,
240 adminFlags?: UserAdminFlag,
225 role?: UserRole 241 role?: UserRole
226}) { 242}) {
227 const path = '/api/v1/users/' + options.userId 243 const path = '/api/v1/users/' + options.userId
@@ -233,6 +249,7 @@ function updateUser (options: {
233 if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota 249 if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota
234 if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily 250 if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily
235 if (options.role !== undefined && options.role !== null) toSend['role'] = options.role 251 if (options.role !== undefined && options.role !== null) toSend['role'] = options.role
252 if (options.adminFlags !== undefined && options.adminFlags !== null) toSend['adminFlags'] = options.adminFlags
236 253
237 return makePutBodyRequest({ 254 return makePutBodyRequest({
238 url: options.url, 255 url: options.url,
diff --git a/shared/utils/videos/video-blacklist.ts b/shared/utils/videos/video-blacklist.ts
index 82d5b7e31..e25a292fc 100644
--- a/shared/utils/videos/video-blacklist.ts
+++ b/shared/utils/videos/video-blacklist.ts
@@ -1,4 +1,6 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { VideoBlacklistType } from '../../models/videos'
3import { makeGetRequest } from '..'
2 4
3function addVideoToBlacklist ( 5function addVideoToBlacklist (
4 url: string, 6 url: string,
@@ -39,40 +41,25 @@ function removeVideoFromBlacklist (url: string, token: string, videoId: number |
39 .expect(specialStatus) 41 .expect(specialStatus)
40} 42}
41 43
42function getBlacklistedVideosList (url: string, token: string, specialStatus = 200) { 44function getBlacklistedVideosList (parameters: {
45 url: string,
46 token: string,
47 sort?: string,
48 type?: VideoBlacklistType,
49 specialStatus?: number
50}) {
51 let { url, token, sort, type, specialStatus = 200 } = parameters
43 const path = '/api/v1/videos/blacklist/' 52 const path = '/api/v1/videos/blacklist/'
44 53
45 return request(url) 54 const query = { sort, type }
46 .get(path)
47 .query({ sort: 'createdAt' })
48 .set('Accept', 'application/json')
49 .set('Authorization', 'Bearer ' + token)
50 .expect(specialStatus)
51 .expect('Content-Type', /json/)
52}
53
54function getBlacklistedVideosListWithTypeFilter (url: string, token: string, type: number, specialStatus = 200) {
55 const path = '/api/v1/videos/blacklist/'
56 55
57 return request(url) 56 return makeGetRequest({
58 .get(path) 57 url,
59 .query({ sort: 'createdAt', type }) 58 path,
60 .set('Accept', 'application/json') 59 query,
61 .set('Authorization', 'Bearer ' + token) 60 token,
62 .expect(specialStatus) 61 statusCodeExpected: specialStatus
63 .expect('Content-Type', /json/) 62 })
64}
65
66function getSortedBlacklistedVideosList (url: string, token: string, sort: string, specialStatus = 200) {
67 const path = '/api/v1/videos/blacklist/'
68
69 return request(url)
70 .get(path)
71 .query({ sort: sort })
72 .set('Accept', 'application/json')
73 .set('Authorization', 'Bearer ' + token)
74 .expect(specialStatus)
75 .expect('Content-Type', /json/)
76} 63}
77 64
78// --------------------------------------------------------------------------- 65// ---------------------------------------------------------------------------
@@ -81,7 +68,5 @@ export {
81 addVideoToBlacklist, 68 addVideoToBlacklist,
82 removeVideoFromBlacklist, 69 removeVideoFromBlacklist,
83 getBlacklistedVideosList, 70 getBlacklistedVideosList,
84 getBlacklistedVideosListWithTypeFilter,
85 getSortedBlacklistedVideosList,
86 updateVideoBlacklist 71 updateVideoBlacklist
87} 72}