diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-09-06 16:35:40 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-09-06 17:28:20 +0200 |
commit | 77a5501f6413aff2f2a626b929dfda486fa9a3e6 (patch) | |
tree | 9f286d1b5a3bede13ea746530c8210c49a064b39 /server/tests/api/check-params/users.ts | |
parent | 5c98d3bf078852043cbdd582c01e3dc4f4b5b79f (diff) | |
download | PeerTube-77a5501f6413aff2f2a626b929dfda486fa9a3e6.tar.gz PeerTube-77a5501f6413aff2f2a626b929dfda486fa9a3e6.tar.zst PeerTube-77a5501f6413aff2f2a626b929dfda486fa9a3e6.zip |
Fix tests and user quota
Diffstat (limited to 'server/tests/api/check-params/users.ts')
-rw-r--r-- | server/tests/api/check-params/users.ts | 159 |
1 files changed, 135 insertions, 24 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 643a82afd..ef78c8262 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts | |||
@@ -43,7 +43,8 @@ describe('Test users API validators', function () { | |||
43 | 43 | ||
44 | const username = 'user1' | 44 | const username = 'user1' |
45 | const password = 'my super password' | 45 | const password = 'my super password' |
46 | await createUser(server.url, server.accessToken, username, password) | 46 | const videoQuota = 42000000 |
47 | await createUser(server.url, server.accessToken, username, password, videoQuota) | ||
47 | 48 | ||
48 | const videoAttributes = {} | 49 | const videoAttributes = {} |
49 | await uploadVideo(server.url, server.accessToken, videoAttributes) | 50 | await uploadVideo(server.url, server.accessToken, videoAttributes) |
@@ -90,7 +91,8 @@ describe('Test users API validators', function () { | |||
90 | const fields = { | 91 | const fields = { |
91 | username: 'ji', | 92 | username: 'ji', |
92 | email: 'test@example.com', | 93 | email: 'test@example.com', |
93 | password: 'my_super_password' | 94 | password: 'my_super_password', |
95 | videoQuota: 42000000 | ||
94 | } | 96 | } |
95 | 97 | ||
96 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 98 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
@@ -100,7 +102,8 @@ describe('Test users API validators', function () { | |||
100 | const fields = { | 102 | const fields = { |
101 | username: 'my_super_username_which_is_very_long', | 103 | username: 'my_super_username_which_is_very_long', |
102 | email: 'test@example.com', | 104 | email: 'test@example.com', |
103 | password: 'my_super_password' | 105 | password: 'my_super_password', |
106 | videoQuota: 42000000 | ||
104 | } | 107 | } |
105 | 108 | ||
106 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 109 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
@@ -110,7 +113,8 @@ describe('Test users API validators', function () { | |||
110 | const fields = { | 113 | const fields = { |
111 | username: 'my username', | 114 | username: 'my username', |
112 | email: 'test@example.com', | 115 | email: 'test@example.com', |
113 | password: 'my_super_password' | 116 | password: 'my_super_password', |
117 | videoQuota: 42000000 | ||
114 | } | 118 | } |
115 | 119 | ||
116 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 120 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
@@ -119,7 +123,8 @@ describe('Test users API validators', function () { | |||
119 | it('Should fail with a missing email', async function () { | 123 | it('Should fail with a missing email', async function () { |
120 | const fields = { | 124 | const fields = { |
121 | username: 'ji', | 125 | username: 'ji', |
122 | password: 'my_super_password' | 126 | password: 'my_super_password', |
127 | videoQuota: 42000000 | ||
123 | } | 128 | } |
124 | 129 | ||
125 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 130 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
@@ -129,7 +134,8 @@ describe('Test users API validators', function () { | |||
129 | const fields = { | 134 | const fields = { |
130 | username: 'my_super_username_which_is_very_long', | 135 | username: 'my_super_username_which_is_very_long', |
131 | email: 'test_example.com', | 136 | email: 'test_example.com', |
132 | password: 'my_super_password' | 137 | password: 'my_super_password', |
138 | videoQuota: 42000000 | ||
133 | } | 139 | } |
134 | 140 | ||
135 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 141 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
@@ -139,7 +145,8 @@ describe('Test users API validators', function () { | |||
139 | const fields = { | 145 | const fields = { |
140 | username: 'my_username', | 146 | username: 'my_username', |
141 | email: 'test@example.com', | 147 | email: 'test@example.com', |
142 | password: 'bla' | 148 | password: 'bla', |
149 | videoQuota: 42000000 | ||
143 | } | 150 | } |
144 | 151 | ||
145 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 152 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
@@ -151,7 +158,8 @@ describe('Test users API validators', function () { | |||
151 | email: 'test@example.com', | 158 | email: 'test@example.com', |
152 | password: 'my super long password which is very very very very very very very very very very very very very very' + | 159 | password: 'my super long password which is very very very very very very very very very very very very very very' + |
153 | 'very very very very very very very very very very very very very very very veryv very very very very' + | 160 | 'very very very very very very very very very very very very very very very veryv very very very very' + |
154 | 'very very very very very very very very very very very very very very very very very very very very long' | 161 | 'very very very very very very very very very very very very very very very very very very very very long', |
162 | videoQuota: 42000000 | ||
155 | } | 163 | } |
156 | 164 | ||
157 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 165 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
@@ -161,7 +169,8 @@ describe('Test users API validators', function () { | |||
161 | const fields = { | 169 | const fields = { |
162 | username: 'my_username', | 170 | username: 'my_username', |
163 | email: 'test@example.com', | 171 | email: 'test@example.com', |
164 | password: 'my super password' | 172 | password: 'my super password', |
173 | videoQuota: 42000000 | ||
165 | } | 174 | } |
166 | 175 | ||
167 | await makePostBodyRequest({ url: server.url, path, token: 'super token', fields, statusCodeExpected: 401 }) | 176 | await makePostBodyRequest({ url: server.url, path, token: 'super token', fields, statusCodeExpected: 401 }) |
@@ -171,7 +180,8 @@ describe('Test users API validators', function () { | |||
171 | const fields = { | 180 | const fields = { |
172 | username: 'user1', | 181 | username: 'user1', |
173 | email: 'test@example.com', | 182 | email: 'test@example.com', |
174 | password: 'my super password' | 183 | password: 'my super password', |
184 | videoQuota: 42000000 | ||
175 | } | 185 | } |
176 | 186 | ||
177 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | 187 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) |
@@ -181,17 +191,40 @@ describe('Test users API validators', function () { | |||
181 | const fields = { | 191 | const fields = { |
182 | username: 'my_username', | 192 | username: 'my_username', |
183 | email: 'user1@example.com', | 193 | email: 'user1@example.com', |
184 | password: 'my super password' | 194 | password: 'my super password', |
195 | videoQuota: 42000000 | ||
185 | } | 196 | } |
186 | 197 | ||
187 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | 198 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) |
188 | }) | 199 | }) |
189 | 200 | ||
201 | it('Should fail without a videoQuota', async function () { | ||
202 | const fields = { | ||
203 | username: 'my_username', | ||
204 | email: 'user1@example.com', | ||
205 | password: 'my super password' | ||
206 | } | ||
207 | |||
208 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
209 | }) | ||
210 | |||
211 | it('Should fail with an invalid videoQuota', async function () { | ||
212 | const fields = { | ||
213 | username: 'my_username', | ||
214 | email: 'user1@example.com', | ||
215 | password: 'my super password', | ||
216 | videoQuota: -5 | ||
217 | } | ||
218 | |||
219 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
220 | }) | ||
221 | |||
190 | it('Should succeed with the correct params', async function () { | 222 | it('Should succeed with the correct params', async function () { |
191 | const fields = { | 223 | const fields = { |
192 | username: 'user2', | 224 | username: 'user2', |
193 | email: 'test@example.com', | 225 | email: 'test@example.com', |
194 | password: 'my super password' | 226 | password: 'my super password', |
227 | videoQuota: -1 | ||
195 | } | 228 | } |
196 | 229 | ||
197 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | 230 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) |
@@ -208,18 +241,20 @@ describe('Test users API validators', function () { | |||
208 | const fields = { | 241 | const fields = { |
209 | username: 'user3', | 242 | username: 'user3', |
210 | email: 'test@example.com', | 243 | email: 'test@example.com', |
211 | password: 'my super password' | 244 | password: 'my super password', |
245 | videoQuota: 42000000 | ||
212 | } | 246 | } |
213 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | 247 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) |
214 | }) | 248 | }) |
215 | }) | 249 | }) |
216 | 250 | ||
217 | describe('When updating a user', function () { | 251 | describe('When updating my account', function () { |
218 | before(async function () { | 252 | it('Should fail with an invalid email attribute', async function () { |
219 | const res = await getUsersList(server.url) | 253 | const fields = { |
254 | email: 'blabla' | ||
255 | } | ||
220 | 256 | ||
221 | userId = res.body.data[1].id | 257 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields }) |
222 | rootId = res.body.data[2].id | ||
223 | }) | 258 | }) |
224 | 259 | ||
225 | it('Should fail with a too small password', async function () { | 260 | it('Should fail with a too small password', async function () { |
@@ -227,7 +262,7 @@ describe('Test users API validators', function () { | |||
227 | password: 'bla' | 262 | password: 'bla' |
228 | } | 263 | } |
229 | 264 | ||
230 | await makePutBodyRequest({ url: server.url, path: path + userId, token: userAccessToken, fields }) | 265 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) |
231 | }) | 266 | }) |
232 | 267 | ||
233 | it('Should fail with a too long password', async function () { | 268 | it('Should fail with a too long password', async function () { |
@@ -237,7 +272,7 @@ describe('Test users API validators', function () { | |||
237 | 'very very very very very very very very very very very very very very very very very very very very long' | 272 | 'very very very very very very very very very very very very very very very very very very very very long' |
238 | } | 273 | } |
239 | 274 | ||
240 | await makePutBodyRequest({ url: server.url, path: path + userId, token: userAccessToken, fields }) | 275 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) |
241 | }) | 276 | }) |
242 | 277 | ||
243 | it('Should fail with an invalid display NSFW attribute', async function () { | 278 | it('Should fail with an invalid display NSFW attribute', async function () { |
@@ -245,7 +280,7 @@ describe('Test users API validators', function () { | |||
245 | displayNSFW: -1 | 280 | displayNSFW: -1 |
246 | } | 281 | } |
247 | 282 | ||
248 | await makePutBodyRequest({ url: server.url, path: path + userId, token: userAccessToken, fields }) | 283 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) |
249 | }) | 284 | }) |
250 | 285 | ||
251 | it('Should fail with an non authenticated user', async function () { | 286 | it('Should fail with an non authenticated user', async function () { |
@@ -253,16 +288,60 @@ describe('Test users API validators', function () { | |||
253 | password: 'my super password' | 288 | password: 'my super password' |
254 | } | 289 | } |
255 | 290 | ||
256 | await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 }) | 291 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 }) |
257 | }) | 292 | }) |
258 | 293 | ||
259 | it('Should succeed with the correct params', async function () { | 294 | it('Should succeed with the correct params', async function () { |
260 | const fields = { | 295 | const fields = { |
261 | password: 'my super password', | 296 | password: 'my super password', |
262 | displayNSFW: true | 297 | displayNSFW: true, |
298 | email: 'super_email@example.com' | ||
263 | } | 299 | } |
264 | 300 | ||
265 | await makePutBodyRequest({ url: server.url, path: path + userId, token: userAccessToken, fields, statusCodeExpected: 204 }) | 301 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) |
302 | }) | ||
303 | }) | ||
304 | |||
305 | describe('When updating a user', function () { | ||
306 | |||
307 | before(async function () { | ||
308 | const res = await getUsersList(server.url) | ||
309 | |||
310 | userId = res.body.data[1].id | ||
311 | rootId = res.body.data[2].id | ||
312 | }) | ||
313 | |||
314 | it('Should fail with an invalid email attribute', async function () { | ||
315 | const fields = { | ||
316 | email: 'blabla' | ||
317 | } | ||
318 | |||
319 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | ||
320 | }) | ||
321 | |||
322 | it('Should fail with an invalid videoQuota attribute', async function () { | ||
323 | const fields = { | ||
324 | videoQuota: -90 | ||
325 | } | ||
326 | |||
327 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | ||
328 | }) | ||
329 | |||
330 | it('Should fail with an non authenticated user', async function () { | ||
331 | const fields = { | ||
332 | videoQuota: 42 | ||
333 | } | ||
334 | |||
335 | await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 }) | ||
336 | }) | ||
337 | |||
338 | it('Should succeed with the correct params', async function () { | ||
339 | const fields = { | ||
340 | email: 'email@example.com', | ||
341 | videoQuota: 42 | ||
342 | } | ||
343 | |||
344 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 }) | ||
266 | }) | 345 | }) |
267 | }) | 346 | }) |
268 | 347 | ||
@@ -491,6 +570,38 @@ describe('Test users API validators', function () { | |||
491 | }) | 570 | }) |
492 | }) | 571 | }) |
493 | 572 | ||
573 | describe('When having a video quota', function () { | ||
574 | it('Should fail with a user having too many video', async function () { | ||
575 | const fields = { | ||
576 | videoQuota: 42 | ||
577 | } | ||
578 | |||
579 | await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields, statusCodeExpected: 204 }) | ||
580 | |||
581 | const videoAttributes = {} | ||
582 | await uploadVideo(server.url, server.accessToken, videoAttributes, 403) | ||
583 | }) | ||
584 | |||
585 | it('Should fail with a registered user having too many video', async function () { | ||
586 | this.timeout(10000) | ||
587 | |||
588 | server.user = { | ||
589 | username: 'user3', | ||
590 | email: 'test3@example.com', | ||
591 | password: 'my super password' | ||
592 | } | ||
593 | userAccessToken = await loginAndGetAccessToken(server) | ||
594 | |||
595 | const videoAttributes = { fixture: 'video_short2.webm' } | ||
596 | await uploadVideo(server.url, userAccessToken, videoAttributes) | ||
597 | await uploadVideo(server.url, userAccessToken, videoAttributes) | ||
598 | await uploadVideo(server.url, userAccessToken, videoAttributes) | ||
599 | await uploadVideo(server.url, userAccessToken, videoAttributes) | ||
600 | await uploadVideo(server.url, userAccessToken, videoAttributes) | ||
601 | await uploadVideo(server.url, userAccessToken, videoAttributes, 403) | ||
602 | }) | ||
603 | }) | ||
604 | |||
494 | after(async function () { | 605 | after(async function () { |
495 | killallServers([ server, serverWithRegistrationDisabled ]) | 606 | killallServers([ server, serverWithRegistrationDisabled ]) |
496 | 607 | ||