]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-playlists.ts
Translated using Weblate (Hungarian)
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-playlists.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
418d092a
C
2
3import * as chai from 'chai'
4import 'mocha'
418d092a
C
5import {
6 addVideoChannel,
df0b219d 7 addVideoInPlaylist,
bfbd9128 8 addVideoToBlacklist,
8519cc92
C
9 checkPlaylistFilesWereRemoved,
10 cleanupTests,
418d092a 11 createUser,
df0b219d
C
12 createVideoPlaylist,
13 deleteVideoChannel,
14 deleteVideoPlaylist,
8519cc92
C
15 doubleFollow,
16 doVideosExistInMyPlaylist,
418d092a 17 flushAndRunMultipleServers,
bfbd9128
C
18 generateUserAccessToken,
19 getAccessToken,
df0b219d 20 getAccountPlaylistsList,
8519cc92
C
21 getAccountPlaylistsListWithToken,
22 getMyUserInformation,
df0b219d
C
23 getPlaylistVideos,
24 getVideoChannelPlaylistsList,
25 getVideoPlaylist,
d4c9f45b 26 getVideoPlaylistPrivacies,
df0b219d
C
27 getVideoPlaylistsList,
28 getVideoPlaylistWithToken,
df0b219d 29 removeUser,
bfbd9128 30 removeVideoFromBlacklist,
df0b219d
C
31 removeVideoFromPlaylist,
32 reorderVideosPlaylist,
418d092a
C
33 ServerInfo,
34 setAccessTokensToServers,
df0b219d 35 setDefaultVideoChannel,
418d092a 36 testImage,
df0b219d 37 unfollow,
bfbd9128 38 updateVideo,
df0b219d
C
39 updateVideoPlaylist,
40 updateVideoPlaylistElement,
418d092a 41 uploadVideo,
df0b219d 42 uploadVideoAndGetId,
418d092a 43 userLogin,
bfbd9128 44 waitJobs
94565d52 45} from '../../../../shared/extra-utils'
df0b219d
C
46import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
47import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model'
bfbd9128 48import { VideoPrivacy } from '../../../../shared/models/videos'
df0b219d 49import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
0b16f5f2 50import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
397d78fb 51import { User } from '../../../../shared/models/users'
bfbd9128
C
52import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../../shared/models/videos/playlist/video-playlist-element.model'
53import {
54 addAccountToAccountBlocklist,
55 addAccountToServerBlocklist,
56 addServerToAccountBlocklist,
57 addServerToServerBlocklist,
58 removeAccountFromAccountBlocklist,
59 removeAccountFromServerBlocklist,
60 removeServerFromAccountBlocklist,
61 removeServerFromServerBlocklist
62} from '../../../../shared/extra-utils/users/blocklist'
418d092a
C
63
64const expect = chai.expect
65
bfbd9128
C
66async function checkPlaylistElementType (
67 servers: ServerInfo[],
68 playlistId: string,
69 type: VideoPlaylistElementType,
70 position: number,
71 name: string,
72 total: number
73) {
74 for (const server of servers) {
75 const res = await getPlaylistVideos(server.url, server.accessToken, playlistId, 0, 10)
76 expect(res.body.total).to.equal(total)
77
78 const videoElement: VideoPlaylistElement = res.body.data.find((e: VideoPlaylistElement) => e.position === position)
79 expect(videoElement.type).to.equal(type, 'On server ' + server.url)
80
81 if (type === VideoPlaylistElementType.REGULAR) {
82 expect(videoElement.video).to.not.be.null
83 expect(videoElement.video.name).to.equal(name)
84 } else {
85 expect(videoElement.video).to.be.null
86 }
87 }
88}
89
418d092a
C
90describe('Test video playlists', function () {
91 let servers: ServerInfo[] = []
92
df0b219d
C
93 let playlistServer2Id1: number
94 let playlistServer2Id2: number
95 let playlistServer2UUID2: number
96
97 let playlistServer1Id: number
98 let playlistServer1UUID: string
bfbd9128
C
99 let playlistServer1UUID2: string
100
101 let playlistElementServer1Video4: number
102 let playlistElementServer1Video5: number
103 let playlistElementNSFW: number
df0b219d
C
104
105 let nsfwVideoServer1: number
106
bfbd9128
C
107 let userAccessTokenServer1: string
108
418d092a
C
109 before(async function () {
110 this.timeout(120000)
111
df0b219d 112 servers = await flushAndRunMultipleServers(3, { transcoding: { enabled: false } })
418d092a
C
113
114 // Get the access tokens
115 await setAccessTokensToServers(servers)
df0b219d 116 await setDefaultVideoChannel(servers)
418d092a
C
117
118 // Server 1 and server 2 follow each other
119 await doubleFollow(servers[0], servers[1])
120 // Server 1 and server 3 follow each other
121 await doubleFollow(servers[0], servers[2])
df0b219d
C
122
123 {
124 const serverPromises: Promise<any>[][] = []
125
126 for (const server of servers) {
127 const videoPromises: Promise<any>[] = []
128
129 for (let i = 0; i < 7; i++) {
130 videoPromises.push(
131 uploadVideo(server.url, server.accessToken, { name: `video ${i} server ${server.serverNumber}`, nsfw: false })
132 .then(res => res.body.video)
133 )
134 }
135
136 serverPromises.push(videoPromises)
137 }
138
139 servers[0].videos = await Promise.all(serverPromises[0])
140 servers[1].videos = await Promise.all(serverPromises[1])
141 servers[2].videos = await Promise.all(serverPromises[2])
142 }
143
a1587156 144 nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id
df0b219d 145
bfbd9128
C
146 {
147 await createUser({
a1587156
C
148 url: servers[0].url,
149 accessToken: servers[0].accessToken,
bfbd9128
C
150 username: 'user1',
151 password: 'password'
152 })
153 userAccessTokenServer1 = await getAccessToken(servers[0].url, 'user1', 'password')
154 }
155
df0b219d 156 await waitJobs(servers)
418d092a
C
157 })
158
bfbd9128
C
159 describe('Get default playlists', function () {
160 it('Should list video playlist privacies', async function () {
a1587156 161 const res = await getVideoPlaylistPrivacies(servers[0].url)
d4c9f45b 162
bfbd9128
C
163 const privacies = res.body
164 expect(Object.keys(privacies)).to.have.length.at.least(3)
d4c9f45b 165
a1587156 166 expect(privacies[3]).to.equal('Private')
bfbd9128 167 })
d4c9f45b 168
bfbd9128 169 it('Should list watch later playlist', async function () {
a1587156
C
170 const url = servers[0].url
171 const accessToken = servers[0].accessToken
df0b219d 172
bfbd9128
C
173 {
174 const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.WATCH_LATER)
175
176 expect(res.body.total).to.equal(1)
177 expect(res.body.data).to.have.lengthOf(1)
178
a1587156 179 const playlist: VideoPlaylist = res.body.data[0]
bfbd9128
C
180 expect(playlist.displayName).to.equal('Watch later')
181 expect(playlist.type.id).to.equal(VideoPlaylistType.WATCH_LATER)
182 expect(playlist.type.label).to.equal('Watch later')
183 }
184
185 {
186 const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.REGULAR)
187
188 expect(res.body.total).to.equal(0)
189 expect(res.body.data).to.have.lengthOf(0)
190 }
191
192 {
193 const res = await getAccountPlaylistsList(url, 'root', 0, 5)
194 expect(res.body.total).to.equal(0)
195 expect(res.body.data).to.have.lengthOf(0)
196 }
197 })
198
199 it('Should get private playlist for a classic user', async function () {
a1587156 200 const token = await generateUserAccessToken(servers[0], 'toto')
bfbd9128 201
a1587156 202 const res = await getAccountPlaylistsListWithToken(servers[0].url, token, 'toto', 0, 5)
df0b219d
C
203
204 expect(res.body.total).to.equal(1)
205 expect(res.body.data).to.have.lengthOf(1)
418d092a 206
a1587156
C
207 const playlistId = res.body.data[0].id
208 await getPlaylistVideos(servers[0].url, token, playlistId, 0, 5)
bfbd9128
C
209 })
210 })
df0b219d 211
bfbd9128 212 describe('Create and federate playlists', function () {
df0b219d 213
bfbd9128
C
214 it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () {
215 this.timeout(30000)
df0b219d 216
bfbd9128 217 await createVideoPlaylist({
a1587156
C
218 url: servers[0].url,
219 token: servers[0].accessToken,
bfbd9128
C
220 playlistAttrs: {
221 displayName: 'my super playlist',
222 privacy: VideoPlaylistPrivacy.PUBLIC,
223 description: 'my super description',
224 thumbnailfile: 'thumbnail.jpg',
a1587156 225 videoChannelId: servers[0].videoChannel.id
bfbd9128
C
226 }
227 })
228
229 await waitJobs(servers)
230
231 for (const server of servers) {
232 const res = await getVideoPlaylistsList(server.url, 0, 5)
233 expect(res.body.total).to.equal(1)
234 expect(res.body.data).to.have.lengthOf(1)
235
a1587156 236 const playlistFromList = res.body.data[0] as VideoPlaylist
bfbd9128
C
237
238 const res2 = await getVideoPlaylist(server.url, playlistFromList.uuid)
951b582f 239 const playlistFromGet = res2.body as VideoPlaylist
bfbd9128
C
240
241 for (const playlist of [ playlistFromGet, playlistFromList ]) {
242 expect(playlist.id).to.be.a('number')
243 expect(playlist.uuid).to.be.a('string')
244
245 expect(playlist.isLocal).to.equal(server.serverNumber === 1)
246
247 expect(playlist.displayName).to.equal('my super playlist')
248 expect(playlist.description).to.equal('my super description')
249 expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
250 expect(playlist.privacy.label).to.equal('Public')
251 expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
252 expect(playlist.type.label).to.equal('Regular')
951b582f 253 expect(playlist.embedPath).to.equal('/video-playlists/embed/' + playlist.uuid)
bfbd9128
C
254
255 expect(playlist.videosLength).to.equal(0)
df0b219d 256
bfbd9128
C
257 expect(playlist.ownerAccount.name).to.equal('root')
258 expect(playlist.ownerAccount.displayName).to.equal('root')
259 expect(playlist.videoChannel.name).to.equal('root_channel')
260 expect(playlist.videoChannel.displayName).to.equal('Main root channel')
261 }
262 }
263 })
4d09cfba 264
bfbd9128
C
265 it('Should create a playlist on server 2 and have the playlist on server 1 but not on server 3', async function () {
266 this.timeout(30000)
267
268 {
269 const res = await createVideoPlaylist({
a1587156
C
270 url: servers[1].url,
271 token: servers[1].accessToken,
bfbd9128
C
272 playlistAttrs: {
273 displayName: 'playlist 2',
274 privacy: VideoPlaylistPrivacy.PUBLIC,
a1587156 275 videoChannelId: servers[1].videoChannel.id
bfbd9128
C
276 }
277 })
278 playlistServer2Id1 = res.body.videoPlaylist.id
279 }
4d09cfba 280
bfbd9128
C
281 {
282 const res = await createVideoPlaylist({
a1587156
C
283 url: servers[1].url,
284 token: servers[1].accessToken,
bfbd9128
C
285 playlistAttrs: {
286 displayName: 'playlist 3',
287 privacy: VideoPlaylistPrivacy.PUBLIC,
288 thumbnailfile: 'thumbnail.jpg',
a1587156 289 videoChannelId: servers[1].videoChannel.id
bfbd9128
C
290 }
291 })
292
293 playlistServer2Id2 = res.body.videoPlaylist.id
294 playlistServer2UUID2 = res.body.videoPlaylist.uuid
295 }
296
a1587156 297 for (const id of [ playlistServer2Id1, playlistServer2Id2 ]) {
bfbd9128 298 await addVideoInPlaylist({
a1587156
C
299 url: servers[1].url,
300 token: servers[1].accessToken,
bfbd9128 301 playlistId: id,
a1587156 302 elementAttrs: { videoId: servers[1].videos[0].id, startTimestamp: 1, stopTimestamp: 2 }
bfbd9128
C
303 })
304 await addVideoInPlaylist({
a1587156
C
305 url: servers[1].url,
306 token: servers[1].accessToken,
bfbd9128 307 playlistId: id,
a1587156 308 elementAttrs: { videoId: servers[1].videos[1].id }
bfbd9128
C
309 })
310 }
311
312 await waitJobs(servers)
313
a1587156 314 for (const server of [ servers[0], servers[1] ]) {
bfbd9128
C
315 const res = await getVideoPlaylistsList(server.url, 0, 5)
316
317 const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2')
318 expect(playlist2).to.not.be.undefined
319 await testImage(server.url, 'thumbnail-playlist', playlist2.thumbnailPath)
320
321 const playlist3 = res.body.data.find(p => p.displayName === 'playlist 3')
322 expect(playlist3).to.not.be.undefined
323 await testImage(server.url, 'thumbnail', playlist3.thumbnailPath)
324 }
4d09cfba 325
a1587156 326 const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
bfbd9128
C
327 expect(res.body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined
328 expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined
329 })
330
331 it('Should have the playlist on server 3 after a new follow', async function () {
332 this.timeout(30000)
333
334 // Server 2 and server 3 follow each other
a1587156 335 await doubleFollow(servers[1], servers[2])
bfbd9128 336
a1587156 337 const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
bfbd9128
C
338
339 const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2')
340 expect(playlist2).to.not.be.undefined
a1587156 341 await testImage(servers[2].url, 'thumbnail-playlist', playlist2.thumbnailPath)
bfbd9128
C
342
343 expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined
344 })
4d09cfba
C
345 })
346
bfbd9128 347 describe('List playlists', function () {
65af03a2 348
bfbd9128
C
349 it('Should correctly list the playlists', async function () {
350 this.timeout(30000)
351
352 {
a1587156 353 const res = await getVideoPlaylistsList(servers[2].url, 1, 2, 'createdAt')
df0b219d 354
bfbd9128
C
355 expect(res.body.total).to.equal(3)
356
357 const data: VideoPlaylist[] = res.body.data
358 expect(data).to.have.lengthOf(2)
a1587156
C
359 expect(data[0].displayName).to.equal('playlist 2')
360 expect(data[1].displayName).to.equal('playlist 3')
bfbd9128
C
361 }
362
363 {
a1587156 364 const res = await getVideoPlaylistsList(servers[2].url, 1, 2, '-createdAt')
bfbd9128
C
365
366 expect(res.body.total).to.equal(3)
367
368 const data: VideoPlaylist[] = res.body.data
369 expect(data).to.have.lengthOf(2)
a1587156
C
370 expect(data[0].displayName).to.equal('playlist 2')
371 expect(data[1].displayName).to.equal('my super playlist')
df0b219d
C
372 }
373 })
374
bfbd9128
C
375 it('Should list video channel playlists', async function () {
376 this.timeout(30000)
df0b219d 377
bfbd9128 378 {
a1587156 379 const res = await getVideoChannelPlaylistsList(servers[0].url, 'root_channel', 0, 2, '-createdAt')
df0b219d 380
bfbd9128 381 expect(res.body.total).to.equal(1)
df0b219d 382
bfbd9128
C
383 const data: VideoPlaylist[] = res.body.data
384 expect(data).to.have.lengthOf(1)
a1587156 385 expect(data[0].displayName).to.equal('my super playlist')
bfbd9128
C
386 }
387 })
df0b219d 388
bfbd9128
C
389 it('Should list account playlists', async function () {
390 this.timeout(30000)
df0b219d 391
bfbd9128 392 {
a1587156 393 const res = await getAccountPlaylistsList(servers[1].url, 'root', 1, 2, '-createdAt')
df0b219d 394
bfbd9128
C
395 expect(res.body.total).to.equal(2)
396
397 const data: VideoPlaylist[] = res.body.data
398 expect(data).to.have.lengthOf(1)
a1587156 399 expect(data[0].displayName).to.equal('playlist 2')
bfbd9128 400 }
df0b219d 401
bfbd9128 402 {
a1587156 403 const res = await getAccountPlaylistsList(servers[1].url, 'root', 1, 2, 'createdAt')
df0b219d 404
bfbd9128
C
405 expect(res.body.total).to.equal(2)
406
407 const data: VideoPlaylist[] = res.body.data
408 expect(data).to.have.lengthOf(1)
a1587156 409 expect(data[0].displayName).to.equal('playlist 3')
df0b219d 410 }
822c7e61
C
411
412 {
a1587156 413 const res = await getAccountPlaylistsList(servers[1].url, 'root', 0, 10, 'createdAt', '3')
822c7e61
C
414
415 expect(res.body.total).to.equal(1)
416
417 const data: VideoPlaylist[] = res.body.data
418 expect(data).to.have.lengthOf(1)
a1587156 419 expect(data[0].displayName).to.equal('playlist 3')
822c7e61
C
420 }
421
422 {
a1587156 423 const res = await getAccountPlaylistsList(servers[1].url, 'root', 0, 10, 'createdAt', '4')
822c7e61
C
424
425 expect(res.body.total).to.equal(0)
426
427 const data: VideoPlaylist[] = res.body.data
428 expect(data).to.have.lengthOf(0)
429 }
bfbd9128 430 })
418d092a 431
bfbd9128
C
432 it('Should not list unlisted or private playlists', async function () {
433 this.timeout(30000)
df0b219d 434
bfbd9128 435 await createVideoPlaylist({
a1587156
C
436 url: servers[1].url,
437 token: servers[1].accessToken,
df0b219d 438 playlistAttrs: {
bfbd9128
C
439 displayName: 'playlist unlisted',
440 privacy: VideoPlaylistPrivacy.UNLISTED
df0b219d
C
441 }
442 })
df0b219d 443
bfbd9128 444 await createVideoPlaylist({
a1587156
C
445 url: servers[1].url,
446 token: servers[1].accessToken,
df0b219d 447 playlistAttrs: {
bfbd9128
C
448 displayName: 'playlist private',
449 privacy: VideoPlaylistPrivacy.PRIVATE
df0b219d
C
450 }
451 })
452
bfbd9128 453 await waitJobs(servers)
df0b219d 454
bfbd9128
C
455 for (const server of servers) {
456 const results = [
a1587156 457 await getAccountPlaylistsList(server.url, 'root@localhost:' + servers[1].port, 0, 5, '-createdAt'),
bfbd9128
C
458 await getVideoPlaylistsList(server.url, 0, 2, '-createdAt')
459 ]
460
a1587156
C
461 expect(results[0].body.total).to.equal(2)
462 expect(results[1].body.total).to.equal(3)
bfbd9128
C
463
464 for (const res of results) {
465 const data: VideoPlaylist[] = res.body.data
466 expect(data).to.have.lengthOf(2)
a1587156
C
467 expect(data[0].displayName).to.equal('playlist 3')
468 expect(data[1].displayName).to.equal('playlist 2')
bfbd9128
C
469 }
470 }
471 })
472 })
df0b219d 473
bfbd9128 474 describe('Update playlists', function () {
df0b219d 475
bfbd9128
C
476 it('Should update a playlist', async function () {
477 this.timeout(30000)
df0b219d 478
bfbd9128
C
479 await updateVideoPlaylist({
480 url: servers[1].url,
481 token: servers[1].accessToken,
482 playlistAttrs: {
483 displayName: 'playlist 3 updated',
484 description: 'description updated',
485 privacy: VideoPlaylistPrivacy.UNLISTED,
486 thumbnailfile: 'thumbnail.jpg',
487 videoChannelId: servers[1].videoChannel.id
488 },
489 playlistId: playlistServer2Id2
490 })
df0b219d 491
bfbd9128 492 await waitJobs(servers)
df0b219d 493
bfbd9128
C
494 for (const server of servers) {
495 const res = await getVideoPlaylist(server.url, playlistServer2UUID2)
496 const playlist: VideoPlaylist = res.body
418d092a 497
bfbd9128
C
498 expect(playlist.displayName).to.equal('playlist 3 updated')
499 expect(playlist.description).to.equal('description updated')
df0b219d 500
bfbd9128
C
501 expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.UNLISTED)
502 expect(playlist.privacy.label).to.equal('Unlisted')
df0b219d 503
bfbd9128
C
504 expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
505 expect(playlist.type.label).to.equal('Regular')
df0b219d 506
bfbd9128 507 expect(playlist.videosLength).to.equal(2)
df0b219d 508
bfbd9128
C
509 expect(playlist.ownerAccount.name).to.equal('root')
510 expect(playlist.ownerAccount.displayName).to.equal('root')
511 expect(playlist.videoChannel.name).to.equal('root_channel')
512 expect(playlist.videoChannel.displayName).to.equal('Main root channel')
513 }
514 })
418d092a
C
515 })
516
bfbd9128 517 describe('Element timestamps', function () {
df0b219d 518
bfbd9128
C
519 it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () {
520 this.timeout(30000)
df0b219d 521
bfbd9128 522 const addVideo = (elementAttrs: any) => {
a1587156 523 return addVideoInPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: playlistServer1Id, elementAttrs })
bfbd9128 524 }
df0b219d 525
bfbd9128 526 const res = await createVideoPlaylist({
a1587156
C
527 url: servers[0].url,
528 token: servers[0].accessToken,
bfbd9128
C
529 playlistAttrs: {
530 displayName: 'playlist 4',
531 privacy: VideoPlaylistPrivacy.PUBLIC,
a1587156 532 videoChannelId: servers[0].videoChannel.id
bfbd9128
C
533 }
534 })
df0b219d 535
bfbd9128
C
536 playlistServer1Id = res.body.videoPlaylist.id
537 playlistServer1UUID = res.body.videoPlaylist.uuid
df0b219d 538
a1587156
C
539 await addVideo({ videoId: servers[0].videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 })
540 await addVideo({ videoId: servers[2].videos[1].uuid, startTimestamp: 35 })
541 await addVideo({ videoId: servers[2].videos[2].uuid })
bfbd9128 542 {
a1587156 543 const res = await addVideo({ videoId: servers[0].videos[3].uuid, stopTimestamp: 35 })
bfbd9128
C
544 playlistElementServer1Video4 = res.body.videoPlaylistElement.id
545 }
df0b219d 546
bfbd9128 547 {
a1587156 548 const res = await addVideo({ videoId: servers[0].videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 })
bfbd9128
C
549 playlistElementServer1Video5 = res.body.videoPlaylistElement.id
550 }
418d092a 551
bfbd9128
C
552 {
553 const res = await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 })
554 playlistElementNSFW = res.body.videoPlaylistElement.id
37190663
C
555
556 await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 4 })
557 await addVideo({ videoId: nsfwVideoServer1 })
bfbd9128 558 }
df0b219d 559
bfbd9128
C
560 await waitJobs(servers)
561 })
df0b219d 562
bfbd9128
C
563 it('Should correctly list playlist videos', async function () {
564 this.timeout(30000)
df0b219d 565
bfbd9128
C
566 for (const server of servers) {
567 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
418d092a 568
37190663 569 expect(res.body.total).to.equal(8)
df0b219d 570
bfbd9128 571 const videoElements: VideoPlaylistElement[] = res.body.data
37190663 572 expect(videoElements).to.have.lengthOf(8)
df0b219d 573
a1587156
C
574 expect(videoElements[0].video.name).to.equal('video 0 server 1')
575 expect(videoElements[0].position).to.equal(1)
576 expect(videoElements[0].startTimestamp).to.equal(15)
577 expect(videoElements[0].stopTimestamp).to.equal(28)
df0b219d 578
a1587156
C
579 expect(videoElements[1].video.name).to.equal('video 1 server 3')
580 expect(videoElements[1].position).to.equal(2)
581 expect(videoElements[1].startTimestamp).to.equal(35)
582 expect(videoElements[1].stopTimestamp).to.be.null
df0b219d 583
a1587156
C
584 expect(videoElements[2].video.name).to.equal('video 2 server 3')
585 expect(videoElements[2].position).to.equal(3)
586 expect(videoElements[2].startTimestamp).to.be.null
587 expect(videoElements[2].stopTimestamp).to.be.null
df0b219d 588
a1587156
C
589 expect(videoElements[3].video.name).to.equal('video 3 server 1')
590 expect(videoElements[3].position).to.equal(4)
591 expect(videoElements[3].startTimestamp).to.be.null
592 expect(videoElements[3].stopTimestamp).to.equal(35)
df0b219d 593
a1587156
C
594 expect(videoElements[4].video.name).to.equal('video 4 server 1')
595 expect(videoElements[4].position).to.equal(5)
596 expect(videoElements[4].startTimestamp).to.equal(45)
597 expect(videoElements[4].stopTimestamp).to.equal(60)
418d092a 598
a1587156
C
599 expect(videoElements[5].video.name).to.equal('NSFW video')
600 expect(videoElements[5].position).to.equal(6)
601 expect(videoElements[5].startTimestamp).to.equal(5)
602 expect(videoElements[5].stopTimestamp).to.be.null
df0b219d 603
37190663
C
604 expect(videoElements[6].video.name).to.equal('NSFW video')
605 expect(videoElements[6].position).to.equal(7)
606 expect(videoElements[6].startTimestamp).to.equal(4)
607 expect(videoElements[6].stopTimestamp).to.be.null
608
609 expect(videoElements[7].video.name).to.equal('NSFW video')
610 expect(videoElements[7].position).to.equal(8)
611 expect(videoElements[7].startTimestamp).to.be.null
612 expect(videoElements[7].stopTimestamp).to.be.null
613
bfbd9128
C
614 const res3 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 2)
615 expect(res3.body.data).to.have.lengthOf(2)
df0b219d
C
616 }
617 })
bfbd9128 618 })
df0b219d 619
bfbd9128
C
620 describe('Element type', function () {
621 let groupUser1: ServerInfo[]
622 let groupWithoutToken1: ServerInfo[]
623 let group1: ServerInfo[]
624 let group2: ServerInfo[]
df0b219d 625
bfbd9128
C
626 let video1: string
627 let video2: string
628 let video3: string
df0b219d 629
bfbd9128
C
630 before(async function () {
631 this.timeout(30000)
df0b219d 632
a1587156
C
633 groupUser1 = [ Object.assign({}, servers[0], { accessToken: userAccessTokenServer1 }) ]
634 groupWithoutToken1 = [ Object.assign({}, servers[0], { accessToken: undefined }) ]
635 group1 = [ servers[0] ]
636 group2 = [ servers[1], servers[2] ]
df0b219d 637
bfbd9128 638 const res = await createVideoPlaylist({
a1587156 639 url: servers[0].url,
bfbd9128
C
640 token: userAccessTokenServer1,
641 playlistAttrs: {
642 displayName: 'playlist 56',
643 privacy: VideoPlaylistPrivacy.PUBLIC,
a1587156 644 videoChannelId: servers[0].videoChannel.id
bfbd9128
C
645 }
646 })
418d092a 647
bfbd9128
C
648 const playlistServer1Id2 = res.body.videoPlaylist.id
649 playlistServer1UUID2 = res.body.videoPlaylist.uuid
df0b219d 650
bfbd9128 651 const addVideo = (elementAttrs: any) => {
a1587156 652 return addVideoInPlaylist({ url: servers[0].url, token: userAccessTokenServer1, playlistId: playlistServer1Id2, elementAttrs })
bfbd9128 653 }
df0b219d 654
bfbd9128
C
655 video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userAccessTokenServer1 })).uuid
656 video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid
657 video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid
df0b219d 658
bfbd9128
C
659 await addVideo({ videoId: video1, startTimestamp: 15, stopTimestamp: 28 })
660 await addVideo({ videoId: video2, startTimestamp: 35 })
661 await addVideo({ videoId: video3 })
df0b219d 662
bfbd9128
C
663 await waitJobs(servers)
664 })
df0b219d 665
bfbd9128
C
666 it('Should update the element type if the video is private', async function () {
667 this.timeout(20000)
df0b219d 668
bfbd9128
C
669 const name = 'video 89'
670 const position = 1
df0b219d 671
bfbd9128 672 {
a1587156 673 await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PRIVATE })
bfbd9128 674 await waitJobs(servers)
418d092a 675
bfbd9128
C
676 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
677 await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.PRIVATE, position, name, 3)
678 await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.PRIVATE, position, name, 3)
679 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
680 }
df0b219d 681
bfbd9128 682 {
a1587156 683 await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PUBLIC })
bfbd9128 684 await waitJobs(servers)
418d092a 685
bfbd9128
C
686 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
687 await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
688 await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
689 // We deleted the video, so even if we recreated it, the old entry is still deleted
690 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
df0b219d
C
691 }
692 })
693
bfbd9128
C
694 it('Should update the element type if the video is blacklisted', async function () {
695 this.timeout(20000)
df0b219d 696
bfbd9128
C
697 const name = 'video 89'
698 const position = 1
df0b219d 699
bfbd9128 700 {
a1587156 701 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video1, 'reason', true)
bfbd9128 702 await waitJobs(servers)
418d092a 703
bfbd9128
C
704 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
705 await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
706 await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
707 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
708 }
df0b219d 709
bfbd9128 710 {
a1587156 711 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video1)
bfbd9128 712 await waitJobs(servers)
df0b219d 713
bfbd9128
C
714 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
715 await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
716 await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
717 // We deleted the video (because unfederated), so even if we recreated it, the old entry is still deleted
718 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
719 }
720 })
df0b219d 721
bfbd9128
C
722 it('Should update the element type if the account or server of the video is blocked', async function () {
723 this.timeout(90000)
df0b219d 724
bfbd9128
C
725 const name = 'video 90'
726 const position = 2
df0b219d 727
bfbd9128 728 {
a1587156 729 await addAccountToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port)
bfbd9128 730 await waitJobs(servers)
df0b219d 731
bfbd9128
C
732 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
733 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
df0b219d 734
a1587156 735 await removeAccountFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port)
bfbd9128 736 await waitJobs(servers)
df0b219d 737
bfbd9128
C
738 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
739 }
df0b219d 740
bfbd9128 741 {
a1587156 742 await addServerToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port)
bfbd9128 743 await waitJobs(servers)
df0b219d 744
bfbd9128
C
745 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
746 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
df0b219d 747
a1587156 748 await removeServerFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port)
bfbd9128 749 await waitJobs(servers)
418d092a 750
bfbd9128
C
751 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
752 }
df0b219d 753
bfbd9128 754 {
a1587156 755 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)
bfbd9128 756 await waitJobs(servers)
df0b219d 757
bfbd9128
C
758 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
759 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
df0b219d 760
a1587156 761 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)
bfbd9128 762 await waitJobs(servers)
df0b219d 763
bfbd9128 764 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
df0b219d 765 }
df0b219d 766
bfbd9128 767 {
a1587156 768 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
bfbd9128 769 await waitJobs(servers)
df0b219d 770
bfbd9128
C
771 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
772 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
df0b219d 773
a1587156 774 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
bfbd9128 775 await waitJobs(servers)
df0b219d 776
bfbd9128 777 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
df0b219d 778 }
bfbd9128 779 })
df0b219d 780
bfbd9128
C
781 it('Should hide the video if it is NSFW', async function () {
782 const res = await getPlaylistVideos(servers[0].url, userAccessTokenServer1, playlistServer1UUID2, 0, 10, { nsfw: false })
783 expect(res.body.total).to.equal(3)
df0b219d 784
bfbd9128
C
785 const elements: VideoPlaylistElement[] = res.body.data
786 const element = elements.find(e => e.position === 3)
df0b219d 787
bfbd9128
C
788 expect(element).to.exist
789 expect(element.video).to.be.null
790 expect(element.type).to.equal(VideoPlaylistElementType.UNAVAILABLE)
791 })
df0b219d 792
bfbd9128 793 })
df0b219d 794
bfbd9128
C
795 describe('Managing playlist elements', function () {
796
797 it('Should reorder the playlist', async function () {
798 this.timeout(30000)
799
800 {
801 await reorderVideosPlaylist({
a1587156
C
802 url: servers[0].url,
803 token: servers[0].accessToken,
bfbd9128
C
804 playlistId: playlistServer1Id,
805 elementAttrs: {
806 startPosition: 2,
807 insertAfterPosition: 3
808 }
809 })
810
811 await waitJobs(servers)
812
813 for (const server of servers) {
814 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
815 const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name)
816
817 expect(names).to.deep.equal([
818 'video 0 server 1',
819 'video 2 server 3',
820 'video 1 server 3',
821 'video 3 server 1',
822 'video 4 server 1',
37190663
C
823 'NSFW video',
824 'NSFW video',
bfbd9128
C
825 'NSFW video'
826 ])
df0b219d
C
827 }
828 }
df0b219d 829
bfbd9128
C
830 {
831 await reorderVideosPlaylist({
a1587156
C
832 url: servers[0].url,
833 token: servers[0].accessToken,
bfbd9128
C
834 playlistId: playlistServer1Id,
835 elementAttrs: {
836 startPosition: 1,
837 reorderLength: 3,
838 insertAfterPosition: 4
839 }
840 })
841
842 await waitJobs(servers)
843
844 for (const server of servers) {
845 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
846 const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name)
847
848 expect(names).to.deep.equal([
849 'video 3 server 1',
850 'video 0 server 1',
851 'video 2 server 3',
852 'video 1 server 3',
853 'video 4 server 1',
37190663
C
854 'NSFW video',
855 'NSFW video',
bfbd9128
C
856 'NSFW video'
857 ])
858 }
df0b219d 859 }
df0b219d 860
bfbd9128
C
861 {
862 await reorderVideosPlaylist({
a1587156
C
863 url: servers[0].url,
864 token: servers[0].accessToken,
bfbd9128
C
865 playlistId: playlistServer1Id,
866 elementAttrs: {
867 startPosition: 6,
868 insertAfterPosition: 3
869 }
870 })
871
872 await waitJobs(servers)
873
874 for (const server of servers) {
875 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
876 const elements: VideoPlaylistElement[] = res.body.data
877 const names = elements.map(v => v.video.name)
878
879 expect(names).to.deep.equal([
880 'video 3 server 1',
881 'video 0 server 1',
882 'video 2 server 3',
883 'NSFW video',
884 'video 1 server 3',
37190663
C
885 'video 4 server 1',
886 'NSFW video',
887 'NSFW video'
bfbd9128
C
888 ])
889
890 for (let i = 1; i <= elements.length; i++) {
a1587156 891 expect(elements[i - 1].position).to.equal(i)
bfbd9128
C
892 }
893 }
df0b219d
C
894 }
895 })
896
bfbd9128
C
897 it('Should update startTimestamp/endTimestamp of some elements', async function () {
898 this.timeout(30000)
899
900 await updateVideoPlaylistElement({
a1587156
C
901 url: servers[0].url,
902 token: servers[0].accessToken,
bfbd9128
C
903 playlistId: playlistServer1Id,
904 playlistElementId: playlistElementServer1Video4,
905 elementAttrs: {
906 startTimestamp: 1
907 }
908 })
df0b219d 909
bfbd9128 910 await updateVideoPlaylistElement({
a1587156
C
911 url: servers[0].url,
912 token: servers[0].accessToken,
bfbd9128
C
913 playlistId: playlistServer1Id,
914 playlistElementId: playlistElementServer1Video5,
915 elementAttrs: {
916 stopTimestamp: null
917 }
918 })
df0b219d 919
bfbd9128 920 await waitJobs(servers)
df0b219d 921
bfbd9128
C
922 for (const server of servers) {
923 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
924 const elements: VideoPlaylistElement[] = res.body.data
418d092a 925
a1587156
C
926 expect(elements[0].video.name).to.equal('video 3 server 1')
927 expect(elements[0].position).to.equal(1)
928 expect(elements[0].startTimestamp).to.equal(1)
929 expect(elements[0].stopTimestamp).to.equal(35)
0b16f5f2 930
a1587156
C
931 expect(elements[5].video.name).to.equal('video 4 server 1')
932 expect(elements[5].position).to.equal(6)
933 expect(elements[5].startTimestamp).to.equal(45)
934 expect(elements[5].stopTimestamp).to.be.null
bfbd9128
C
935 }
936 })
0b16f5f2 937
bfbd9128
C
938 it('Should check videos existence in my playlist', async function () {
939 const videoIds = [
a1587156 940 servers[0].videos[0].id,
bfbd9128 941 42000,
a1587156 942 servers[0].videos[3].id,
bfbd9128 943 43000,
a1587156 944 servers[0].videos[4].id
bfbd9128 945 ]
a1587156 946 const res = await doVideosExistInMyPlaylist(servers[0].url, servers[0].accessToken, videoIds)
bfbd9128
C
947 const obj = res.body as VideoExistInPlaylist
948
949 {
a1587156 950 const elem = obj[servers[0].videos[0].id]
bfbd9128 951 expect(elem).to.have.lengthOf(1)
a1587156
C
952 expect(elem[0].playlistElementId).to.exist
953 expect(elem[0].playlistId).to.equal(playlistServer1Id)
954 expect(elem[0].startTimestamp).to.equal(15)
955 expect(elem[0].stopTimestamp).to.equal(28)
bfbd9128 956 }
0b16f5f2 957
bfbd9128 958 {
a1587156 959 const elem = obj[servers[0].videos[3].id]
bfbd9128 960 expect(elem).to.have.lengthOf(1)
a1587156
C
961 expect(elem[0].playlistElementId).to.equal(playlistElementServer1Video4)
962 expect(elem[0].playlistId).to.equal(playlistServer1Id)
963 expect(elem[0].startTimestamp).to.equal(1)
964 expect(elem[0].stopTimestamp).to.equal(35)
bfbd9128 965 }
0b16f5f2 966
bfbd9128 967 {
a1587156 968 const elem = obj[servers[0].videos[4].id]
bfbd9128 969 expect(elem).to.have.lengthOf(1)
a1587156
C
970 expect(elem[0].playlistId).to.equal(playlistServer1Id)
971 expect(elem[0].startTimestamp).to.equal(45)
972 expect(elem[0].stopTimestamp).to.equal(null)
bfbd9128 973 }
0b16f5f2 974
a1587156
C
975 expect(obj[42000]).to.have.lengthOf(0)
976 expect(obj[43000]).to.have.lengthOf(0)
bfbd9128 977 })
2a10aab3 978
bfbd9128 979 it('Should automatically update updatedAt field of playlists', async function () {
a1587156
C
980 const server = servers[1]
981 const videoId = servers[1].videos[5].id
2a10aab3 982
bfbd9128
C
983 async function getPlaylistNames () {
984 const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, undefined, '-updatedAt')
2a10aab3 985
bfbd9128
C
986 return (res.body.data as VideoPlaylist[]).map(p => p.displayName)
987 }
2a10aab3 988
bfbd9128
C
989 const elementAttrs = { videoId }
990 const res1 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, elementAttrs })
991 const res2 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, elementAttrs })
2a10aab3 992
bfbd9128
C
993 const element1 = res1.body.videoPlaylistElement.id
994 const element2 = res2.body.videoPlaylistElement.id
2a10aab3 995
bfbd9128 996 const names1 = await getPlaylistNames()
a1587156
C
997 expect(names1[0]).to.equal('playlist 3 updated')
998 expect(names1[1]).to.equal('playlist 2')
2a10aab3 999
bfbd9128
C
1000 await removeVideoFromPlaylist({
1001 url: server.url,
1002 token: server.accessToken,
1003 playlistId: playlistServer2Id1,
1004 playlistElementId: element1
1005 })
2a10aab3 1006
bfbd9128 1007 const names2 = await getPlaylistNames()
a1587156
C
1008 expect(names2[0]).to.equal('playlist 2')
1009 expect(names2[1]).to.equal('playlist 3 updated')
2a10aab3 1010
bfbd9128
C
1011 await removeVideoFromPlaylist({
1012 url: server.url,
1013 token: server.accessToken,
1014 playlistId: playlistServer2Id2,
1015 playlistElementId: element2
1016 })
df0b219d 1017
bfbd9128 1018 const names3 = await getPlaylistNames()
a1587156
C
1019 expect(names3[0]).to.equal('playlist 3 updated')
1020 expect(names3[1]).to.equal('playlist 2')
df0b219d
C
1021 })
1022
bfbd9128
C
1023 it('Should delete some elements', async function () {
1024 this.timeout(30000)
df0b219d 1025
bfbd9128 1026 await removeVideoFromPlaylist({
a1587156
C
1027 url: servers[0].url,
1028 token: servers[0].accessToken,
bfbd9128
C
1029 playlistId: playlistServer1Id,
1030 playlistElementId: playlistElementServer1Video4
1031 })
df0b219d 1032
bfbd9128 1033 await removeVideoFromPlaylist({
a1587156
C
1034 url: servers[0].url,
1035 token: servers[0].accessToken,
bfbd9128
C
1036 playlistId: playlistServer1Id,
1037 playlistElementId: playlistElementNSFW
1038 })
df0b219d 1039
bfbd9128 1040 await waitJobs(servers)
df0b219d 1041
bfbd9128
C
1042 for (const server of servers) {
1043 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
418d092a 1044
37190663 1045 expect(res.body.total).to.equal(6)
df0b219d 1046
bfbd9128 1047 const elements: VideoPlaylistElement[] = res.body.data
37190663 1048 expect(elements).to.have.lengthOf(6)
df0b219d 1049
a1587156
C
1050 expect(elements[0].video.name).to.equal('video 0 server 1')
1051 expect(elements[0].position).to.equal(1)
df0b219d 1052
a1587156
C
1053 expect(elements[1].video.name).to.equal('video 2 server 3')
1054 expect(elements[1].position).to.equal(2)
418d092a 1055
a1587156
C
1056 expect(elements[2].video.name).to.equal('video 1 server 3')
1057 expect(elements[2].position).to.equal(3)
1b319b7a 1058
a1587156
C
1059 expect(elements[3].video.name).to.equal('video 4 server 1')
1060 expect(elements[3].position).to.equal(4)
37190663
C
1061
1062 expect(elements[4].video.name).to.equal('NSFW video')
1063 expect(elements[4].position).to.equal(5)
1064
1065 expect(elements[5].video.name).to.equal('NSFW video')
1066 expect(elements[5].position).to.equal(6)
1b319b7a
C
1067 }
1068 })
1b319b7a 1069
bfbd9128
C
1070 it('Should be able to create a public playlist, and set it to private', async function () {
1071 this.timeout(30000)
1b319b7a 1072
bfbd9128 1073 const res = await createVideoPlaylist({
a1587156
C
1074 url: servers[0].url,
1075 token: servers[0].accessToken,
bfbd9128
C
1076 playlistAttrs: {
1077 displayName: 'my super public playlist',
1078 privacy: VideoPlaylistPrivacy.PUBLIC,
a1587156 1079 videoChannelId: servers[0].videoChannel.id
bfbd9128
C
1080 }
1081 })
1082 const videoPlaylistIds = res.body.videoPlaylist
1b319b7a 1083
bfbd9128 1084 await waitJobs(servers)
1b319b7a 1085
bfbd9128
C
1086 for (const server of servers) {
1087 await getVideoPlaylist(server.url, videoPlaylistIds.uuid, 200)
1088 }
1b319b7a 1089
bfbd9128 1090 const playlistAttrs = { privacy: VideoPlaylistPrivacy.PRIVATE }
a1587156 1091 await updateVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: videoPlaylistIds.id, playlistAttrs })
1b319b7a 1092
bfbd9128 1093 await waitJobs(servers)
1b319b7a 1094
a1587156 1095 for (const server of [ servers[1], servers[2] ]) {
bfbd9128
C
1096 await getVideoPlaylist(server.url, videoPlaylistIds.uuid, 404)
1097 }
a1587156 1098 await getVideoPlaylist(servers[0].url, videoPlaylistIds.uuid, 401)
418d092a 1099
a1587156 1100 await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistIds.uuid, 200)
bfbd9128
C
1101 })
1102 })
df0b219d 1103
bfbd9128 1104 describe('Playlist deletion', function () {
df0b219d 1105
bfbd9128
C
1106 it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () {
1107 this.timeout(30000)
418d092a 1108
a1587156 1109 await deleteVideoPlaylist(servers[0].url, servers[0].accessToken, playlistServer1Id)
418d092a 1110
bfbd9128 1111 await waitJobs(servers)
418d092a 1112
bfbd9128
C
1113 for (const server of servers) {
1114 await getVideoPlaylist(server.url, playlistServer1UUID, 404)
1115 }
1116 })
418d092a 1117
bfbd9128
C
1118 it('Should have deleted the thumbnail on server 1, 2 and 3', async function () {
1119 this.timeout(30000)
df0b219d 1120
bfbd9128
C
1121 for (const server of servers) {
1122 await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.internalServerNumber)
1123 }
1124 })
df0b219d 1125
bfbd9128
C
1126 it('Should unfollow servers 1 and 2 and hide their playlists', async function () {
1127 this.timeout(30000)
df0b219d 1128
bfbd9128 1129 const finder = data => data.find(p => p.displayName === 'my super playlist')
df0b219d 1130
bfbd9128 1131 {
a1587156 1132 const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
bfbd9128
C
1133 expect(res.body.total).to.equal(3)
1134 expect(finder(res.body.data)).to.not.be.undefined
1135 }
418d092a 1136
a1587156 1137 await unfollow(servers[2].url, servers[2].accessToken, servers[0])
df0b219d 1138
bfbd9128 1139 {
a1587156 1140 const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
bfbd9128 1141 expect(res.body.total).to.equal(1)
418d092a 1142
bfbd9128 1143 expect(finder(res.body.data)).to.be.undefined
df0b219d
C
1144 }
1145 })
df0b219d 1146
bfbd9128
C
1147 it('Should delete a channel and put the associated playlist in private mode', async function () {
1148 this.timeout(30000)
df0b219d 1149
a1587156 1150 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, { name: 'super_channel', displayName: 'super channel' })
bfbd9128 1151 const videoChannelId = res.body.videoChannel.id
df0b219d 1152
bfbd9128 1153 const res2 = await createVideoPlaylist({
a1587156
C
1154 url: servers[0].url,
1155 token: servers[0].accessToken,
bfbd9128
C
1156 playlistAttrs: {
1157 displayName: 'channel playlist',
1158 privacy: VideoPlaylistPrivacy.PUBLIC,
1159 videoChannelId
1160 }
1161 })
1162 const videoPlaylistUUID = res2.body.videoPlaylist.uuid
1163
1164 await waitJobs(servers)
df0b219d 1165
a1587156 1166 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'super_channel')
df0b219d 1167
bfbd9128 1168 await waitJobs(servers)
418d092a 1169
a1587156 1170 const res3 = await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistUUID)
bfbd9128
C
1171 expect(res3.body.displayName).to.equal('channel playlist')
1172 expect(res3.body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE)
df0b219d 1173
a1587156 1174 await getVideoPlaylist(servers[1].url, videoPlaylistUUID, 404)
1eddc9a7 1175 })
df0b219d 1176
bfbd9128
C
1177 it('Should delete an account and delete its playlists', async function () {
1178 this.timeout(30000)
418d092a 1179
bfbd9128
C
1180 const user = { username: 'user_1', password: 'password' }
1181 const res = await createUser({
a1587156
C
1182 url: servers[0].url,
1183 accessToken: servers[0].accessToken,
bfbd9128
C
1184 username: user.username,
1185 password: user.password
1186 })
397d78fb 1187
bfbd9128 1188 const userId = res.body.user.id
a1587156 1189 const userAccessToken = await userLogin(servers[0], user)
df0b219d 1190
a1587156
C
1191 const resChannel = await getMyUserInformation(servers[0].url, userAccessToken)
1192 const userChannel = (resChannel.body as User).videoChannels[0]
df0b219d 1193
bfbd9128 1194 await createVideoPlaylist({
a1587156 1195 url: servers[0].url,
bfbd9128
C
1196 token: userAccessToken,
1197 playlistAttrs: {
1198 displayName: 'playlist to be deleted',
1199 privacy: VideoPlaylistPrivacy.PUBLIC,
1200 videoChannelId: userChannel.id
1201 }
1202 })
df0b219d 1203
bfbd9128
C
1204 await waitJobs(servers)
1205
1206 const finder = data => data.find(p => p.displayName === 'playlist to be deleted')
1207
1208 {
a1587156 1209 for (const server of [ servers[0], servers[1] ]) {
bfbd9128
C
1210 const res = await getVideoPlaylistsList(server.url, 0, 15)
1211 expect(finder(res.body.data)).to.not.be.undefined
1212 }
df0b219d 1213 }
df0b219d 1214
a1587156 1215 await removeUser(servers[0].url, userId, servers[0].accessToken)
bfbd9128 1216 await waitJobs(servers)
df0b219d 1217
bfbd9128 1218 {
a1587156 1219 for (const server of [ servers[0], servers[1] ]) {
bfbd9128
C
1220 const res = await getVideoPlaylistsList(server.url, 0, 15)
1221 expect(finder(res.body.data)).to.be.undefined
1222 }
df0b219d 1223 }
bfbd9128 1224 })
418d092a
C
1225 })
1226
7c3b7976
C
1227 after(async function () {
1228 await cleanupTests(servers)
418d092a
C
1229 })
1230})