1 import * as request from 'supertest'
3 import { UserRole } from '../../../shared'
11 role: UserRole = UserRole.USER,
14 const path = '/api/v1/users'
19 email: username + '@example.com',
25 .set('Accept', 'application/json')
26 .set('Authorization', 'Bearer ' + accessToken)
28 .expect(specialStatus)
31 function registerUser (url: string, username: string, password: string, specialStatus = 204) {
32 const path = '/api/v1/users/register'
36 email: username + '@example.com'
41 .set('Accept', 'application/json')
43 .expect(specialStatus)
46 function getMyUserInformation (url: string, accessToken: string) {
47 const path = '/api/v1/users/me'
51 .set('Accept', 'application/json')
52 .set('Authorization', 'Bearer ' + accessToken)
54 .expect('Content-Type', /json/)
57 function getUserInformation (url: string, accessToken: string, userId: number) {
58 const path = '/api/v1/users/' + userId
62 .set('Accept', 'application/json')
63 .set('Authorization', 'Bearer ' + accessToken)
65 .expect('Content-Type', /json/)
68 function getUserVideoRating (url: string, accessToken: string, videoId: number) {
69 const path = '/api/v1/users/me/videos/' + videoId + '/rating'
73 .set('Accept', 'application/json')
74 .set('Authorization', 'Bearer ' + accessToken)
76 .expect('Content-Type', /json/)
79 function getUsersList (url: string) {
80 const path = '/api/v1/users'
84 .set('Accept', 'application/json')
86 .expect('Content-Type', /json/)
89 function getUsersListPaginationAndSort (url: string, start: number, count: number, sort: string) {
90 const path = '/api/v1/users'
97 .set('Accept', 'application/json')
99 .expect('Content-Type', /json/)
102 function removeUser (url: string, userId: number, accessToken: string, expectedStatus = 204) {
103 const path = '/api/v1/users'
106 .delete(path + '/' + userId)
107 .set('Accept', 'application/json')
108 .set('Authorization', 'Bearer ' + accessToken)
109 .expect(expectedStatus)
112 function updateMyUser (url: string, accessToken: string, newPassword: string, displayNSFW?: boolean, email?: string) {
113 const path = '/api/v1/users/me'
116 if (newPassword !== undefined && newPassword !== null) toSend['password'] = newPassword
117 if (displayNSFW !== undefined && displayNSFW !== null) toSend['displayNSFW'] = displayNSFW
118 if (email !== undefined && email !== null) toSend['email'] = email
122 .set('Accept', 'application/json')
123 .set('Authorization', 'Bearer ' + accessToken)
128 function updateUser (url: string, userId: number, accessToken: string, email: string, videoQuota: number, role: UserRole) {
129 const path = '/api/v1/users/' + userId
132 if (email !== undefined && email !== null) toSend['email'] = email
133 if (videoQuota !== undefined && videoQuota !== null) toSend['videoQuota'] = videoQuota
134 if (role !== undefined && role !== null) toSend['role'] = role
138 .set('Accept', 'application/json')
139 .set('Authorization', 'Bearer ' + accessToken)
144 // ---------------------------------------------------------------------------
149 getMyUserInformation,
152 getUsersListPaginationAndSort,