aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils')
-rw-r--r--server/tests/utils/miscs/miscs.ts7
-rw-r--r--server/tests/utils/users/users.ts78
2 files changed, 53 insertions, 32 deletions
diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts
index 424b0db98..2147a07ff 100644
--- a/server/tests/utils/miscs/miscs.ts
+++ b/server/tests/utils/miscs/miscs.ts
@@ -3,6 +3,10 @@ import { readFile, readdir } from 'fs'
3 3
4let webtorrent = new WebTorrent() 4let webtorrent = new WebTorrent()
5 5
6function immutableAssign <T, U> (target: T, source: U) {
7 return Object.assign<{}, T, U>({}, target, source)
8}
9
6function readFilePromise (path: string) { 10function readFilePromise (path: string) {
7 return new Promise<Buffer>((res, rej) => { 11 return new Promise<Buffer>((res, rej) => {
8 readFile(path, (err, data) => { 12 readFile(path, (err, data) => {
@@ -48,5 +52,6 @@ export {
48 readdirPromise, 52 readdirPromise,
49 dateIsValid, 53 dateIsValid,
50 wait, 54 wait,
51 webtorrentAdd 55 webtorrentAdd,
56 immutableAssign
52} 57}
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts
index bd8d7ab04..e0cca3f51 100644
--- a/server/tests/utils/users/users.ts
+++ b/server/tests/utils/users/users.ts
@@ -1,4 +1,5 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { makePutBodyRequest } from '../'
2 3
3import { UserRole } from '../../../../shared/index' 4import { UserRole } from '../../../../shared/index'
4 5
@@ -43,14 +44,14 @@ function registerUser (url: string, username: string, password: string, specialS
43 .expect(specialStatus) 44 .expect(specialStatus)
44} 45}
45 46
46function getMyUserInformation (url: string, accessToken: string) { 47function getMyUserInformation (url: string, accessToken: string, specialStatus = 200) {
47 const path = '/api/v1/users/me' 48 const path = '/api/v1/users/me'
48 49
49 return request(url) 50 return request(url)
50 .get(path) 51 .get(path)
51 .set('Accept', 'application/json') 52 .set('Accept', 'application/json')
52 .set('Authorization', 'Bearer ' + accessToken) 53 .set('Authorization', 'Bearer ' + accessToken)
53 .expect(200) 54 .expect(specialStatus)
54 .expect('Content-Type', /json/) 55 .expect('Content-Type', /json/)
55} 56}
56 57
@@ -65,14 +66,14 @@ function getUserInformation (url: string, accessToken: string, userId: number) {
65 .expect('Content-Type', /json/) 66 .expect('Content-Type', /json/)
66} 67}
67 68
68function getUserVideoRating (url: string, accessToken: string, videoId: number) { 69function getMyUserVideoRating (url: string, accessToken: string, videoId: number | string, specialStatus = 200) {
69 const path = '/api/v1/users/me/videos/' + videoId + '/rating' 70 const path = '/api/v1/users/me/videos/' + videoId + '/rating'
70 71
71 return request(url) 72 return request(url)
72 .get(path) 73 .get(path)
73 .set('Accept', 'application/json') 74 .set('Accept', 'application/json')
74 .set('Authorization', 'Bearer ' + accessToken) 75 .set('Authorization', 'Bearer ' + accessToken)
75 .expect(200) 76 .expect(specialStatus)
76 .expect('Content-Type', /json/) 77 .expect('Content-Type', /json/)
77} 78}
78 79
@@ -101,7 +102,7 @@ function getUsersListPaginationAndSort (url: string, accessToken: string, start:
101 .expect('Content-Type', /json/) 102 .expect('Content-Type', /json/)
102} 103}
103 104
104function removeUser (url: string, userId: number, accessToken: string, expectedStatus = 204) { 105function removeUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204) {
105 const path = '/api/v1/users' 106 const path = '/api/v1/users'
106 107
107 return request(url) 108 return request(url)
@@ -111,38 +112,53 @@ function removeUser (url: string, userId: number, accessToken: string, expectedS
111 .expect(expectedStatus) 112 .expect(expectedStatus)
112} 113}
113 114
114function updateMyUser (url: string, accessToken: string, newPassword: string, displayNSFW?: boolean, 115function updateMyUser (options: {
115 email?: string, autoPlayVideo?: boolean) { 116 url: string
117 accessToken: string,
118 newPassword?: string,
119 displayNSFW?: boolean,
120 email?: string,
121 autoPlayVideo?: boolean
122}) {
116 const path = '/api/v1/users/me' 123 const path = '/api/v1/users/me'
117 124
118 const toSend = {} 125 const toSend = {}
119 if (newPassword !== undefined && newPassword !== null) toSend['password'] = newPassword 126 if (options.newPassword !== undefined && options.newPassword !== null) toSend['password'] = options.newPassword
120 if (displayNSFW !== undefined && displayNSFW !== null) toSend['displayNSFW'] = displayNSFW 127 if (options.displayNSFW !== undefined && options.displayNSFW !== null) toSend['displayNSFW'] = options.displayNSFW
121 if (autoPlayVideo !== undefined && autoPlayVideo !== null) toSend['autoPlayVideo'] = autoPlayVideo 128 if (options.autoPlayVideo !== undefined && options.autoPlayVideo !== null) toSend['autoPlayVideo'] = options.autoPlayVideo
122 if (email !== undefined && email !== null) toSend['email'] = email 129 if (options.email !== undefined && options.email !== null) toSend['email'] = options.email
123 130
124 return request(url) 131 return makePutBodyRequest({
125 .put(path) 132 url: options.url,
126 .set('Accept', 'application/json') 133 path,
127 .set('Authorization', 'Bearer ' + accessToken) 134 token: options.accessToken,
128 .send(toSend) 135 fields: toSend,
129 .expect(204) 136 statusCodeExpected: 204
137 })
130} 138}
131 139
132function updateUser (url: string, userId: number, accessToken: string, email: string, videoQuota: number, role: UserRole) { 140function updateUser (options: {
133 const path = '/api/v1/users/' + userId 141 url: string
142 userId: number,
143 accessToken: string,
144 email?: string,
145 videoQuota?: number,
146 role?: UserRole
147}) {
148 const path = '/api/v1/users/' + options.userId
134 149
135 const toSend = {} 150 const toSend = {}
136 if (email !== undefined && email !== null) toSend['email'] = email 151 if (options.email !== undefined && options.email !== null) toSend['email'] = options.email
137 if (videoQuota !== undefined && videoQuota !== null) toSend['videoQuota'] = videoQuota 152 if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota
138 if (role !== undefined && role !== null) toSend['role'] = role 153 if (options.role !== undefined && options.role !== null) toSend['role'] = options.role
139 154
140 return request(url) 155 return makePutBodyRequest({
141 .put(path) 156 url: options.url,
142 .set('Accept', 'application/json') 157 path,
143 .set('Authorization', 'Bearer ' + accessToken) 158 token: options.accessToken,
144 .send(toSend) 159 fields: toSend,
145 .expect(204) 160 statusCodeExpected: 204
161 })
146} 162}
147 163
148// --------------------------------------------------------------------------- 164// ---------------------------------------------------------------------------
@@ -151,7 +167,7 @@ export {
151 createUser, 167 createUser,
152 registerUser, 168 registerUser,
153 getMyUserInformation, 169 getMyUserInformation,
154 getUserVideoRating, 170 getMyUserVideoRating,
155 getUsersList, 171 getUsersList,
156 getUsersListPaginationAndSort, 172 getUsersListPaginationAndSort,
157 removeUser, 173 removeUser,