aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
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
parent07b1a18aa678d260009a93e36606c5c5f585723d (diff)
downloadPeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.tar.gz
PeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.tar.zst
PeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.zip
Add playlist rest tests
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/video-playlists.ts818
-rw-r--r--server/tests/api/videos/video-playlists.ts728
-rw-r--r--server/tests/fixtures/thumbnail-playlist.jpgbin0 -> 2520 bytes
4 files changed, 950 insertions, 597 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index 77c17036a..ca51cd39a 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -16,6 +16,7 @@ import './video-captions'
16import './video-channels' 16import './video-channels'
17import './video-comments' 17import './video-comments'
18import './video-imports' 18import './video-imports'
19import './video-playlists'
19import './videos' 20import './videos'
20import './videos-filter' 21import './videos-filter'
21import './videos-history' 22import './videos-history'
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 })
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts
index cb23239da..7dd1563fc 100644
--- a/server/tests/api/videos/video-playlists.ts
+++ b/server/tests/api/videos/video-playlists.ts
@@ -2,152 +2,768 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { join } from 'path'
6import * as request from 'supertest'
7import { VideoPrivacy } from '../../../../shared/models/videos'
8import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
9import { 5import {
10 addVideoChannel, 6 addVideoChannel,
11 checkTmpIsEmpty, 7 addVideoInPlaylist,
12 checkVideoFilesWereRemoved, 8 checkPlaylistFilesWereRemoved,
13 completeVideoCheck,
14 createUser, 9 createUser,
15 dateIsValid, 10 createVideoPlaylist,
11 deleteVideoChannel,
12 deleteVideoPlaylist,
16 doubleFollow, 13 doubleFollow,
17 flushAndRunMultipleServers, 14 flushAndRunMultipleServers,
18 flushTests, 15 flushTests,
19 getLocalVideos, 16 getAccountPlaylistsList,
20 getVideo, 17 getAccountPlaylistsListWithToken,
21 getVideoChannelsList, 18 getPlaylistVideos,
22 getVideosList, 19 getVideoChannelPlaylistsList,
20 getVideoPlaylist,
21 getVideoPlaylistsList,
22 getVideoPlaylistWithToken,
23 killallServers, 23 killallServers,
24 rateVideo, 24 removeUser,
25 removeVideo, 25 removeVideoFromPlaylist,
26 reorderVideosPlaylist,
26 ServerInfo, 27 ServerInfo,
27 setAccessTokensToServers, 28 setAccessTokensToServers,
29 setDefaultVideoChannel,
28 testImage, 30 testImage,
29 updateVideo, 31 unfollow,
32 updateVideoPlaylist,
33 updateVideoPlaylistElement,
30 uploadVideo, 34 uploadVideo,
35 uploadVideoAndGetId,
31 userLogin, 36 userLogin,
32 viewVideo, 37 waitJobs
33 wait,
34 webtorrentAdd
35} from '../../../../shared/utils' 38} from '../../../../shared/utils'
36import { 39import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
37 addVideoCommentReply, 40import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model'
38 addVideoCommentThread, 41import { Video } from '../../../../shared/models/videos'
39 deleteVideoComment, 42import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
40 getVideoCommentThreads,
41 getVideoThreadComments
42} from '../../../../shared/utils/videos/video-comments'
43import { waitJobs } from '../../../../shared/utils/server/jobs'
44 43
45const expect = chai.expect 44const expect = chai.expect
46 45
47describe('Test video playlists', function () { 46describe('Test video playlists', function () {
48 let servers: ServerInfo[] = [] 47 let servers: ServerInfo[] = []
49 48
49 let playlistServer2Id1: number
50 let playlistServer2Id2: number
51 let playlistServer2UUID2: number
52
53 let playlistServer1Id: number
54 let playlistServer1UUID: string
55
56 let nsfwVideoServer1: number
57
50 before(async function () { 58 before(async function () {
51 this.timeout(120000) 59 this.timeout(120000)
52 60
53 servers = await flushAndRunMultipleServers(3) 61 servers = await flushAndRunMultipleServers(3, { transcoding: { enabled: false } })
54 62
55 // Get the access tokens 63 // Get the access tokens
56 await setAccessTokensToServers(servers) 64 await setAccessTokensToServers(servers)
65 await setDefaultVideoChannel(servers)
57 66
58 // Server 1 and server 2 follow each other 67 // Server 1 and server 2 follow each other
59 await doubleFollow(servers[0], servers[1]) 68 await doubleFollow(servers[0], servers[1])
60 // Server 1 and server 3 follow each other 69 // Server 1 and server 3 follow each other
61 await doubleFollow(servers[0], servers[2]) 70 await doubleFollow(servers[0], servers[2])
71
72 {
73 const serverPromises: Promise<any>[][] = []
74
75 for (const server of servers) {
76 const videoPromises: Promise<any>[] = []
77
78 for (let i = 0; i < 7; i++) {
79 videoPromises.push(
80 uploadVideo(server.url, server.accessToken, { name: `video ${i} server ${server.serverNumber}`, nsfw: false })
81 .then(res => res.body.video)
82 )
83 }
84
85 serverPromises.push(videoPromises)
86 }
87
88 servers[0].videos = await Promise.all(serverPromises[0])
89 servers[1].videos = await Promise.all(serverPromises[1])
90 servers[2].videos = await Promise.all(serverPromises[2])
91 }
92
93 nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[ 0 ], videoName: 'NSFW video', nsfw: true })).id
94
95 await waitJobs(servers)
62 }) 96 })
63 97
64 it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () { 98 it('Should list watch later playlist', async function () {
99 const url = servers[ 0 ].url
100 const accessToken = servers[ 0 ].accessToken
101
102 {
103 const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.WATCH_LATER)
104
105 expect(res.body.total).to.equal(1)
106 expect(res.body.data).to.have.lengthOf(1)
65 107
108 const playlist: VideoPlaylist = res.body.data[ 0 ]
109 expect(playlist.displayName).to.equal('Watch later')
110 expect(playlist.type.id).to.equal(VideoPlaylistType.WATCH_LATER)
111 expect(playlist.type.label).to.equal('Watch later')
112 }
113
114 {
115 const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.REGULAR)
116
117 expect(res.body.total).to.equal(0)
118 expect(res.body.data).to.have.lengthOf(0)
119 }
120
121 {
122 const res = await getAccountPlaylistsList(url, 'root', 0, 5)
123 expect(res.body.total).to.equal(0)
124 expect(res.body.data).to.have.lengthOf(0)
125 }
126 })
127
128 it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () {
129 this.timeout(30000)
130
131 await createVideoPlaylist({
132 url: servers[0].url,
133 token: servers[0].accessToken,
134 playlistAttrs: {
135 displayName: 'my super playlist',
136 privacy: VideoPlaylistPrivacy.PUBLIC,
137 description: 'my super description',
138 thumbnailfile: 'thumbnail.jpg',
139 videoChannelId: servers[0].videoChannel.id
140 }
141 })
142
143 await waitJobs(servers)
144
145 for (const server of servers) {
146 const res = await getVideoPlaylistsList(server.url, 0, 5)
147 expect(res.body.total).to.equal(1)
148 expect(res.body.data).to.have.lengthOf(1)
149
150 const playlistFromList = res.body.data[0] as VideoPlaylist
151
152 const res2 = await getVideoPlaylist(server.url, playlistFromList.uuid)
153 const playlistFromGet = res2.body
154
155 for (const playlist of [ playlistFromGet, playlistFromList ]) {
156 expect(playlist.id).to.be.a('number')
157 expect(playlist.uuid).to.be.a('string')
158
159 expect(playlist.isLocal).to.equal(server.serverNumber === 1)
160
161 expect(playlist.displayName).to.equal('my super playlist')
162 expect(playlist.description).to.equal('my super description')
163 expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
164 expect(playlist.privacy.label).to.equal('Public')
165 expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
166 expect(playlist.type.label).to.equal('Regular')
167
168 expect(playlist.videosLength).to.equal(0)
169
170 expect(playlist.ownerAccount.name).to.equal('root')
171 expect(playlist.ownerAccount.displayName).to.equal('root')
172 expect(playlist.videoChannel.name).to.equal('root_channel')
173 expect(playlist.videoChannel.displayName).to.equal('Main root channel')
174 }
175 }
66 }) 176 })
67 177
68 it('Should create a playlist on server 2 and have the playlist on server 1 but not on server 3', async function () { 178 it('Should create a playlist on server 2 and have the playlist on server 1 but not on server 3', async function () {
69 // create 2 playlists (with videos and no videos) 179 this.timeout(30000)
70 // With thumbnail and no thumbnail 180
181 {
182 const res = await createVideoPlaylist({
183 url: servers[1].url,
184 token: servers[1].accessToken,
185 playlistAttrs: {
186 displayName: 'playlist 2',
187 privacy: VideoPlaylistPrivacy.PUBLIC
188 }
189 })
190 playlistServer2Id1 = res.body.videoPlaylist.id
191 }
192
193 {
194 const res = await createVideoPlaylist({
195 url: servers[ 1 ].url,
196 token: servers[ 1 ].accessToken,
197 playlistAttrs: {
198 displayName: 'playlist 3',
199 privacy: VideoPlaylistPrivacy.PUBLIC,
200 thumbnailfile: 'thumbnail.jpg'
201 }
202 })
203
204 playlistServer2Id2 = res.body.videoPlaylist.id
205 playlistServer2UUID2 = res.body.videoPlaylist.uuid
206 }
207
208 for (let id of [ playlistServer2Id1, playlistServer2Id2 ]) {
209 await addVideoInPlaylist({
210 url: servers[ 1 ].url,
211 token: servers[ 1 ].accessToken,
212 playlistId: id,
213 elementAttrs: { videoId: servers[ 1 ].videos[ 0 ].id, startTimestamp: 1, stopTimestamp: 2 }
214 })
215 await addVideoInPlaylist({
216 url: servers[ 1 ].url,
217 token: servers[ 1 ].accessToken,
218 playlistId: id,
219 elementAttrs: { videoId: servers[ 1 ].videos[ 1 ].id }
220 })
221 }
222
223 await waitJobs(servers)
224
225 for (const server of [ servers[0], servers[1] ]) {
226 const res = await getVideoPlaylistsList(server.url, 0, 5)
227
228 const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2')
229 expect(playlist2).to.not.be.undefined
230 await testImage(server.url, 'thumbnail-playlist', playlist2.thumbnailPath)
231
232 const playlist3 = res.body.data.find(p => p.displayName === 'playlist 3')
233 expect(playlist3).to.not.be.undefined
234 await testImage(server.url, 'thumbnail', playlist3.thumbnailPath)
235 }
236
237 const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
238 expect(res.body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined
239 expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined
71 }) 240 })
72 241
73 it('Should have the playlist on server 3 after a new follow', async function () { 242 it('Should have the playlist on server 3 after a new follow', async function () {
243 this.timeout(30000)
244
74 // Server 2 and server 3 follow each other 245 // Server 2 and server 3 follow each other
75 await doubleFollow(servers[1], servers[2]) 246 await doubleFollow(servers[1], servers[2])
247
248 const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
249
250 const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2')
251 expect(playlist2).to.not.be.undefined
252 await testImage(servers[2].url, 'thumbnail-playlist', playlist2.thumbnailPath)
253
254 expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined
76 }) 255 })
77 256
78 it('Should create some playlists and list them correctly', async function () { 257 it('Should correctly list the playlists', async function () {
79 // create 3 playlists with some videos in it 258 this.timeout(30000)
80 // check pagination 259
81 // check sort 260 {
82 // check empty 261 const res = await getVideoPlaylistsList(servers[ 2 ].url, 1, 2, 'createdAt')
262
263 expect(res.body.total).to.equal(3)
264
265 const data: VideoPlaylist[] = res.body.data
266 expect(data).to.have.lengthOf(2)
267 expect(data[ 0 ].displayName).to.equal('playlist 2')
268 expect(data[ 1 ].displayName).to.equal('playlist 3')
269 }
270
271 {
272 const res = await getVideoPlaylistsList(servers[ 2 ].url, 1, 2, '-createdAt')
273
274 expect(res.body.total).to.equal(3)
275
276 const data: VideoPlaylist[] = res.body.data
277 expect(data).to.have.lengthOf(2)
278 expect(data[ 0 ].displayName).to.equal('playlist 2')
279 expect(data[ 1 ].displayName).to.equal('my super playlist')
280 }
83 }) 281 })
84 282
85 it('Should list video channel playlists', async function () { 283 it('Should list video channel playlists', async function () {
86 // check pagination 284 this.timeout(30000)
87 // check sort 285
88 // check empty 286 {
287 const res = await getVideoChannelPlaylistsList(servers[ 0 ].url, 'root_channel', 0, 2, '-createdAt')
288
289 expect(res.body.total).to.equal(1)
290
291 const data: VideoPlaylist[] = res.body.data
292 expect(data).to.have.lengthOf(1)
293 expect(data[ 0 ].displayName).to.equal('my super playlist')
294 }
89 }) 295 })
90 296
91 it('Should list account playlists', async function () { 297 it('Should list account playlists', async function () {
92 // check pagination 298 this.timeout(30000)
93 // check sort 299
94 // check empty 300 {
301 const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 1, 2, '-createdAt')
302
303 expect(res.body.total).to.equal(2)
304
305 const data: VideoPlaylist[] = res.body.data
306 expect(data).to.have.lengthOf(1)
307 expect(data[ 0 ].displayName).to.equal('playlist 2')
308 }
309
310 {
311 const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 1, 2, 'createdAt')
312
313 expect(res.body.total).to.equal(2)
314
315 const data: VideoPlaylist[] = res.body.data
316 expect(data).to.have.lengthOf(1)
317 expect(data[ 0 ].displayName).to.equal('playlist 3')
318 }
95 }) 319 })
96 320
97 it('Should get a playlist', async function () { 321 it('Should not list unlisted or private playlists', async function () {
98 // get empty playlist 322 this.timeout(30000)
99 // get non empty playlist 323
324 await createVideoPlaylist({
325 url: servers[ 1 ].url,
326 token: servers[ 1 ].accessToken,
327 playlistAttrs: {
328 displayName: 'playlist unlisted',
329 privacy: VideoPlaylistPrivacy.UNLISTED
330 }
331 })
332
333 await createVideoPlaylist({
334 url: servers[ 1 ].url,
335 token: servers[ 1 ].accessToken,
336 playlistAttrs: {
337 displayName: 'playlist private',
338 privacy: VideoPlaylistPrivacy.PRIVATE
339 }
340 })
341
342 await waitJobs(servers)
343
344 for (const server of servers) {
345 const results = [
346 await getAccountPlaylistsList(server.url, 'root@localhost:9002', 0, 5, '-createdAt'),
347 await getVideoPlaylistsList(server.url, 0, 2, '-createdAt')
348 ]
349
350 expect(results[0].body.total).to.equal(2)
351 expect(results[1].body.total).to.equal(3)
352
353 for (const res of results) {
354 const data: VideoPlaylist[] = res.body.data
355 expect(data).to.have.lengthOf(2)
356 expect(data[ 0 ].displayName).to.equal('playlist 3')
357 expect(data[ 1 ].displayName).to.equal('playlist 2')
358 }
359 }
100 }) 360 })
101 361
102 it('Should update a playlist', async function () { 362 it('Should update a playlist', async function () {
103 // update thumbnail 363 this.timeout(30000)
104 364
105 // update other details 365 await updateVideoPlaylist({
366 url: servers[1].url,
367 token: servers[1].accessToken,
368 playlistAttrs: {
369 displayName: 'playlist 3 updated',
370 description: 'description updated',
371 privacy: VideoPlaylistPrivacy.UNLISTED,
372 thumbnailfile: 'thumbnail.jpg',
373 videoChannelId: servers[1].videoChannel.id
374 },
375 playlistId: playlistServer2Id2
376 })
377
378 await waitJobs(servers)
379
380 for (const server of servers) {
381 const res = await getVideoPlaylist(server.url, playlistServer2UUID2)
382 const playlist: VideoPlaylist = res.body
383
384 expect(playlist.displayName).to.equal('playlist 3 updated')
385 expect(playlist.description).to.equal('description updated')
386
387 expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.UNLISTED)
388 expect(playlist.privacy.label).to.equal('Unlisted')
389
390 expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
391 expect(playlist.type.label).to.equal('Regular')
392
393 expect(playlist.videosLength).to.equal(2)
394
395 expect(playlist.ownerAccount.name).to.equal('root')
396 expect(playlist.ownerAccount.displayName).to.equal('root')
397 expect(playlist.videoChannel.name).to.equal('root_channel')
398 expect(playlist.videoChannel.displayName).to.equal('Main root channel')
399 }
106 }) 400 })
107 401
108 it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () { 402 it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () {
403 this.timeout(30000)
404
405 const addVideo = (elementAttrs: any) => {
406 return addVideoInPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: playlistServer1Id, elementAttrs })
407 }
109 408
409 const res = await createVideoPlaylist({
410 url: servers[ 0 ].url,
411 token: servers[ 0 ].accessToken,
412 playlistAttrs: {
413 displayName: 'playlist 4',
414 privacy: VideoPlaylistPrivacy.PUBLIC
415 }
416 })
417
418 playlistServer1Id = res.body.videoPlaylist.id
419 playlistServer1UUID = res.body.videoPlaylist.uuid
420
421 await addVideo({ videoId: servers[0].videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 })
422 await addVideo({ videoId: servers[2].videos[1].uuid, startTimestamp: 35 })
423 await addVideo({ videoId: servers[2].videos[2].uuid })
424 await addVideo({ videoId: servers[0].videos[3].uuid, stopTimestamp: 35 })
425 await addVideo({ videoId: servers[0].videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 })
426 await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 })
427
428 await waitJobs(servers)
110 }) 429 })
111 430
112 it('Should correctly list playlist videos', async function () { 431 it('Should correctly list playlist videos', async function () {
113 // empty 432 this.timeout(30000)
114 // some filters? 433
434 for (const server of servers) {
435 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
436
437 expect(res.body.total).to.equal(6)
438
439 const videos: Video[] = res.body.data
440 expect(videos).to.have.lengthOf(6)
441
442 expect(videos[0].name).to.equal('video 0 server 1')
443 expect(videos[0].playlistElement.position).to.equal(1)
444 expect(videos[0].playlistElement.startTimestamp).to.equal(15)
445 expect(videos[0].playlistElement.stopTimestamp).to.equal(28)
446
447 expect(videos[1].name).to.equal('video 1 server 3')
448 expect(videos[1].playlistElement.position).to.equal(2)
449 expect(videos[1].playlistElement.startTimestamp).to.equal(35)
450 expect(videos[1].playlistElement.stopTimestamp).to.be.null
451
452 expect(videos[2].name).to.equal('video 2 server 3')
453 expect(videos[2].playlistElement.position).to.equal(3)
454 expect(videos[2].playlistElement.startTimestamp).to.be.null
455 expect(videos[2].playlistElement.stopTimestamp).to.be.null
456
457 expect(videos[3].name).to.equal('video 3 server 1')
458 expect(videos[3].playlistElement.position).to.equal(4)
459 expect(videos[3].playlistElement.startTimestamp).to.be.null
460 expect(videos[3].playlistElement.stopTimestamp).to.equal(35)
461
462 expect(videos[4].name).to.equal('video 4 server 1')
463 expect(videos[4].playlistElement.position).to.equal(5)
464 expect(videos[4].playlistElement.startTimestamp).to.equal(45)
465 expect(videos[4].playlistElement.stopTimestamp).to.equal(60)
466
467 expect(videos[5].name).to.equal('NSFW video')
468 expect(videos[5].playlistElement.position).to.equal(6)
469 expect(videos[5].playlistElement.startTimestamp).to.equal(5)
470 expect(videos[5].playlistElement.stopTimestamp).to.be.null
471
472 const res2 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10, { nsfw: false })
473 expect(res2.body.total).to.equal(5)
474 expect(res2.body.data.find(v => v.name === 'NSFW video')).to.be.undefined
475
476 const res3 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 2)
477 expect(res3.body.data).to.have.lengthOf(2)
478 }
115 }) 479 })
116 480
117 it('Should reorder the playlist', async function () { 481 it('Should reorder the playlist', async function () {
118 // reorder 1 element 482 this.timeout(30000)
119 // reorder 3 elements 483
120 // reorder at the beginning 484 {
121 // reorder at the end 485 await reorderVideosPlaylist({
122 // reorder before/after 486 url: servers[ 0 ].url,
487 token: servers[ 0 ].accessToken,
488 playlistId: playlistServer1Id,
489 elementAttrs: {
490 startPosition: 2,
491 insertAfterPosition: 3
492 }
493 })
494
495 await waitJobs(servers)
496
497 for (const server of servers) {
498 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
499 const names = res.body.data.map(v => v.name)
500
501 expect(names).to.deep.equal([
502 'video 0 server 1',
503 'video 2 server 3',
504 'video 1 server 3',
505 'video 3 server 1',
506 'video 4 server 1',
507 'NSFW video'
508 ])
509 }
510 }
511
512 {
513 await reorderVideosPlaylist({
514 url: servers[0].url,
515 token: servers[0].accessToken,
516 playlistId: playlistServer1Id,
517 elementAttrs: {
518 startPosition: 1,
519 reorderLength: 3,
520 insertAfterPosition: 4
521 }
522 })
523
524 await waitJobs(servers)
525
526 for (const server of servers) {
527 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
528 const names = res.body.data.map(v => v.name)
529
530 expect(names).to.deep.equal([
531 'video 3 server 1',
532 'video 0 server 1',
533 'video 2 server 3',
534 'video 1 server 3',
535 'video 4 server 1',
536 'NSFW video'
537 ])
538 }
539 }
540
541 {
542 await reorderVideosPlaylist({
543 url: servers[0].url,
544 token: servers[0].accessToken,
545 playlistId: playlistServer1Id,
546 elementAttrs: {
547 startPosition: 6,
548 insertAfterPosition: 3
549 }
550 })
551
552 await waitJobs(servers)
553
554 for (const server of servers) {
555 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
556 const videos: Video[] = res.body.data
557
558 const names = videos.map(v => v.name)
559
560 expect(names).to.deep.equal([
561 'video 3 server 1',
562 'video 0 server 1',
563 'video 2 server 3',
564 'NSFW video',
565 'video 1 server 3',
566 'video 4 server 1'
567 ])
568
569 for (let i = 1; i <= videos.length; i++) {
570 expect(videos[i - 1].playlistElement.position).to.equal(i)
571 }
572 }
573 }
123 }) 574 })
124 575
125 it('Should update startTimestamp/endTimestamp of some elements', async function () { 576 it('Should update startTimestamp/endTimestamp of some elements', async function () {
126 577 this.timeout(30000)
578
579 await updateVideoPlaylistElement({
580 url: servers[0].url,
581 token: servers[0].accessToken,
582 playlistId: playlistServer1Id,
583 videoId: servers[0].videos[3].uuid,
584 elementAttrs: {
585 startTimestamp: 1
586 }
587 })
588
589 await updateVideoPlaylistElement({
590 url: servers[0].url,
591 token: servers[0].accessToken,
592 playlistId: playlistServer1Id,
593 videoId: servers[0].videos[4].uuid,
594 elementAttrs: {
595 stopTimestamp: null
596 }
597 })
598
599 await waitJobs(servers)
600
601 for (const server of servers) {
602 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
603 const videos: Video[] = res.body.data
604
605 expect(videos[0].name).to.equal('video 3 server 1')
606 expect(videos[0].playlistElement.position).to.equal(1)
607 expect(videos[0].playlistElement.startTimestamp).to.equal(1)
608 expect(videos[0].playlistElement.stopTimestamp).to.equal(35)
609
610 expect(videos[5].name).to.equal('video 4 server 1')
611 expect(videos[5].playlistElement.position).to.equal(6)
612 expect(videos[5].playlistElement.startTimestamp).to.equal(45)
613 expect(videos[5].playlistElement.stopTimestamp).to.be.null
614 }
127 }) 615 })
128 616
129 it('Should delete some elements', async function () { 617 it('Should delete some elements', async function () {
618 this.timeout(30000)
619
620 await removeVideoFromPlaylist({
621 url: servers[0].url,
622 token: servers[0].accessToken,
623 playlistId: playlistServer1Id,
624 videoId: servers[0].videos[3].uuid
625 })
626
627 await removeVideoFromPlaylist({
628 url: servers[0].url,
629 token: servers[0].accessToken,
630 playlistId: playlistServer1Id,
631 videoId: nsfwVideoServer1
632 })
633
634 await waitJobs(servers)
635
636 for (const server of servers) {
637 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
638
639 expect(res.body.total).to.equal(4)
640
641 const videos: Video[] = res.body.data
642 expect(videos).to.have.lengthOf(4)
130 643
644 expect(videos[ 0 ].name).to.equal('video 0 server 1')
645 expect(videos[ 0 ].playlistElement.position).to.equal(1)
646
647 expect(videos[ 1 ].name).to.equal('video 2 server 3')
648 expect(videos[ 1 ].playlistElement.position).to.equal(2)
649
650 expect(videos[ 2 ].name).to.equal('video 1 server 3')
651 expect(videos[ 2 ].playlistElement.position).to.equal(3)
652
653 expect(videos[ 3 ].name).to.equal('video 4 server 1')
654 expect(videos[ 3 ].playlistElement.position).to.equal(4)
655 }
131 }) 656 })
132 657
133 it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () { 658 it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () {
659 this.timeout(30000)
134 660
661 await deleteVideoPlaylist(servers[0].url, servers[0].accessToken, playlistServer1Id)
662
663 await waitJobs(servers)
664
665 for (const server of servers) {
666 await getVideoPlaylist(server.url, playlistServer1UUID, 404)
667 }
135 }) 668 })
136 669
137 it('Should have deleted the thumbnail on server 1, 2 and 3', async function () { 670 it('Should have deleted the thumbnail on server 1, 2 and 3', async function () {
671 this.timeout(30000)
138 672
673 for (const server of servers) {
674 await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.serverNumber)
675 }
139 }) 676 })
140 677
141 it('Should unfollow servers 1 and 2 and hide their playlists', async function () { 678 it('Should unfollow servers 1 and 2 and hide their playlists', async function () {
679 this.timeout(30000)
142 680
681 const finder = data => data.find(p => p.displayName === 'my super playlist')
682
683 {
684 const res = await getVideoPlaylistsList(servers[ 2 ].url, 0, 5)
685 expect(res.body.total).to.equal(2)
686 expect(finder(res.body.data)).to.not.be.undefined
687 }
688
689 await unfollow(servers[2].url, servers[2].accessToken, servers[0])
690
691 {
692 const res = await getVideoPlaylistsList(servers[ 2 ].url, 0, 5)
693 expect(res.body.total).to.equal(1)
694
695 expect(finder(res.body.data)).to.be.undefined
696 }
143 }) 697 })
144 698
145 it('Should delete a channel and remove the associated playlist', async function () { 699 it('Should delete a channel and put the associated playlist in private mode', async function () {
700 this.timeout(30000)
701
702 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, { name: 'super_channel', displayName: 'super channel' })
703 const videoChannelId = res.body.videoChannel.id
146 704
705 const res2 = await createVideoPlaylist({
706 url: servers[0].url,
707 token: servers[0].accessToken,
708 playlistAttrs: {
709 displayName: 'channel playlist',
710 privacy: VideoPlaylistPrivacy.PUBLIC,
711 videoChannelId
712 }
713 })
714 const videoPlaylistUUID = res2.body.videoPlaylist.uuid
715
716 await waitJobs(servers)
717
718 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'super_channel')
719
720 await waitJobs(servers)
721
722 const res3 = await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistUUID)
723 expect(res3.body.displayName).to.equal('channel playlist')
724 expect(res3.body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE)
725
726 await getVideoPlaylist(servers[1].url, videoPlaylistUUID, 404)
147 }) 727 })
148 728
149 it('Should delete an account and delete its playlists', async function () { 729 it('Should delete an account and delete its playlists', async function () {
730 this.timeout(30000)
731
732 const user = { username: 'user_1', password: 'password' }
733 const res = await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
734
735 const userId = res.body.user.id
736 const userAccessToken = await userLogin(servers[0], user)
150 737
738 await createVideoPlaylist({
739 url: servers[0].url,
740 token: userAccessToken,
741 playlistAttrs: {
742 displayName: 'playlist to be deleted',
743 privacy: VideoPlaylistPrivacy.PUBLIC
744 }
745 })
746
747 await waitJobs(servers)
748
749 const finder = data => data.find(p => p.displayName === 'playlist to be deleted')
750
751 {
752 for (const server of [ servers[0], servers[1] ]) {
753 const res = await getVideoPlaylistsList(server.url, 0, 15)
754 expect(finder(res.body.data)).to.not.be.undefined
755 }
756 }
757
758 await removeUser(servers[0].url, userId, servers[0].accessToken)
759 await waitJobs(servers)
760
761 {
762 for (const server of [ servers[0], servers[1] ]) {
763 const res = await getVideoPlaylistsList(server.url, 0, 15)
764 expect(finder(res.body.data)).to.be.undefined
765 }
766 }
151 }) 767 })
152 768
153 after(async function () { 769 after(async function () {
diff --git a/server/tests/fixtures/thumbnail-playlist.jpg b/server/tests/fixtures/thumbnail-playlist.jpg
new file mode 100644
index 000000000..19db4f18c
--- /dev/null
+++ b/server/tests/fixtures/thumbnail-playlist.jpg
Binary files differ