1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
8 checkPlaylistFilesWereRemoved,
14 flushAndRunMultipleServers,
16 getAccountPlaylistsList,
17 getAccountPlaylistsListWithToken,
19 getVideoChannelPlaylistsList,
21 getVideoPlaylistsList,
22 getVideoPlaylistWithToken,
25 removeVideoFromPlaylist,
26 reorderVideosPlaylist,
28 setAccessTokensToServers,
29 setDefaultVideoChannel,
33 updateVideoPlaylistElement,
38 } from '../../../../shared/utils'
39 import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
40 import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model'
41 import { Video } from '../../../../shared/models/videos'
42 import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
44 const expect = chai.expect
46 describe('Test video playlists', function () {
47 let servers: ServerInfo[] = []
49 let playlistServer2Id1: number
50 let playlistServer2Id2: number
51 let playlistServer2UUID2: number
53 let playlistServer1Id: number
54 let playlistServer1UUID: string
56 let nsfwVideoServer1: number
58 before(async function () {
61 servers = await flushAndRunMultipleServers(3, { transcoding: { enabled: false } })
63 // Get the access tokens
64 await setAccessTokensToServers(servers)
65 await setDefaultVideoChannel(servers)
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])
73 const serverPromises: Promise<any>[][] = []
75 for (const server of servers) {
76 const videoPromises: Promise<any>[] = []
78 for (let i = 0; i < 7; i++) {
80 uploadVideo(server.url, server.accessToken, { name: `video ${i} server ${server.serverNumber}`, nsfw: false })
81 .then(res => res.body.video)
85 serverPromises.push(videoPromises)
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])
93 nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[ 0 ], videoName: 'NSFW video', nsfw: true })).id
95 await waitJobs(servers)
98 it('Should list watch later playlist', async function () {
99 const url = servers[ 0 ].url
100 const accessToken = servers[ 0 ].accessToken
103 const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.WATCH_LATER)
105 expect(res.body.total).to.equal(1)
106 expect(res.body.data).to.have.lengthOf(1)
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')
115 const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.REGULAR)
117 expect(res.body.total).to.equal(0)
118 expect(res.body.data).to.have.lengthOf(0)
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)
128 it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () {
131 await createVideoPlaylist({
133 token: servers[0].accessToken,
135 displayName: 'my super playlist',
136 privacy: VideoPlaylistPrivacy.PUBLIC,
137 description: 'my super description',
138 thumbnailfile: 'thumbnail.jpg',
139 videoChannelId: servers[0].videoChannel.id
143 await waitJobs(servers)
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)
150 const playlistFromList = res.body.data[0] as VideoPlaylist
152 const res2 = await getVideoPlaylist(server.url, playlistFromList.uuid)
153 const playlistFromGet = res2.body
155 for (const playlist of [ playlistFromGet, playlistFromList ]) {
156 expect(playlist.id).to.be.a('number')
157 expect(playlist.uuid).to.be.a('string')
159 expect(playlist.isLocal).to.equal(server.serverNumber === 1)
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')
168 expect(playlist.videosLength).to.equal(0)
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')
178 it('Should create a playlist on server 2 and have the playlist on server 1 but not on server 3', async function () {
182 const res = await createVideoPlaylist({
184 token: servers[1].accessToken,
186 displayName: 'playlist 2',
187 privacy: VideoPlaylistPrivacy.PUBLIC
190 playlistServer2Id1 = res.body.videoPlaylist.id
194 const res = await createVideoPlaylist({
195 url: servers[ 1 ].url,
196 token: servers[ 1 ].accessToken,
198 displayName: 'playlist 3',
199 privacy: VideoPlaylistPrivacy.PUBLIC,
200 thumbnailfile: 'thumbnail.jpg'
204 playlistServer2Id2 = res.body.videoPlaylist.id
205 playlistServer2UUID2 = res.body.videoPlaylist.uuid
208 for (let id of [ playlistServer2Id1, playlistServer2Id2 ]) {
209 await addVideoInPlaylist({
210 url: servers[ 1 ].url,
211 token: servers[ 1 ].accessToken,
213 elementAttrs: { videoId: servers[ 1 ].videos[ 0 ].id, startTimestamp: 1, stopTimestamp: 2 }
215 await addVideoInPlaylist({
216 url: servers[ 1 ].url,
217 token: servers[ 1 ].accessToken,
219 elementAttrs: { videoId: servers[ 1 ].videos[ 1 ].id }
223 await waitJobs(servers)
225 for (const server of [ servers[0], servers[1] ]) {
226 const res = await getVideoPlaylistsList(server.url, 0, 5)
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)
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)
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
242 it('Should have the playlist on server 3 after a new follow', async function () {
245 // Server 2 and server 3 follow each other
246 await doubleFollow(servers[1], servers[2])
248 const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
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)
254 expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined
257 it('Should correctly list the playlists', async function () {
261 const res = await getVideoPlaylistsList(servers[ 2 ].url, 1, 2, 'createdAt')
263 expect(res.body.total).to.equal(3)
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')
272 const res = await getVideoPlaylistsList(servers[ 2 ].url, 1, 2, '-createdAt')
274 expect(res.body.total).to.equal(3)
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')
283 it('Should list video channel playlists', async function () {
287 const res = await getVideoChannelPlaylistsList(servers[ 0 ].url, 'root_channel', 0, 2, '-createdAt')
289 expect(res.body.total).to.equal(1)
291 const data: VideoPlaylist[] = res.body.data
292 expect(data).to.have.lengthOf(1)
293 expect(data[ 0 ].displayName).to.equal('my super playlist')
297 it('Should list account playlists', async function () {
301 const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 1, 2, '-createdAt')
303 expect(res.body.total).to.equal(2)
305 const data: VideoPlaylist[] = res.body.data
306 expect(data).to.have.lengthOf(1)
307 expect(data[ 0 ].displayName).to.equal('playlist 2')
311 const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 1, 2, 'createdAt')
313 expect(res.body.total).to.equal(2)
315 const data: VideoPlaylist[] = res.body.data
316 expect(data).to.have.lengthOf(1)
317 expect(data[ 0 ].displayName).to.equal('playlist 3')
321 it('Should not list unlisted or private playlists', async function () {
324 await createVideoPlaylist({
325 url: servers[ 1 ].url,
326 token: servers[ 1 ].accessToken,
328 displayName: 'playlist unlisted',
329 privacy: VideoPlaylistPrivacy.UNLISTED
333 await createVideoPlaylist({
334 url: servers[ 1 ].url,
335 token: servers[ 1 ].accessToken,
337 displayName: 'playlist private',
338 privacy: VideoPlaylistPrivacy.PRIVATE
342 await waitJobs(servers)
344 for (const server of servers) {
346 await getAccountPlaylistsList(server.url, 'root@localhost:9002', 0, 5, '-createdAt'),
347 await getVideoPlaylistsList(server.url, 0, 2, '-createdAt')
350 expect(results[0].body.total).to.equal(2)
351 expect(results[1].body.total).to.equal(3)
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')
362 it('Should update a playlist', async function () {
365 await updateVideoPlaylist({
367 token: servers[1].accessToken,
369 displayName: 'playlist 3 updated',
370 description: 'description updated',
371 privacy: VideoPlaylistPrivacy.UNLISTED,
372 thumbnailfile: 'thumbnail.jpg',
373 videoChannelId: servers[1].videoChannel.id
375 playlistId: playlistServer2Id2
378 await waitJobs(servers)
380 for (const server of servers) {
381 const res = await getVideoPlaylist(server.url, playlistServer2UUID2)
382 const playlist: VideoPlaylist = res.body
384 expect(playlist.displayName).to.equal('playlist 3 updated')
385 expect(playlist.description).to.equal('description updated')
387 expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.UNLISTED)
388 expect(playlist.privacy.label).to.equal('Unlisted')
390 expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
391 expect(playlist.type.label).to.equal('Regular')
393 expect(playlist.videosLength).to.equal(2)
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')
402 it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () {
405 const addVideo = (elementAttrs: any) => {
406 return addVideoInPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: playlistServer1Id, elementAttrs })
409 const res = await createVideoPlaylist({
410 url: servers[ 0 ].url,
411 token: servers[ 0 ].accessToken,
413 displayName: 'playlist 4',
414 privacy: VideoPlaylistPrivacy.PUBLIC
418 playlistServer1Id = res.body.videoPlaylist.id
419 playlistServer1UUID = res.body.videoPlaylist.uuid
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 })
428 await waitJobs(servers)
431 it('Should correctly list playlist videos', async function () {
434 for (const server of servers) {
435 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
437 expect(res.body.total).to.equal(6)
439 const videos: Video[] = res.body.data
440 expect(videos).to.have.lengthOf(6)
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)
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
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
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)
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)
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
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
476 const res3 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 2)
477 expect(res3.body.data).to.have.lengthOf(2)
481 it('Should reorder the playlist', async function () {
485 await reorderVideosPlaylist({
486 url: servers[ 0 ].url,
487 token: servers[ 0 ].accessToken,
488 playlistId: playlistServer1Id,
491 insertAfterPosition: 3
495 await waitJobs(servers)
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)
501 expect(names).to.deep.equal([
513 await reorderVideosPlaylist({
515 token: servers[0].accessToken,
516 playlistId: playlistServer1Id,
520 insertAfterPosition: 4
524 await waitJobs(servers)
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)
530 expect(names).to.deep.equal([
542 await reorderVideosPlaylist({
544 token: servers[0].accessToken,
545 playlistId: playlistServer1Id,
548 insertAfterPosition: 3
552 await waitJobs(servers)
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
558 const names = videos.map(v => v.name)
560 expect(names).to.deep.equal([
569 for (let i = 1; i <= videos.length; i++) {
570 expect(videos[i - 1].playlistElement.position).to.equal(i)
576 it('Should update startTimestamp/endTimestamp of some elements', async function () {
579 await updateVideoPlaylistElement({
581 token: servers[0].accessToken,
582 playlistId: playlistServer1Id,
583 videoId: servers[0].videos[3].uuid,
589 await updateVideoPlaylistElement({
591 token: servers[0].accessToken,
592 playlistId: playlistServer1Id,
593 videoId: servers[0].videos[4].uuid,
599 await waitJobs(servers)
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
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)
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
617 it('Should delete some elements', async function () {
620 await removeVideoFromPlaylist({
622 token: servers[0].accessToken,
623 playlistId: playlistServer1Id,
624 videoId: servers[0].videos[3].uuid
627 await removeVideoFromPlaylist({
629 token: servers[0].accessToken,
630 playlistId: playlistServer1Id,
631 videoId: nsfwVideoServer1
634 await waitJobs(servers)
636 for (const server of servers) {
637 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
639 expect(res.body.total).to.equal(4)
641 const videos: Video[] = res.body.data
642 expect(videos).to.have.lengthOf(4)
644 expect(videos[ 0 ].name).to.equal('video 0 server 1')
645 expect(videos[ 0 ].playlistElement.position).to.equal(1)
647 expect(videos[ 1 ].name).to.equal('video 2 server 3')
648 expect(videos[ 1 ].playlistElement.position).to.equal(2)
650 expect(videos[ 2 ].name).to.equal('video 1 server 3')
651 expect(videos[ 2 ].playlistElement.position).to.equal(3)
653 expect(videos[ 3 ].name).to.equal('video 4 server 1')
654 expect(videos[ 3 ].playlistElement.position).to.equal(4)
658 it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () {
661 await deleteVideoPlaylist(servers[0].url, servers[0].accessToken, playlistServer1Id)
663 await waitJobs(servers)
665 for (const server of servers) {
666 await getVideoPlaylist(server.url, playlistServer1UUID, 404)
670 it('Should have deleted the thumbnail on server 1, 2 and 3', async function () {
673 for (const server of servers) {
674 await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.serverNumber)
678 it('Should unfollow servers 1 and 2 and hide their playlists', async function () {
681 const finder = data => data.find(p => p.displayName === 'my super playlist')
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
689 await unfollow(servers[2].url, servers[2].accessToken, servers[0])
692 const res = await getVideoPlaylistsList(servers[ 2 ].url, 0, 5)
693 expect(res.body.total).to.equal(1)
695 expect(finder(res.body.data)).to.be.undefined
699 it('Should delete a channel and put the associated playlist in private mode', async function () {
702 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, { name: 'super_channel', displayName: 'super channel' })
703 const videoChannelId = res.body.videoChannel.id
705 const res2 = await createVideoPlaylist({
707 token: servers[0].accessToken,
709 displayName: 'channel playlist',
710 privacy: VideoPlaylistPrivacy.PUBLIC,
714 const videoPlaylistUUID = res2.body.videoPlaylist.uuid
716 await waitJobs(servers)
718 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'super_channel')
720 await waitJobs(servers)
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)
726 await getVideoPlaylist(servers[1].url, videoPlaylistUUID, 404)
729 it('Should delete an account and delete its playlists', async function () {
732 const user = { username: 'user_1', password: 'password' }
733 const res = await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
735 const userId = res.body.user.id
736 const userAccessToken = await userLogin(servers[0], user)
738 await createVideoPlaylist({
740 token: userAccessToken,
742 displayName: 'playlist to be deleted',
743 privacy: VideoPlaylistPrivacy.PUBLIC
747 await waitJobs(servers)
749 const finder = data => data.find(p => p.displayName === 'playlist to be deleted')
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
758 await removeUser(servers[0].url, userId, servers[0].accessToken)
759 await waitJobs(servers)
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
769 after(async function () {
770 killallServers(servers)
772 // Keep the logs if the test failed