]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-playlists.ts
Add playlist rest tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-playlists.ts
CommitLineData
418d092a
C
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
418d092a
C
5import {
6 addVideoChannel,
df0b219d
C
7 addVideoInPlaylist,
8 checkPlaylistFilesWereRemoved,
418d092a 9 createUser,
df0b219d
C
10 createVideoPlaylist,
11 deleteVideoChannel,
12 deleteVideoPlaylist,
418d092a
C
13 doubleFollow,
14 flushAndRunMultipleServers,
15 flushTests,
df0b219d
C
16 getAccountPlaylistsList,
17 getAccountPlaylistsListWithToken,
18 getPlaylistVideos,
19 getVideoChannelPlaylistsList,
20 getVideoPlaylist,
21 getVideoPlaylistsList,
22 getVideoPlaylistWithToken,
418d092a 23 killallServers,
df0b219d
C
24 removeUser,
25 removeVideoFromPlaylist,
26 reorderVideosPlaylist,
418d092a
C
27 ServerInfo,
28 setAccessTokensToServers,
df0b219d 29 setDefaultVideoChannel,
418d092a 30 testImage,
df0b219d
C
31 unfollow,
32 updateVideoPlaylist,
33 updateVideoPlaylistElement,
418d092a 34 uploadVideo,
df0b219d 35 uploadVideoAndGetId,
418d092a 36 userLogin,
df0b219d 37 waitJobs
418d092a 38} from '../../../../shared/utils'
df0b219d
C
39import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
40import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model'
41import { Video } from '../../../../shared/models/videos'
42import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
418d092a
C
43
44const expect = chai.expect
45
46describe('Test video playlists', function () {
47 let servers: ServerInfo[] = []
48
df0b219d
C
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
418d092a
C
58 before(async function () {
59 this.timeout(120000)
60
df0b219d 61 servers = await flushAndRunMultipleServers(3, { transcoding: { enabled: false } })
418d092a
C
62
63 // Get the access tokens
64 await setAccessTokensToServers(servers)
df0b219d 65 await setDefaultVideoChannel(servers)
418d092a
C
66
67 // Server 1 and server 2 follow each other
68 await doubleFollow(servers[0], servers[1])
69 // Server 1 and server 3 follow each other
70 await doubleFollow(servers[0], servers[2])
df0b219d
C
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)
418d092a
C
96 })
97
df0b219d
C
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)
418d092a 107
df0b219d
C
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 }
418d092a
C
176 })
177
178 it('Should create a playlist on server 2 and have the playlist on server 1 but not on server 3', async function () {
df0b219d
C
179 this.timeout(30000)
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
418d092a
C
240 })
241
242 it('Should have the playlist on server 3 after a new follow', async function () {
df0b219d
C
243 this.timeout(30000)
244
418d092a
C
245 // Server 2 and server 3 follow each other
246 await doubleFollow(servers[1], servers[2])
df0b219d
C
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
418d092a
C
255 })
256
df0b219d
C
257 it('Should correctly list the playlists', async function () {
258 this.timeout(30000)
259
260 {
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 }
418d092a
C
281 })
282
283 it('Should list video channel playlists', async function () {
df0b219d
C
284 this.timeout(30000)
285
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 }
418d092a
C
295 })
296
297 it('Should list account playlists', async function () {
df0b219d
C
298 this.timeout(30000)
299
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 }
418d092a
C
319 })
320
df0b219d
C
321 it('Should not list unlisted or private playlists', async function () {
322 this.timeout(30000)
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 }
418d092a
C
360 })
361
362 it('Should update a playlist', async function () {
df0b219d
C
363 this.timeout(30000)
364
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 }
418d092a
C
400 })
401
402 it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () {
df0b219d
C
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 }
418d092a 408
df0b219d
C
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)
418d092a
C
429 })
430
431 it('Should correctly list playlist videos', async function () {
df0b219d
C
432 this.timeout(30000)
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 }
418d092a
C
479 })
480
481 it('Should reorder the playlist', async function () {
df0b219d
C
482 this.timeout(30000)
483
484 {
485 await reorderVideosPlaylist({
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 }
418d092a
C
574 })
575
576 it('Should update startTimestamp/endTimestamp of some elements', async function () {
df0b219d
C
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 }
418d092a
C
615 })
616
617 it('Should delete some elements', async function () {
df0b219d
C
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)
418d092a 643
df0b219d
C
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 }
418d092a
C
656 })
657
658 it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () {
df0b219d 659 this.timeout(30000)
418d092a 660
df0b219d
C
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 }
418d092a
C
668 })
669
670 it('Should have deleted the thumbnail on server 1, 2 and 3', async function () {
df0b219d 671 this.timeout(30000)
418d092a 672
df0b219d
C
673 for (const server of servers) {
674 await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.serverNumber)
675 }
418d092a
C
676 })
677
678 it('Should unfollow servers 1 and 2 and hide their playlists', async function () {
df0b219d 679 this.timeout(30000)
418d092a 680
df0b219d
C
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 }
418d092a
C
697 })
698
df0b219d
C
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
418d092a 704
df0b219d
C
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)
418d092a
C
727 })
728
729 it('Should delete an account and delete its playlists', async function () {
df0b219d
C
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)
418d092a 737
df0b219d
C
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 }
418d092a
C
767 })
768
769 after(async function () {
770 killallServers(servers)
771
772 // Keep the logs if the test failed
773 if (this['ok']) {
774 await flushTests()
775 }
776 })
777})