1 import * as request from 'supertest'
3 function createUser (url: string, accessToken: string, username: string, password: string, videoQuota = 1000000, specialStatus = 204) {
4 const path = '/api/v1/users'
8 email: username + '@example.com',
14 .set('Accept', 'application/json')
15 .set('Authorization', 'Bearer ' + accessToken)
17 .expect(specialStatus)
20 function registerUser (url: string, username: string, password: string, specialStatus = 204) {
21 const path = '/api/v1/users/register'
25 email: username + '@example.com'
30 .set('Accept', 'application/json')
32 .expect(specialStatus)
35 function getMyUserInformation (url: string, accessToken: string) {
36 const path = '/api/v1/users/me'
40 .set('Accept', 'application/json')
41 .set('Authorization', 'Bearer ' + accessToken)
43 .expect('Content-Type', /json/)
46 function getUserInformation (url: string, accessToken: string, userId: number) {
47 const path = '/api/v1/users/' + userId
51 .set('Accept', 'application/json')
52 .set('Authorization', 'Bearer ' + accessToken)
54 .expect('Content-Type', /json/)
57 function getUserVideoRating (url: string, accessToken: string, videoId: number) {
58 const path = '/api/v1/users/me/videos/' + videoId + '/rating'
62 .set('Accept', 'application/json')
63 .set('Authorization', 'Bearer ' + accessToken)
65 .expect('Content-Type', /json/)
68 function getUsersList (url: string) {
69 const path = '/api/v1/users'
73 .set('Accept', 'application/json')
75 .expect('Content-Type', /json/)
78 function getUsersListPaginationAndSort (url: string, start: number, count: number, sort: string) {
79 const path = '/api/v1/users'
86 .set('Accept', 'application/json')
88 .expect('Content-Type', /json/)
91 function removeUser (url: string, userId: number, accessToken: string, expectedStatus = 204) {
92 const path = '/api/v1/users'
95 .delete(path + '/' + userId)
96 .set('Accept', 'application/json')
97 .set('Authorization', 'Bearer ' + accessToken)
98 .expect(expectedStatus)
101 function updateMyUser (url: string, accessToken: string, newPassword: string, displayNSFW?: boolean, email?: string) {
102 const path = '/api/v1/users/me'
105 if (newPassword !== undefined && newPassword !== null) toSend['password'] = newPassword
106 if (displayNSFW !== undefined && displayNSFW !== null) toSend['displayNSFW'] = displayNSFW
107 if (email !== undefined && email !== null) toSend['email'] = email
111 .set('Accept', 'application/json')
112 .set('Authorization', 'Bearer ' + accessToken)
117 function updateUser (url: string, userId: number, accessToken: string, email: string, videoQuota: number) {
118 const path = '/api/v1/users/' + userId
121 if (email !== undefined && email !== null) toSend['password'] = email
122 if (videoQuota !== undefined && videoQuota !== null) toSend['videoQuota'] = videoQuota
126 .set('Accept', 'application/json')
127 .set('Authorization', 'Bearer ' + accessToken)
132 // ---------------------------------------------------------------------------
137 getMyUserInformation,
140 getUsersListPaginationAndSort,