1 import * as request from 'supertest'
3 function createUser (url: string, accessToken: string, username: string, password: string, specialStatus = 204) {
4 const path = '/api/v1/users'
8 email: username + '@example.com'
13 .set('Accept', 'application/json')
14 .set('Authorization', 'Bearer ' + accessToken)
16 .expect(specialStatus)
19 function registerUser (url: string, username: string, password: string, specialStatus = 204) {
20 const path = '/api/v1/users/register'
24 email: username + '@example.com'
29 .set('Accept', 'application/json')
31 .expect(specialStatus)
34 function getUserInformation (url: string, accessToken: string) {
35 const path = '/api/v1/users/me'
39 .set('Accept', 'application/json')
40 .set('Authorization', 'Bearer ' + accessToken)
42 .expect('Content-Type', /json/)
45 function getUserVideoRating (url: string, accessToken: string, videoId: number) {
46 const path = '/api/v1/users/me/videos/' + videoId + '/rating'
50 .set('Accept', 'application/json')
51 .set('Authorization', 'Bearer ' + accessToken)
53 .expect('Content-Type', /json/)
56 function getUsersList (url: string) {
57 const path = '/api/v1/users'
61 .set('Accept', 'application/json')
63 .expect('Content-Type', /json/)
66 function getUsersListPaginationAndSort (url: string, start: number, count: number, sort: string) {
67 const path = '/api/v1/users'
74 .set('Accept', 'application/json')
76 .expect('Content-Type', /json/)
79 function removeUser (url: string, userId: number, accessToken: string, expectedStatus = 204) {
80 const path = '/api/v1/users'
83 .delete(path + '/' + userId)
84 .set('Accept', 'application/json')
85 .set('Authorization', 'Bearer ' + accessToken)
86 .expect(expectedStatus)
89 function updateUser (url: string, userId: number, accessToken: string, newPassword: string, displayNSFW: boolean) {
90 const path = '/api/v1/users/' + userId
93 if (newPassword !== undefined && newPassword !== null) toSend['password'] = newPassword
94 if (displayNSFW !== undefined && displayNSFW !== null) toSend['displayNSFW'] = displayNSFW
98 .set('Accept', 'application/json')
99 .set('Authorization', 'Bearer ' + accessToken)
104 // ---------------------------------------------------------------------------
112 getUsersListPaginationAndSort,