aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils/users.ts')
-rw-r--r--server/tests/utils/users.ts44
1 files changed, 37 insertions, 7 deletions
diff --git a/server/tests/utils/users.ts b/server/tests/utils/users.ts
index 6e4b5f2f5..1c3f6826e 100644
--- a/server/tests/utils/users.ts
+++ b/server/tests/utils/users.ts
@@ -1,11 +1,12 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2 2
3function createUser (url: string, accessToken: string, username: string, password: string, specialStatus = 204) { 3function createUser (url: string, accessToken: string, username: string, password: string, videoQuota = 1000000, specialStatus = 204) {
4 const path = '/api/v1/users' 4 const path = '/api/v1/users'
5 const body = { 5 const body = {
6 username, 6 username,
7 password, 7 password,
8 email: username + '@example.com' 8 email: username + '@example.com',
9 videoQuota
9 } 10 }
10 11
11 return request(url) 12 return request(url)
@@ -31,7 +32,7 @@ function registerUser (url: string, username: string, password: string, specialS
31 .expect(specialStatus) 32 .expect(specialStatus)
32} 33}
33 34
34function getUserInformation (url: string, accessToken: string) { 35function getMyUserInformation (url: string, accessToken: string) {
35 const path = '/api/v1/users/me' 36 const path = '/api/v1/users/me'
36 37
37 return request(url) 38 return request(url)
@@ -42,6 +43,17 @@ function getUserInformation (url: string, accessToken: string) {
42 .expect('Content-Type', /json/) 43 .expect('Content-Type', /json/)
43} 44}
44 45
46function getUserInformation (url: string, accessToken: string, userId: number) {
47 const path = '/api/v1/users/' + userId
48
49 return request(url)
50 .get(path)
51 .set('Accept', 'application/json')
52 .set('Authorization', 'Bearer ' + accessToken)
53 .expect(200)
54 .expect('Content-Type', /json/)
55}
56
45function getUserVideoRating (url: string, accessToken: string, videoId: number) { 57function getUserVideoRating (url: string, accessToken: string, videoId: number) {
46 const path = '/api/v1/users/me/videos/' + videoId + '/rating' 58 const path = '/api/v1/users/me/videos/' + videoId + '/rating'
47 59
@@ -86,12 +98,28 @@ function removeUser (url: string, userId: number, accessToken: string, expectedS
86 .expect(expectedStatus) 98 .expect(expectedStatus)
87} 99}
88 100
89function updateUser (url: string, userId: number, accessToken: string, newPassword: string, displayNSFW: boolean) { 101function updateMyUser (url: string, accessToken: string, newPassword: string, displayNSFW?: boolean, email?: string) {
90 const path = '/api/v1/users/' + userId 102 const path = '/api/v1/users/me'
91 103
92 const toSend = {} 104 const toSend = {}
93 if (newPassword !== undefined && newPassword !== null) toSend['password'] = newPassword 105 if (newPassword !== undefined && newPassword !== null) toSend['password'] = newPassword
94 if (displayNSFW !== undefined && displayNSFW !== null) toSend['displayNSFW'] = displayNSFW 106 if (displayNSFW !== undefined && displayNSFW !== null) toSend['displayNSFW'] = displayNSFW
107 if (email !== undefined && email !== null) toSend['email'] = email
108
109 return request(url)
110 .put(path)
111 .set('Accept', 'application/json')
112 .set('Authorization', 'Bearer ' + accessToken)
113 .send(toSend)
114 .expect(204)
115}
116
117function updateUser (url: string, userId: number, accessToken: string, email: string, videoQuota: number) {
118 const path = '/api/v1/users/' + userId
119
120 const toSend = {}
121 if (email !== undefined && email !== null) toSend['password'] = email
122 if (videoQuota !== undefined && videoQuota !== null) toSend['videoQuota'] = videoQuota
95 123
96 return request(url) 124 return request(url)
97 .put(path) 125 .put(path)
@@ -106,10 +134,12 @@ function updateUser (url: string, userId: number, accessToken: string, newPasswo
106export { 134export {
107 createUser, 135 createUser,
108 registerUser, 136 registerUser,
109 getUserInformation, 137 getMyUserInformation,
110 getUserVideoRating, 138 getUserVideoRating,
111 getUsersList, 139 getUsersList,
112 getUsersListPaginationAndSort, 140 getUsersListPaginationAndSort,
113 removeUser, 141 removeUser,
114 updateUser 142 updateUser,
143 updateMyUser,
144 getUserInformation
115} 145}