1 import * as request from 'supertest'
2 import { makePutBodyRequest } from '../'
4 import { UserRole } from '../../../../shared/index'
12 role: UserRole = UserRole.USER,
15 const path = '/api/v1/users'
20 email: username + '@example.com',
26 .set('Accept', 'application/json')
27 .set('Authorization', 'Bearer ' + accessToken)
29 .expect(specialStatus)
32 function registerUser (url: string, username: string, password: string, specialStatus = 204) {
33 const path = '/api/v1/users/register'
37 email: username + '@example.com'
42 .set('Accept', 'application/json')
44 .expect(specialStatus)
47 function getMyUserInformation (url: string, accessToken: string, specialStatus = 200) {
48 const path = '/api/v1/users/me'
52 .set('Accept', 'application/json')
53 .set('Authorization', 'Bearer ' + accessToken)
54 .expect(specialStatus)
55 .expect('Content-Type', /json/)
58 function getUserInformation (url: string, accessToken: string, userId: number) {
59 const path = '/api/v1/users/' + userId
63 .set('Accept', 'application/json')
64 .set('Authorization', 'Bearer ' + accessToken)
66 .expect('Content-Type', /json/)
69 function getMyUserVideoRating (url: string, accessToken: string, videoId: number | string, specialStatus = 200) {
70 const path = '/api/v1/users/me/videos/' + videoId + '/rating'
74 .set('Accept', 'application/json')
75 .set('Authorization', 'Bearer ' + accessToken)
76 .expect(specialStatus)
77 .expect('Content-Type', /json/)
80 function getUsersList (url: string, accessToken: string) {
81 const path = '/api/v1/users'
85 .set('Accept', 'application/json')
86 .set('Authorization', 'Bearer ' + accessToken)
88 .expect('Content-Type', /json/)
91 function getUsersListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string) {
92 const path = '/api/v1/users'
99 .set('Accept', 'application/json')
100 .set('Authorization', 'Bearer ' + accessToken)
102 .expect('Content-Type', /json/)
105 function removeUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204) {
106 const path = '/api/v1/users'
109 .delete(path + '/' + userId)
110 .set('Accept', 'application/json')
111 .set('Authorization', 'Bearer ' + accessToken)
112 .expect(expectedStatus)
115 function updateMyUser (options: {
118 newPassword?: string,
119 displayNSFW?: boolean,
121 autoPlayVideo?: boolean
123 const path = '/api/v1/users/me'
126 if (options.newPassword !== undefined && options.newPassword !== null) toSend['password'] = options.newPassword
127 if (options.displayNSFW !== undefined && options.displayNSFW !== null) toSend['displayNSFW'] = options.displayNSFW
128 if (options.autoPlayVideo !== undefined && options.autoPlayVideo !== null) toSend['autoPlayVideo'] = options.autoPlayVideo
129 if (options.email !== undefined && options.email !== null) toSend['email'] = options.email
131 return makePutBodyRequest({
134 token: options.accessToken,
136 statusCodeExpected: 204
140 function updateUser (options: {
148 const path = '/api/v1/users/' + options.userId
151 if (options.email !== undefined && options.email !== null) toSend['email'] = options.email
152 if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota
153 if (options.role !== undefined && options.role !== null) toSend['role'] = options.role
155 return makePutBodyRequest({
158 token: options.accessToken,
160 statusCodeExpected: 204
164 // ---------------------------------------------------------------------------
169 getMyUserInformation,
170 getMyUserVideoRating,
172 getUsersListPaginationAndSort,