aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-playlists.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-03-05 10:58:44 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-03-18 11:17:59 +0100
commitdf0b219d36bf6852cdf2a7ad09ed4a41c6bccefa (patch)
treec4984e854f5dc18e5c27afd73b843bd52c143034 /server/tests/api/check-params/video-playlists.ts
parent07b1a18aa678d260009a93e36606c5c5f585723d (diff)
downloadPeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.tar.gz
PeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.tar.zst
PeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.zip
Add playlist rest tests
Diffstat (limited to 'server/tests/api/check-params/video-playlists.ts')
-rw-r--r--server/tests/api/check-params/video-playlists.ts818
1 files changed, 277 insertions, 541 deletions
diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts
index 68fe362e9..803e7afb9 100644
--- a/server/tests/api/check-params/video-playlists.ts
+++ b/server/tests/api/check-params/video-playlists.ts
@@ -2,20 +2,24 @@
2 2
3import 'mocha' 3import 'mocha'
4import { 4import {
5 createUser, 5 addVideoInPlaylist,
6 createVideoPlaylist, 6 createVideoPlaylist,
7 deleteVideoPlaylist, 7 deleteVideoPlaylist,
8 flushTests, 8 flushTests,
9 generateUserAccessToken,
10 getAccountPlaylistsListWithToken,
9 getVideoPlaylist, 11 getVideoPlaylist,
10 immutableAssign, 12 immutableAssign,
11 killallServers, 13 killallServers,
12 makeGetRequest, 14 makeGetRequest,
15 removeVideoFromPlaylist,
16 reorderVideosPlaylist,
13 runServer, 17 runServer,
14 ServerInfo, 18 ServerInfo,
15 setAccessTokensToServers, 19 setAccessTokensToServers,
16 updateVideoPlaylist, 20 updateVideoPlaylist,
17 userLogin, 21 updateVideoPlaylistElement,
18 addVideoInPlaylist, uploadVideo, updateVideoPlaylistElement, removeVideoFromPlaylist, reorderVideosPlaylist 22 uploadVideoAndGetId
19} from '../../../../shared/utils' 23} from '../../../../shared/utils'
20import { 24import {
21 checkBadCountPagination, 25 checkBadCountPagination,
@@ -23,11 +27,13 @@ import {
23 checkBadStartPagination 27 checkBadStartPagination
24} from '../../../../shared/utils/requests/check-api-params' 28} from '../../../../shared/utils/requests/check-api-params'
25import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' 29import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
30import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
26 31
27describe('Test video playlists API validator', function () { 32describe('Test video playlists API validator', function () {
28 let server: ServerInfo 33 let server: ServerInfo
29 let userAccessToken = '' 34 let userAccessToken: string
30 let playlistUUID: string 35 let playlistUUID: string
36 let watchLaterPlaylistId: number
31 let videoId: number 37 let videoId: number
32 let videoId2: number 38 let videoId2: number
33 39
@@ -42,19 +48,13 @@ describe('Test video playlists API validator', function () {
42 48
43 await setAccessTokensToServers([ server ]) 49 await setAccessTokensToServers([ server ])
44 50
45 const username = 'user1' 51 userAccessToken = await generateUserAccessToken(server, 'user1')
46 const password = 'my super password' 52 videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id
47 await createUser(server.url, server.accessToken, username, password) 53 videoId2 = (await uploadVideoAndGetId({ server, videoName: 'video 2' })).id
48 userAccessToken = await userLogin(server, { username, password })
49 54
50 { 55 {
51 const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) 56 const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root',0, 5, VideoPlaylistType.WATCH_LATER)
52 videoId = res.body.video.id 57 watchLaterPlaylistId = res.body.data[0].id
53 }
54
55 {
56 const res = await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
57 videoId2 = res.body.video.id
58 } 58 }
59 59
60 { 60 {
@@ -93,6 +93,12 @@ describe('Test video playlists API validator', function () {
93 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken) 93 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
94 }) 94 })
95 95
96 it('Should fail with a bad playlist type', async function () {
97 await makeGetRequest({ url: server.url, path: globalPath, query: { playlistType: 3 } })
98 await makeGetRequest({ url: server.url, path: accountPath, query: { playlistType: 3 } })
99 await makeGetRequest({ url: server.url, path: videoChannelPath, query: { playlistType: 3 } })
100 })
101
96 it('Should fail with a bad account parameter', async function () { 102 it('Should fail with a bad account parameter', async function () {
97 const accountPath = '/api/v1/accounts/root2/video-playlists' 103 const accountPath = '/api/v1/accounts/root2/video-playlists'
98 104
@@ -158,410 +164,250 @@ describe('Test video playlists API validator', function () {
158 }) 164 })
159 165
160 describe('When creating/updating a video playlist', function () { 166 describe('When creating/updating a video playlist', function () {
167 const getBase = (playlistAttrs: any = {}, wrapper: any = {}) => {
168 return Object.assign({
169 expectedStatus: 400,
170 url: server.url,
171 token: server.accessToken,
172 playlistAttrs: Object.assign({
173 displayName: 'display name',
174 privacy: VideoPlaylistPrivacy.UNLISTED,
175 thumbnailfile: 'thumbnail.jpg'
176 }, playlistAttrs)
177 }, wrapper)
178 }
179 const getUpdate = (params: any, playlistId: number | string) => {
180 return immutableAssign(params, { playlistId: playlistId })
181 }
161 182
162 it('Should fail with an unauthenticated user', async function () { 183 it('Should fail with an unauthenticated user', async function () {
163 const baseParams = { 184 const params = getBase({}, { token: null, expectedStatus: 401 })
164 url: server.url,
165 token: null,
166 playlistAttrs: {
167 displayName: 'super playlist',
168 privacy: VideoPlaylistPrivacy.PUBLIC
169 },
170 expectedStatus: 401
171 }
172 185
173 await createVideoPlaylist(baseParams) 186 await createVideoPlaylist(params)
174 await updateVideoPlaylist(immutableAssign(baseParams, { playlistId: playlistUUID })) 187 await updateVideoPlaylist(getUpdate(params, playlistUUID))
175 }) 188 })
176 189
177 it('Should fail without displayName', async function () { 190 it('Should fail without displayName', async function () {
178 const baseParams = { 191 const params = getBase({ displayName: undefined })
179 url: server.url,
180 token: server.accessToken,
181 playlistAttrs: {
182 privacy: VideoPlaylistPrivacy.PUBLIC
183 } as any,
184 expectedStatus: 400
185 }
186 192
187 await createVideoPlaylist(baseParams) 193 await createVideoPlaylist(params)
188 await updateVideoPlaylist(immutableAssign(baseParams, { playlistId: playlistUUID })) 194 await updateVideoPlaylist(getUpdate(params, playlistUUID))
189 }) 195 })
190 196
191 it('Should fail with an incorrect display name', async function () { 197 it('Should fail with an incorrect display name', async function () {
192 const baseParams = { 198 const params = getBase({ displayName: 's'.repeat(300) })
193 url: server.url,
194 token: server.accessToken,
195 playlistAttrs: {
196 displayName: 's'.repeat(300),
197 privacy: VideoPlaylistPrivacy.PUBLIC
198 },
199 expectedStatus: 400
200 }
201 199
202 await createVideoPlaylist(baseParams) 200 await createVideoPlaylist(params)
203 await updateVideoPlaylist(immutableAssign(baseParams, { playlistId: playlistUUID })) 201 await updateVideoPlaylist(getUpdate(params, playlistUUID))
204 }) 202 })
205 203
206 it('Should fail with an incorrect description', async function () { 204 it('Should fail with an incorrect description', async function () {
207 const baseParams = { 205 const params = getBase({ description: 't' })
208 url: server.url,
209 token: server.accessToken,
210 playlistAttrs: {
211 displayName: 'display name',
212 privacy: VideoPlaylistPrivacy.PUBLIC,
213 description: 't'
214 },
215 expectedStatus: 400
216 }
217 206
218 await createVideoPlaylist(baseParams) 207 await createVideoPlaylist(params)
219 await updateVideoPlaylist(immutableAssign(baseParams, { playlistId: playlistUUID })) 208 await updateVideoPlaylist(getUpdate(params, playlistUUID))
220 }) 209 })
221 210
222 it('Should fail with an incorrect privacy', async function () { 211 it('Should fail with an incorrect privacy', async function () {
223 const baseParams = { 212 const params = getBase({ privacy: 45 })
224 url: server.url,
225 token: server.accessToken,
226 playlistAttrs: {
227 displayName: 'display name',
228 privacy: 45
229 } as any,
230 expectedStatus: 400
231 }
232 213
233 await createVideoPlaylist(baseParams) 214 await createVideoPlaylist(params)
234 await updateVideoPlaylist(immutableAssign(baseParams, { playlistId: playlistUUID })) 215 await updateVideoPlaylist(getUpdate(params, playlistUUID))
235 }) 216 })
236 217
237 it('Should fail with an unknown video channel id', async function () { 218 it('Should fail with an unknown video channel id', async function () {
238 const baseParams = { 219 const params = getBase({ videoChannelId: 42 }, { expectedStatus: 404 })
239 url: server.url,
240 token: server.accessToken,
241 playlistAttrs: {
242 displayName: 'display name',
243 privacy: VideoPlaylistPrivacy.PUBLIC,
244 videoChannelId: 42
245 },
246 expectedStatus: 404
247 }
248 220
249 await createVideoPlaylist(baseParams) 221 await createVideoPlaylist(params)
250 await updateVideoPlaylist(immutableAssign(baseParams, { playlistId: playlistUUID })) 222 await updateVideoPlaylist(getUpdate(params, playlistUUID))
251 }) 223 })
252 224
253 it('Should fail with an incorrect thumbnail file', async function () { 225 it('Should fail with an incorrect thumbnail file', async function () {
254 const baseParams = { 226 const params = getBase({ thumbnailfile: 'avatar.png' })
255 url: server.url,
256 token: server.accessToken,
257 playlistAttrs: {
258 displayName: 'display name',
259 privacy: VideoPlaylistPrivacy.PUBLIC,
260 thumbnailfile: 'avatar.png'
261 },
262 expectedStatus: 400
263 }
264 227
265 await createVideoPlaylist(baseParams) 228 await createVideoPlaylist(params)
266 await updateVideoPlaylist(immutableAssign(baseParams, { playlistId: playlistUUID })) 229 await updateVideoPlaylist(getUpdate(params, playlistUUID))
267 }) 230 })
268 231
269 it('Should fail with an unknown playlist to update', async function () { 232 it('Should fail with an unknown playlist to update', async function () {
270 await updateVideoPlaylist({ 233 await updateVideoPlaylist(getUpdate(
271 url: server.url, 234 getBase({}, { expectedStatus: 404 }),
272 token: server.accessToken, 235 42
273 playlistId: 42, 236 ))
274 playlistAttrs: {
275 displayName: 'display name',
276 privacy: VideoPlaylistPrivacy.PUBLIC
277 },
278 expectedStatus: 404
279 })
280 }) 237 })
281 238
282 it('Should fail to update a playlist of another user', async function () { 239 it('Should fail to update a playlist of another user', async function () {
283 await updateVideoPlaylist({ 240 await updateVideoPlaylist(getUpdate(
284 url: server.url, 241 getBase({}, { token: userAccessToken, expectedStatus: 403 }),
285 token: userAccessToken, 242 playlistUUID
286 playlistId: playlistUUID, 243 ))
287 playlistAttrs: {
288 displayName: 'display name',
289 privacy: VideoPlaylistPrivacy.PUBLIC
290 },
291 expectedStatus: 403
292 })
293 }) 244 })
294 245
295 it('Should fail to update to private a public/unlisted playlist', async function () { 246 it('Should fail to update to private a public/unlisted playlist', async function () {
296 const res = await createVideoPlaylist({ 247 const params = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC }, { expectedStatus: 200 })
297 url: server.url, 248
298 token: server.accessToken, 249 const res = await createVideoPlaylist(params)
299 playlistAttrs: {
300 displayName: 'super playlist',
301 privacy: VideoPlaylistPrivacy.PUBLIC
302 }
303 })
304 const playlist = res.body.videoPlaylist 250 const playlist = res.body.videoPlaylist
305 251
306 await updateVideoPlaylist({ 252 const paramsUpdate = getBase({ privacy: VideoPlaylistPrivacy.PRIVATE }, { expectedStatus: 409 })
307 url: server.url, 253
308 token: server.accessToken, 254 await updateVideoPlaylist(getUpdate(paramsUpdate, playlist.id))
309 playlistId: playlist.id, 255 })
310 playlistAttrs: { 256
311 displayName: 'display name', 257 it('Should fail to update the watch later playlist', async function () {
312 privacy: VideoPlaylistPrivacy.PRIVATE 258 await updateVideoPlaylist(getUpdate(
313 }, 259 getBase({}, { expectedStatus: 409 }),
314 expectedStatus: 409 260 watchLaterPlaylistId
315 }) 261 ))
316 }) 262 })
317 263
318 it('Should succeed with the correct params', async function () { 264 it('Should succeed with the correct params', async function () {
319 const baseParams = { 265 {
320 url: server.url, 266 const params = getBase({}, { expectedStatus: 200 })
321 token: server.accessToken, 267 await createVideoPlaylist(params)
322 playlistAttrs: {
323 displayName: 'display name',
324 privacy: VideoPlaylistPrivacy.UNLISTED,
325 thumbnailfile: 'thumbnail.jpg'
326 }
327 } 268 }
328 269
329 await createVideoPlaylist(baseParams) 270 {
330 await updateVideoPlaylist(immutableAssign(baseParams, { playlistId: playlistUUID })) 271 const params = getBase({}, { expectedStatus: 204 })
272 await updateVideoPlaylist(getUpdate(params, playlistUUID))
273 }
331 }) 274 })
332 }) 275 })
333 276
334 describe('When adding an element in a playlist', function () { 277 describe('When adding an element in a playlist', function () {
335 it('Should fail with an unauthenticated user', async function () { 278 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => {
336 await addVideoInPlaylist({ 279 return Object.assign({
280 expectedStatus: 400,
337 url: server.url, 281 url: server.url,
338 token: null, 282 token: server.accessToken,
339 elementAttrs: {
340 videoId: videoId
341 },
342 playlistId: playlistUUID, 283 playlistId: playlistUUID,
343 expectedStatus: 401 284 elementAttrs: Object.assign({
344 }) 285 videoId: videoId,
286 startTimestamp: 2,
287 stopTimestamp: 3
288 }, elementAttrs)
289 }, wrapper)
290 }
291
292 it('Should fail with an unauthenticated user', async function () {
293 const params = getBase({}, { token: null, expectedStatus: 401 })
294 await addVideoInPlaylist(params)
345 }) 295 })
346 296
347 it('Should fail with the playlist of another user', async function () { 297 it('Should fail with the playlist of another user', async function () {
348 await addVideoInPlaylist({ 298 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 })
349 url: server.url, 299 await addVideoInPlaylist(params)
350 token: userAccessToken,
351 elementAttrs: {
352 videoId: videoId
353 },
354 playlistId: playlistUUID,
355 expectedStatus: 403
356 })
357 }) 300 })
358 301
359 it('Should fail with an unknown or incorrect playlist id', async function () { 302 it('Should fail with an unknown or incorrect playlist id', async function () {
360 await addVideoInPlaylist({ 303 {
361 url: server.url, 304 const params = getBase({}, { playlistId: 'toto' })
362 token: server.accessToken, 305 await addVideoInPlaylist(params)
363 elementAttrs: { 306 }
364 videoId: videoId
365 },
366 playlistId: 'toto',
367 expectedStatus: 400
368 })
369 307
370 await addVideoInPlaylist({ 308 {
371 url: server.url, 309 const params = getBase({}, { playlistId: 42, expectedStatus: 404 })
372 token: server.accessToken, 310 await addVideoInPlaylist(params)
373 elementAttrs: { 311 }
374 videoId: videoId
375 },
376 playlistId: 42,
377 expectedStatus: 404
378 })
379 }) 312 })
380 313
381 it('Should fail with an unknown or incorrect video id', async function () { 314 it('Should fail with an unknown or incorrect video id', async function () {
382 await addVideoInPlaylist({ 315 const params = getBase({ videoId: 42 }, { expectedStatus: 404 })
383 url: server.url, 316 await addVideoInPlaylist(params)
384 token: server.accessToken,
385 elementAttrs: {
386 videoId: 'toto' as any
387 },
388 playlistId: playlistUUID,
389 expectedStatus: 400
390 })
391
392 await addVideoInPlaylist({
393 url: server.url,
394 token: server.accessToken,
395 elementAttrs: {
396 videoId: 42
397 },
398 playlistId: playlistUUID,
399 expectedStatus: 404
400 })
401 }) 317 })
402 318
403 it('Should fail with a bad start/stop timestamp', async function () { 319 it('Should fail with a bad start/stop timestamp', async function () {
404 await addVideoInPlaylist({ 320 {
405 url: server.url, 321 const params = getBase({ startTimestamp: -42 })
406 token: server.accessToken, 322 await addVideoInPlaylist(params)
407 elementAttrs: { 323 }
408 videoId: videoId,
409 startTimestamp: -42
410 },
411 playlistId: playlistUUID,
412 expectedStatus: 400
413 })
414 324
415 await addVideoInPlaylist({ 325 {
416 url: server.url, 326 const params = getBase({ stopTimestamp: 'toto' as any })
417 token: server.accessToken, 327 await addVideoInPlaylist(params)
418 elementAttrs: { 328 }
419 videoId: videoId,
420 stopTimestamp: 'toto' as any
421 },
422 playlistId: playlistUUID,
423 expectedStatus: 400
424 })
425 }) 329 })
426 330
427 it('Succeed with the correct params', async function () { 331 it('Succeed with the correct params', async function () {
428 await addVideoInPlaylist({ 332 const params = getBase({}, { expectedStatus: 200 })
429 url: server.url, 333 await addVideoInPlaylist(params)
430 token: server.accessToken,
431 elementAttrs: {
432 videoId: videoId,
433 stopTimestamp: 3
434 },
435 playlistId: playlistUUID,
436 expectedStatus: 200
437 })
438 }) 334 })
439 335
440 it('Should fail if the video was already added in the playlist', async function () { 336 it('Should fail if the video was already added in the playlist', async function () {
441 await addVideoInPlaylist({ 337 const params = getBase({}, { expectedStatus: 409 })
442 url: server.url, 338 await addVideoInPlaylist(params)
443 token: server.accessToken,
444 elementAttrs: {
445 videoId: videoId,
446 stopTimestamp: 3
447 },
448 playlistId: playlistUUID,
449 expectedStatus: 409
450 })
451 }) 339 })
452 }) 340 })
453 341
454 describe('When updating an element in a playlist', function () { 342 describe('When updating an element in a playlist', function () {
455 it('Should fail with an unauthenticated user', async function () { 343 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => {
456 await updateVideoPlaylistElement({ 344 return Object.assign({
457 url: server.url, 345 url: server.url,
458 token: null, 346 token: server.accessToken,
459 elementAttrs: { }, 347 elementAttrs: Object.assign({
348 startTimestamp: 1,
349 stopTimestamp: 2
350 }, elementAttrs),
460 videoId: videoId, 351 videoId: videoId,
461 playlistId: playlistUUID, 352 playlistId: playlistUUID,
462 expectedStatus: 401 353 expectedStatus: 400
463 }) 354 }, wrapper)
355 }
356
357 it('Should fail with an unauthenticated user', async function () {
358 const params = getBase({}, { token: null, expectedStatus: 401 })
359 await updateVideoPlaylistElement(params)
464 }) 360 })
465 361
466 it('Should fail with the playlist of another user', async function () { 362 it('Should fail with the playlist of another user', async function () {
467 await updateVideoPlaylistElement({ 363 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 })
468 url: server.url, 364 await updateVideoPlaylistElement(params)
469 token: userAccessToken,
470 elementAttrs: { },
471 videoId: videoId,
472 playlistId: playlistUUID,
473 expectedStatus: 403
474 })
475 }) 365 })
476 366
477 it('Should fail with an unknown or incorrect playlist id', async function () { 367 it('Should fail with an unknown or incorrect playlist id', async function () {
478 await updateVideoPlaylistElement({ 368 {
479 url: server.url, 369 const params = getBase({}, { playlistId: 'toto' })
480 token: server.accessToken, 370 await updateVideoPlaylistElement(params)
481 elementAttrs: { }, 371 }
482 videoId: videoId,
483 playlistId: 'toto',
484 expectedStatus: 400
485 })
486 372
487 await updateVideoPlaylistElement({ 373 {
488 url: server.url, 374 const params = getBase({}, { playlistId: 42, expectedStatus: 404 })
489 token: server.accessToken, 375 await updateVideoPlaylistElement(params)
490 elementAttrs: { }, 376 }
491 videoId: videoId,
492 playlistId: 42,
493 expectedStatus: 404
494 })
495 }) 377 })
496 378
497 it('Should fail with an unknown or incorrect video id', async function () { 379 it('Should fail with an unknown or incorrect video id', async function () {
498 await updateVideoPlaylistElement({ 380 {
499 url: server.url, 381 const params = getBase({}, { videoId: 'toto' })
500 token: server.accessToken, 382 await updateVideoPlaylistElement(params)
501 elementAttrs: { }, 383 }
502 videoId: 'toto',
503 playlistId: playlistUUID,
504 expectedStatus: 400
505 })
506 384
507 await updateVideoPlaylistElement({ 385 {
508 url: server.url, 386 const params = getBase({}, { videoId: 42, expectedStatus: 404 })
509 token: server.accessToken, 387 await updateVideoPlaylistElement(params)
510 elementAttrs: { }, 388 }
511 videoId: 42,
512 playlistId: playlistUUID,
513 expectedStatus: 404
514 })
515 }) 389 })
516 390
517 it('Should fail with a bad start/stop timestamp', async function () { 391 it('Should fail with a bad start/stop timestamp', async function () {
518 await updateVideoPlaylistElement({ 392 {
519 url: server.url, 393 const params = getBase({ startTimestamp: 'toto' as any })
520 token: server.accessToken, 394 await updateVideoPlaylistElement(params)
521 elementAttrs: { 395 }
522 startTimestamp: 'toto' as any
523 },
524 videoId: videoId,
525 playlistId: playlistUUID,
526 expectedStatus: 400
527 })
528 396
529 await updateVideoPlaylistElement({ 397 {
530 url: server.url, 398 const params = getBase({ stopTimestamp: -42 })
531 token: server.accessToken, 399 await updateVideoPlaylistElement(params)
532 elementAttrs: { 400 }
533 stopTimestamp: -42
534 },
535 videoId: videoId,
536 playlistId: playlistUUID,
537 expectedStatus: 400
538 })
539 }) 401 })
540 402
541 it('Should fail with an unknown element', async function () { 403 it('Should fail with an unknown element', async function () {
542 await updateVideoPlaylistElement({ 404 const params = getBase({}, { videoId: videoId2, expectedStatus: 404 })
543 url: server.url, 405 await updateVideoPlaylistElement(params)
544 token: server.accessToken,
545 elementAttrs: {
546 stopTimestamp: 2
547 },
548 videoId: videoId2,
549 playlistId: playlistUUID,
550 expectedStatus: 404
551 })
552 }) 406 })
553 407
554 it('Succeed with the correct params', async function () { 408 it('Succeed with the correct params', async function () {
555 await updateVideoPlaylistElement({ 409 const params = getBase({}, { expectedStatus: 204 })
556 url: server.url, 410 await updateVideoPlaylistElement(params)
557 token: server.accessToken,
558 elementAttrs: {
559 stopTimestamp: 2
560 },
561 videoId: videoId,
562 playlistId: playlistUUID,
563 expectedStatus: 204
564 })
565 }) 411 })
566 }) 412 })
567 413
@@ -569,280 +415,166 @@ describe('Test video playlists API validator', function () {
569 let videoId3: number 415 let videoId3: number
570 let videoId4: number 416 let videoId4: number
571 417
572 before(async function () { 418 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => {
573 { 419 return Object.assign({
574 const res = await uploadVideo(server.url, server.accessToken, { name: 'video 3' })
575 videoId3 = res.body.video.id
576 }
577
578 {
579 const res = await uploadVideo(server.url, server.accessToken, { name: 'video 4' })
580 videoId4 = res.body.video.id
581 }
582
583 await addVideoInPlaylist({
584 url: server.url, 420 url: server.url,
585 token: server.accessToken, 421 token: server.accessToken,
586 playlistId: playlistUUID, 422 playlistId: playlistUUID,
587 elementAttrs: { videoId: videoId3 } 423 elementAttrs: Object.assign({
588 }) 424 startPosition: 1,
425 insertAfterPosition: 2,
426 reorderLength: 3
427 }, elementAttrs),
428 expectedStatus: 400
429 }, wrapper)
430 }
589 431
590 await addVideoInPlaylist({ 432 before(async function () {
591 url: server.url, 433 videoId3 = (await uploadVideoAndGetId({ server, videoName: 'video 3' })).id
592 token: server.accessToken, 434 videoId4 = (await uploadVideoAndGetId({ server, videoName: 'video 4' })).id
593 playlistId: playlistUUID, 435
594 elementAttrs: { videoId: videoId4 } 436 for (let id of [ videoId3, videoId4 ]) {
595 }) 437 await addVideoInPlaylist({
438 url: server.url,
439 token: server.accessToken,
440 playlistId: playlistUUID,
441 elementAttrs: { videoId: id }
442 })
443 }
596 }) 444 })
597 445
598 it('Should fail with an unauthenticated user', async function () { 446 it('Should fail with an unauthenticated user', async function () {
599 await reorderVideosPlaylist({ 447 const params = getBase({}, { token: null, expectedStatus: 401 })
600 url: server.url, 448 await reorderVideosPlaylist(params)
601 token: null,
602 playlistId: playlistUUID,
603 elementAttrs: {
604 startPosition: 1,
605 insertAfterPosition: 2
606 },
607 expectedStatus: 401
608 })
609 }) 449 })
610 450
611 it('Should fail with the playlist of another user', async function () { 451 it('Should fail with the playlist of another user', async function () {
612 await reorderVideosPlaylist({ 452 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 })
613 url: server.url, 453 await reorderVideosPlaylist(params)
614 token: userAccessToken,
615 playlistId: playlistUUID,
616 elementAttrs: {
617 startPosition: 1,
618 insertAfterPosition: 2
619 },
620 expectedStatus: 403
621 })
622 }) 454 })
623 455
624 it('Should fail with an invalid playlist', async function () { 456 it('Should fail with an invalid playlist', async function () {
625 await reorderVideosPlaylist({ 457 {
626 url: server.url, 458 const params = getBase({}, { playlistId: 'toto' })
627 token: server.accessToken, 459 await reorderVideosPlaylist(params)
628 playlistId: 'toto', 460 }
629 elementAttrs: {
630 startPosition: 1,
631 insertAfterPosition: 2
632 },
633 expectedStatus: 400
634 })
635 461
636 await reorderVideosPlaylist({ 462 {
637 url: server.url, 463 const params = getBase({}, { playlistId: 42, expectedStatus: 404 })
638 token: server.accessToken, 464 await reorderVideosPlaylist(params)
639 playlistId: 42, 465 }
640 elementAttrs: {
641 startPosition: 1,
642 insertAfterPosition: 2
643 },
644 expectedStatus: 404
645 })
646 }) 466 })
647 467
648 it('Should fail with an invalid start position', async function () { 468 it('Should fail with an invalid start position', async function () {
649 await reorderVideosPlaylist({ 469 {
650 url: server.url, 470 const params = getBase({ startPosition: -1 })
651 token: server.accessToken, 471 await reorderVideosPlaylist(params)
652 playlistId: playlistUUID, 472 }
653 elementAttrs: {
654 startPosition: -1,
655 insertAfterPosition: 2
656 },
657 expectedStatus: 400
658 })
659 473
660 await reorderVideosPlaylist({ 474 {
661 url: server.url, 475 const params = getBase({ startPosition: 'toto' as any })
662 token: server.accessToken, 476 await reorderVideosPlaylist(params)
663 playlistId: playlistUUID, 477 }
664 elementAttrs: {
665 startPosition: 'toto' as any,
666 insertAfterPosition: 2
667 },
668 expectedStatus: 400
669 })
670 478
671 await reorderVideosPlaylist({ 479 {
672 url: server.url, 480 const params = getBase({ startPosition: 42 })
673 token: server.accessToken, 481 await reorderVideosPlaylist(params)
674 playlistId: playlistUUID, 482 }
675 elementAttrs: {
676 startPosition: 42,
677 insertAfterPosition: 2
678 },
679 expectedStatus: 400
680 })
681 }) 483 })
682 484
683 it('Should fail with an invalid insert after position', async function () { 485 it('Should fail with an invalid insert after position', async function () {
684 await reorderVideosPlaylist({ 486 {
685 url: server.url, 487 const params = getBase({ insertAfterPosition: 'toto' as any })
686 token: server.accessToken, 488 await reorderVideosPlaylist(params)
687 playlistId: playlistUUID, 489 }
688 elementAttrs: {
689 startPosition: 1,
690 insertAfterPosition: 'toto' as any
691 },
692 expectedStatus: 400
693 })
694 490
695 await reorderVideosPlaylist({ 491 {
696 url: server.url, 492 const params = getBase({ insertAfterPosition: -2 })
697 token: server.accessToken, 493 await reorderVideosPlaylist(params)
698 playlistId: playlistUUID, 494 }
699 elementAttrs: {
700 startPosition: 1,
701 insertAfterPosition: -2
702 },
703 expectedStatus: 400
704 })
705 495
706 await reorderVideosPlaylist({ 496 {
707 url: server.url, 497 const params = getBase({ insertAfterPosition: 42 })
708 token: server.accessToken, 498 await reorderVideosPlaylist(params)
709 playlistId: playlistUUID, 499 }
710 elementAttrs: {
711 startPosition: 1,
712 insertAfterPosition: 42
713 },
714 expectedStatus: 400
715 })
716 }) 500 })
717 501
718 it('Should fail with an invalid reorder length', async function () { 502 it('Should fail with an invalid reorder length', async function () {
719 await reorderVideosPlaylist({ 503 {
720 url: server.url, 504 const params = getBase({ reorderLength: 'toto' as any })
721 token: server.accessToken, 505 await reorderVideosPlaylist(params)
722 playlistId: playlistUUID, 506 }
723 elementAttrs: {
724 startPosition: 1,
725 insertAfterPosition: 2,
726 reorderLength: 'toto' as any
727 },
728 expectedStatus: 400
729 })
730 507
731 await reorderVideosPlaylist({ 508 {
732 url: server.url, 509 const params = getBase({ reorderLength: -2 })
733 token: server.accessToken, 510 await reorderVideosPlaylist(params)
734 playlistId: playlistUUID, 511 }
735 elementAttrs: {
736 startPosition: 1,
737 insertAfterPosition: 2,
738 reorderLength: -1
739 },
740 expectedStatus: 400
741 })
742 512
743 await reorderVideosPlaylist({ 513 {
744 url: server.url, 514 const params = getBase({ reorderLength: 42 })
745 token: server.accessToken, 515 await reorderVideosPlaylist(params)
746 playlistId: playlistUUID, 516 }
747 elementAttrs: {
748 startPosition: 1,
749 insertAfterPosition: 2,
750 reorderLength: 4
751 },
752 expectedStatus: 400
753 })
754 }) 517 })
755 518
756 it('Succeed with the correct params', async function () { 519 it('Succeed with the correct params', async function () {
757 await reorderVideosPlaylist({ 520 const params = getBase({}, { expectedStatus: 204 })
758 url: server.url, 521 await reorderVideosPlaylist(params)
759 token: server.accessToken,
760 playlistId: playlistUUID,
761 elementAttrs: {
762 startPosition: 1,
763 insertAfterPosition: 2,
764 reorderLength: 3
765 },
766 expectedStatus: 204
767 })
768 }) 522 })
769 }) 523 })
770 524
771 describe('When deleting an element in a playlist', function () { 525 describe('When deleting an element in a playlist', function () {
772 it('Should fail with an unauthenticated user', async function () { 526 const getBase = (wrapper: any = {}) => {
773 await removeVideoFromPlaylist({ 527 return Object.assign({
774 url: server.url, 528 url: server.url,
775 token: null, 529 token: server.accessToken,
776 videoId, 530 videoId: videoId,
777 playlistId: playlistUUID, 531 playlistId: playlistUUID,
778 expectedStatus: 401 532 expectedStatus: 400
779 }) 533 }, wrapper)
534 }
535
536 it('Should fail with an unauthenticated user', async function () {
537 const params = getBase({ token: null, expectedStatus: 401 })
538 await removeVideoFromPlaylist(params)
780 }) 539 })
781 540
782 it('Should fail with the playlist of another user', async function () { 541 it('Should fail with the playlist of another user', async function () {
783 await removeVideoFromPlaylist({ 542 const params = getBase({ token: userAccessToken, expectedStatus: 403 })
784 url: server.url, 543 await removeVideoFromPlaylist(params)
785 token: userAccessToken,
786 videoId,
787 playlistId: playlistUUID,
788 expectedStatus: 403
789 })
790 }) 544 })
791 545
792 it('Should fail with an unknown or incorrect playlist id', async function () { 546 it('Should fail with an unknown or incorrect playlist id', async function () {
793 await removeVideoFromPlaylist({ 547 {
794 url: server.url, 548 const params = getBase({ playlistId: 'toto' })
795 token: server.accessToken, 549 await removeVideoFromPlaylist(params)
796 videoId, 550 }
797 playlistId: 'toto',
798 expectedStatus: 400
799 })
800 551
801 await removeVideoFromPlaylist({ 552 {
802 url: server.url, 553 const params = getBase({ playlistId: 42, expectedStatus: 404 })
803 token: server.accessToken, 554 await removeVideoFromPlaylist(params)
804 videoId, 555 }
805 playlistId: 42,
806 expectedStatus: 404
807 })
808 }) 556 })
809 557
810 it('Should fail with an unknown or incorrect video id', async function () { 558 it('Should fail with an unknown or incorrect video id', async function () {
811 await removeVideoFromPlaylist({ 559 {
812 url: server.url, 560 const params = getBase({ videoId: 'toto' })
813 token: server.accessToken, 561 await removeVideoFromPlaylist(params)
814 videoId: 'toto', 562 }
815 playlistId: playlistUUID,
816 expectedStatus: 400
817 })
818 563
819 await removeVideoFromPlaylist({ 564 {
820 url: server.url, 565 const params = getBase({ videoId: 42, expectedStatus: 404 })
821 token: server.accessToken, 566 await removeVideoFromPlaylist(params)
822 videoId: 42, 567 }
823 playlistId: playlistUUID,
824 expectedStatus: 404
825 })
826 }) 568 })
827 569
828 it('Should fail with an unknown element', async function () { 570 it('Should fail with an unknown element', async function () {
829 await removeVideoFromPlaylist({ 571 const params = getBase({ videoId: videoId2, expectedStatus: 404 })
830 url: server.url, 572 await removeVideoFromPlaylist(params)
831 token: server.accessToken,
832 videoId: videoId2,
833 playlistId: playlistUUID,
834 expectedStatus: 404
835 })
836 }) 573 })
837 574
838 it('Succeed with the correct params', async function () { 575 it('Succeed with the correct params', async function () {
839 await removeVideoFromPlaylist({ 576 const params = getBase({ expectedStatus: 204 })
840 url: server.url, 577 await removeVideoFromPlaylist(params)
841 token: server.accessToken,
842 videoId: videoId,
843 playlistId: playlistUUID,
844 expectedStatus: 204
845 })
846 }) 578 })
847 }) 579 })
848 580
@@ -855,6 +587,10 @@ describe('Test video playlists API validator', function () {
855 await deleteVideoPlaylist(server.url, userAccessToken, playlistUUID, 403) 587 await deleteVideoPlaylist(server.url, userAccessToken, playlistUUID, 403)
856 }) 588 })
857 589
590 it('Should fail with the watch later playlist', async function () {
591 await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, 409)
592 })
593
858 it('Should succeed with the correct params', async function () { 594 it('Should succeed with the correct params', async function () {
859 await deleteVideoPlaylist(server.url, server.accessToken, playlistUUID) 595 await deleteVideoPlaylist(server.url, server.accessToken, playlistUUID)
860 }) 596 })