]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-playlists.ts
Fix broken playlist api
[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 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
144 nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[ 0 ], videoName: 'NSFW video', nsfw: true })).id
145
bfbd9128
C
146 {
147 await createUser({
148 url: servers[ 0 ].url,
149 accessToken: servers[ 0 ].accessToken,
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 () {
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
bfbd9128
C
166 expect(privacies[ 3 ]).to.equal('Private')
167 })
d4c9f45b 168
bfbd9128
C
169 it('Should list watch later playlist', async function () {
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
179 const playlist: VideoPlaylist = res.body.data[ 0 ]
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 () {
200 const token = await generateUserAccessToken(servers[ 0 ], 'toto')
201
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
bfbd9128
C
207 const playlistId = res.body.data[ 0 ].id
208 await getPlaylistVideos(servers[ 0 ].url, token, playlistId, 0, 5)
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
C
217 await createVideoPlaylist({
218 url: servers[ 0 ].url,
219 token: servers[ 0 ].accessToken,
220 playlistAttrs: {
221 displayName: 'my super playlist',
222 privacy: VideoPlaylistPrivacy.PUBLIC,
223 description: 'my super description',
224 thumbnailfile: 'thumbnail.jpg',
225 videoChannelId: servers[ 0 ].videoChannel.id
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
236 const playlistFromList = res.body.data[ 0 ] as VideoPlaylist
237
238 const res2 = await getVideoPlaylist(server.url, playlistFromList.uuid)
239 const playlistFromGet = res2.body
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')
253
254 expect(playlist.videosLength).to.equal(0)
df0b219d 255
bfbd9128
C
256 expect(playlist.ownerAccount.name).to.equal('root')
257 expect(playlist.ownerAccount.displayName).to.equal('root')
258 expect(playlist.videoChannel.name).to.equal('root_channel')
259 expect(playlist.videoChannel.displayName).to.equal('Main root channel')
260 }
261 }
262 })
4d09cfba 263
bfbd9128
C
264 it('Should create a playlist on server 2 and have the playlist on server 1 but not on server 3', async function () {
265 this.timeout(30000)
266
267 {
268 const res = await createVideoPlaylist({
269 url: servers[ 1 ].url,
270 token: servers[ 1 ].accessToken,
271 playlistAttrs: {
272 displayName: 'playlist 2',
273 privacy: VideoPlaylistPrivacy.PUBLIC,
274 videoChannelId: servers[ 1 ].videoChannel.id
275 }
276 })
277 playlistServer2Id1 = res.body.videoPlaylist.id
278 }
4d09cfba 279
bfbd9128
C
280 {
281 const res = await createVideoPlaylist({
282 url: servers[ 1 ].url,
283 token: servers[ 1 ].accessToken,
284 playlistAttrs: {
285 displayName: 'playlist 3',
286 privacy: VideoPlaylistPrivacy.PUBLIC,
287 thumbnailfile: 'thumbnail.jpg',
288 videoChannelId: servers[ 1 ].videoChannel.id
289 }
290 })
291
292 playlistServer2Id2 = res.body.videoPlaylist.id
293 playlistServer2UUID2 = res.body.videoPlaylist.uuid
294 }
295
296 for (let id of [ playlistServer2Id1, playlistServer2Id2 ]) {
297 await addVideoInPlaylist({
298 url: servers[ 1 ].url,
299 token: servers[ 1 ].accessToken,
300 playlistId: id,
301 elementAttrs: { videoId: servers[ 1 ].videos[ 0 ].id, startTimestamp: 1, stopTimestamp: 2 }
302 })
303 await addVideoInPlaylist({
304 url: servers[ 1 ].url,
305 token: servers[ 1 ].accessToken,
306 playlistId: id,
307 elementAttrs: { videoId: servers[ 1 ].videos[ 1 ].id }
308 })
309 }
310
311 await waitJobs(servers)
312
313 for (const server of [ servers[ 0 ], servers[ 1 ] ]) {
314 const res = await getVideoPlaylistsList(server.url, 0, 5)
315
316 const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2')
317 expect(playlist2).to.not.be.undefined
318 await testImage(server.url, 'thumbnail-playlist', playlist2.thumbnailPath)
319
320 const playlist3 = res.body.data.find(p => p.displayName === 'playlist 3')
321 expect(playlist3).to.not.be.undefined
322 await testImage(server.url, 'thumbnail', playlist3.thumbnailPath)
323 }
4d09cfba 324
bfbd9128
C
325 const res = await getVideoPlaylistsList(servers[ 2 ].url, 0, 5)
326 expect(res.body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined
327 expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined
328 })
329
330 it('Should have the playlist on server 3 after a new follow', async function () {
331 this.timeout(30000)
332
333 // Server 2 and server 3 follow each other
334 await doubleFollow(servers[ 1 ], servers[ 2 ])
335
336 const res = await getVideoPlaylistsList(servers[ 2 ].url, 0, 5)
337
338 const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2')
339 expect(playlist2).to.not.be.undefined
340 await testImage(servers[ 2 ].url, 'thumbnail-playlist', playlist2.thumbnailPath)
341
342 expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined
343 })
4d09cfba
C
344 })
345
bfbd9128
C
346 describe('List playlists', function () {
347 it('Should correctly list the playlists', async function () {
348 this.timeout(30000)
349
350 {
351 const res = await getVideoPlaylistsList(servers[ 2 ].url, 1, 2, 'createdAt')
df0b219d 352
bfbd9128
C
353 expect(res.body.total).to.equal(3)
354
355 const data: VideoPlaylist[] = res.body.data
356 expect(data).to.have.lengthOf(2)
357 expect(data[ 0 ].displayName).to.equal('playlist 2')
358 expect(data[ 1 ].displayName).to.equal('playlist 3')
359 }
360
361 {
362 const res = await getVideoPlaylistsList(servers[ 2 ].url, 1, 2, '-createdAt')
363
364 expect(res.body.total).to.equal(3)
365
366 const data: VideoPlaylist[] = res.body.data
367 expect(data).to.have.lengthOf(2)
368 expect(data[ 0 ].displayName).to.equal('playlist 2')
369 expect(data[ 1 ].displayName).to.equal('my super playlist')
df0b219d
C
370 }
371 })
372
bfbd9128
C
373 it('Should list video channel playlists', async function () {
374 this.timeout(30000)
df0b219d 375
bfbd9128
C
376 {
377 const res = await getVideoChannelPlaylistsList(servers[ 0 ].url, 'root_channel', 0, 2, '-createdAt')
df0b219d 378
bfbd9128 379 expect(res.body.total).to.equal(1)
df0b219d 380
bfbd9128
C
381 const data: VideoPlaylist[] = res.body.data
382 expect(data).to.have.lengthOf(1)
383 expect(data[ 0 ].displayName).to.equal('my super playlist')
384 }
385 })
df0b219d 386
bfbd9128
C
387 it('Should list account playlists', async function () {
388 this.timeout(30000)
df0b219d 389
bfbd9128
C
390 {
391 const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 1, 2, '-createdAt')
df0b219d 392
bfbd9128
C
393 expect(res.body.total).to.equal(2)
394
395 const data: VideoPlaylist[] = res.body.data
396 expect(data).to.have.lengthOf(1)
397 expect(data[ 0 ].displayName).to.equal('playlist 2')
398 }
df0b219d 399
bfbd9128
C
400 {
401 const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 1, 2, 'createdAt')
df0b219d 402
bfbd9128
C
403 expect(res.body.total).to.equal(2)
404
405 const data: VideoPlaylist[] = res.body.data
406 expect(data).to.have.lengthOf(1)
407 expect(data[ 0 ].displayName).to.equal('playlist 3')
df0b219d 408 }
bfbd9128 409 })
418d092a 410
bfbd9128
C
411 it('Should not list unlisted or private playlists', async function () {
412 this.timeout(30000)
df0b219d 413
bfbd9128
C
414 await createVideoPlaylist({
415 url: servers[ 1 ].url,
416 token: servers[ 1 ].accessToken,
df0b219d 417 playlistAttrs: {
bfbd9128
C
418 displayName: 'playlist unlisted',
419 privacy: VideoPlaylistPrivacy.UNLISTED
df0b219d
C
420 }
421 })
df0b219d 422
bfbd9128 423 await createVideoPlaylist({
df0b219d
C
424 url: servers[ 1 ].url,
425 token: servers[ 1 ].accessToken,
426 playlistAttrs: {
bfbd9128
C
427 displayName: 'playlist private',
428 privacy: VideoPlaylistPrivacy.PRIVATE
df0b219d
C
429 }
430 })
431
bfbd9128 432 await waitJobs(servers)
df0b219d 433
bfbd9128
C
434 for (const server of servers) {
435 const results = [
436 await getAccountPlaylistsList(server.url, 'root@localhost:' + servers[ 1 ].port, 0, 5, '-createdAt'),
437 await getVideoPlaylistsList(server.url, 0, 2, '-createdAt')
438 ]
439
440 expect(results[ 0 ].body.total).to.equal(2)
441 expect(results[ 1 ].body.total).to.equal(3)
442
443 for (const res of results) {
444 const data: VideoPlaylist[] = res.body.data
445 expect(data).to.have.lengthOf(2)
446 expect(data[ 0 ].displayName).to.equal('playlist 3')
447 expect(data[ 1 ].displayName).to.equal('playlist 2')
448 }
449 }
450 })
451 })
df0b219d 452
bfbd9128 453 describe('Update playlists', function () {
df0b219d 454
bfbd9128
C
455 it('Should update a playlist', async function () {
456 this.timeout(30000)
df0b219d 457
bfbd9128
C
458 await updateVideoPlaylist({
459 url: servers[1].url,
460 token: servers[1].accessToken,
461 playlistAttrs: {
462 displayName: 'playlist 3 updated',
463 description: 'description updated',
464 privacy: VideoPlaylistPrivacy.UNLISTED,
465 thumbnailfile: 'thumbnail.jpg',
466 videoChannelId: servers[1].videoChannel.id
467 },
468 playlistId: playlistServer2Id2
469 })
df0b219d 470
bfbd9128 471 await waitJobs(servers)
df0b219d 472
bfbd9128
C
473 for (const server of servers) {
474 const res = await getVideoPlaylist(server.url, playlistServer2UUID2)
475 const playlist: VideoPlaylist = res.body
418d092a 476
bfbd9128
C
477 expect(playlist.displayName).to.equal('playlist 3 updated')
478 expect(playlist.description).to.equal('description updated')
df0b219d 479
bfbd9128
C
480 expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.UNLISTED)
481 expect(playlist.privacy.label).to.equal('Unlisted')
df0b219d 482
bfbd9128
C
483 expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
484 expect(playlist.type.label).to.equal('Regular')
df0b219d 485
bfbd9128 486 expect(playlist.videosLength).to.equal(2)
df0b219d 487
bfbd9128
C
488 expect(playlist.ownerAccount.name).to.equal('root')
489 expect(playlist.ownerAccount.displayName).to.equal('root')
490 expect(playlist.videoChannel.name).to.equal('root_channel')
491 expect(playlist.videoChannel.displayName).to.equal('Main root channel')
492 }
493 })
418d092a
C
494 })
495
bfbd9128 496 describe('Element timestamps', function () {
df0b219d 497
bfbd9128
C
498 it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () {
499 this.timeout(30000)
df0b219d 500
bfbd9128
C
501 const addVideo = (elementAttrs: any) => {
502 return addVideoInPlaylist({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, playlistId: playlistServer1Id, elementAttrs })
503 }
df0b219d 504
bfbd9128
C
505 const res = await createVideoPlaylist({
506 url: servers[ 0 ].url,
507 token: servers[ 0 ].accessToken,
508 playlistAttrs: {
509 displayName: 'playlist 4',
510 privacy: VideoPlaylistPrivacy.PUBLIC,
511 videoChannelId: servers[ 0 ].videoChannel.id
512 }
513 })
df0b219d 514
bfbd9128
C
515 playlistServer1Id = res.body.videoPlaylist.id
516 playlistServer1UUID = res.body.videoPlaylist.uuid
df0b219d 517
bfbd9128
C
518 await addVideo({ videoId: servers[ 0 ].videos[ 0 ].uuid, startTimestamp: 15, stopTimestamp: 28 })
519 await addVideo({ videoId: servers[ 2 ].videos[ 1 ].uuid, startTimestamp: 35 })
520 await addVideo({ videoId: servers[ 2 ].videos[ 2 ].uuid })
521 {
522 const res = await addVideo({ videoId: servers[ 0 ].videos[ 3 ].uuid, stopTimestamp: 35 })
523 playlistElementServer1Video4 = res.body.videoPlaylistElement.id
524 }
df0b219d 525
bfbd9128
C
526 {
527 const res = await addVideo({ videoId: servers[ 0 ].videos[ 4 ].uuid, startTimestamp: 45, stopTimestamp: 60 })
528 playlistElementServer1Video5 = res.body.videoPlaylistElement.id
529 }
418d092a 530
bfbd9128
C
531 {
532 const res = await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 })
533 playlistElementNSFW = res.body.videoPlaylistElement.id
534 }
df0b219d 535
bfbd9128
C
536 await waitJobs(servers)
537 })
df0b219d 538
bfbd9128
C
539 it('Should correctly list playlist videos', async function () {
540 this.timeout(30000)
df0b219d 541
bfbd9128
C
542 for (const server of servers) {
543 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
418d092a 544
bfbd9128 545 expect(res.body.total).to.equal(6)
df0b219d 546
bfbd9128
C
547 const videoElements: VideoPlaylistElement[] = res.body.data
548 expect(videoElements).to.have.lengthOf(6)
df0b219d 549
bfbd9128
C
550 expect(videoElements[ 0 ].video.name).to.equal('video 0 server 1')
551 expect(videoElements[ 0 ].position).to.equal(1)
552 expect(videoElements[ 0 ].startTimestamp).to.equal(15)
553 expect(videoElements[ 0 ].stopTimestamp).to.equal(28)
df0b219d 554
bfbd9128
C
555 expect(videoElements[ 1 ].video.name).to.equal('video 1 server 3')
556 expect(videoElements[ 1 ].position).to.equal(2)
557 expect(videoElements[ 1 ].startTimestamp).to.equal(35)
558 expect(videoElements[ 1 ].stopTimestamp).to.be.null
df0b219d 559
bfbd9128
C
560 expect(videoElements[ 2 ].video.name).to.equal('video 2 server 3')
561 expect(videoElements[ 2 ].position).to.equal(3)
562 expect(videoElements[ 2 ].startTimestamp).to.be.null
563 expect(videoElements[ 2 ].stopTimestamp).to.be.null
df0b219d 564
bfbd9128
C
565 expect(videoElements[ 3 ].video.name).to.equal('video 3 server 1')
566 expect(videoElements[ 3 ].position).to.equal(4)
567 expect(videoElements[ 3 ].startTimestamp).to.be.null
568 expect(videoElements[ 3 ].stopTimestamp).to.equal(35)
df0b219d 569
bfbd9128
C
570 expect(videoElements[ 4 ].video.name).to.equal('video 4 server 1')
571 expect(videoElements[ 4 ].position).to.equal(5)
572 expect(videoElements[ 4 ].startTimestamp).to.equal(45)
573 expect(videoElements[ 4 ].stopTimestamp).to.equal(60)
418d092a 574
bfbd9128
C
575 expect(videoElements[ 5 ].video.name).to.equal('NSFW video')
576 expect(videoElements[ 5 ].position).to.equal(6)
577 expect(videoElements[ 5 ].startTimestamp).to.equal(5)
578 expect(videoElements[ 5 ].stopTimestamp).to.be.null
df0b219d 579
bfbd9128
C
580 const res3 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 2)
581 expect(res3.body.data).to.have.lengthOf(2)
df0b219d
C
582 }
583 })
bfbd9128 584 })
df0b219d 585
bfbd9128
C
586 describe('Element type', function () {
587 let groupUser1: ServerInfo[]
588 let groupWithoutToken1: ServerInfo[]
589 let group1: ServerInfo[]
590 let group2: ServerInfo[]
df0b219d 591
bfbd9128
C
592 let video1: string
593 let video2: string
594 let video3: string
df0b219d 595
bfbd9128
C
596 before(async function () {
597 this.timeout(30000)
df0b219d 598
bfbd9128
C
599 groupUser1 = [ Object.assign({}, servers[ 0 ], { accessToken: userAccessTokenServer1 }) ]
600 groupWithoutToken1 = [ Object.assign({}, servers[ 0 ], { accessToken: undefined }) ]
601 group1 = [ servers[ 0 ] ]
602 group2 = [ servers[ 1 ], servers[ 2 ] ]
df0b219d 603
bfbd9128
C
604 const res = await createVideoPlaylist({
605 url: servers[ 0 ].url,
606 token: userAccessTokenServer1,
607 playlistAttrs: {
608 displayName: 'playlist 56',
609 privacy: VideoPlaylistPrivacy.PUBLIC,
610 videoChannelId: servers[ 0 ].videoChannel.id
611 }
612 })
418d092a 613
bfbd9128
C
614 const playlistServer1Id2 = res.body.videoPlaylist.id
615 playlistServer1UUID2 = res.body.videoPlaylist.uuid
df0b219d 616
bfbd9128
C
617 const addVideo = (elementAttrs: any) => {
618 return addVideoInPlaylist({ url: servers[ 0 ].url, token: userAccessTokenServer1, playlistId: playlistServer1Id2, elementAttrs })
619 }
df0b219d 620
bfbd9128
C
621 video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userAccessTokenServer1 })).uuid
622 video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid
623 video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid
df0b219d 624
bfbd9128
C
625 await addVideo({ videoId: video1, startTimestamp: 15, stopTimestamp: 28 })
626 await addVideo({ videoId: video2, startTimestamp: 35 })
627 await addVideo({ videoId: video3 })
df0b219d 628
bfbd9128
C
629 await waitJobs(servers)
630 })
df0b219d 631
bfbd9128
C
632 it('Should update the element type if the video is private', async function () {
633 this.timeout(20000)
df0b219d 634
bfbd9128
C
635 const name = 'video 89'
636 const position = 1
df0b219d 637
bfbd9128
C
638 {
639 await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, video1, { privacy: VideoPrivacy.PRIVATE })
640 await waitJobs(servers)
418d092a 641
bfbd9128
C
642 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
643 await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.PRIVATE, position, name, 3)
644 await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.PRIVATE, position, name, 3)
645 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
646 }
df0b219d 647
bfbd9128
C
648 {
649 await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, video1, { privacy: VideoPrivacy.PUBLIC })
650 await waitJobs(servers)
418d092a 651
bfbd9128
C
652 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
653 await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
654 await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
655 // We deleted the video, so even if we recreated it, the old entry is still deleted
656 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
df0b219d
C
657 }
658 })
659
bfbd9128
C
660 it('Should update the element type if the video is blacklisted', async function () {
661 this.timeout(20000)
df0b219d 662
bfbd9128
C
663 const name = 'video 89'
664 const position = 1
df0b219d 665
bfbd9128
C
666 {
667 await addVideoToBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video1, 'reason', true)
668 await waitJobs(servers)
418d092a 669
bfbd9128
C
670 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
671 await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
672 await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
673 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
674 }
df0b219d 675
bfbd9128
C
676 {
677 await removeVideoFromBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video1)
678 await waitJobs(servers)
df0b219d 679
bfbd9128
C
680 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
681 await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
682 await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
683 // We deleted the video (because unfederated), so even if we recreated it, the old entry is still deleted
684 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3)
685 }
686 })
df0b219d 687
bfbd9128
C
688 it('Should update the element type if the account or server of the video is blocked', async function () {
689 this.timeout(90000)
df0b219d 690
bfbd9128
C
691 const name = 'video 90'
692 const position = 2
df0b219d 693
bfbd9128
C
694 {
695 await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port)
696 await waitJobs(servers)
df0b219d 697
bfbd9128
C
698 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
699 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
df0b219d 700
bfbd9128
C
701 await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port)
702 await waitJobs(servers)
df0b219d 703
bfbd9128
C
704 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
705 }
df0b219d 706
bfbd9128
C
707 {
708 await addServerToAccountBlocklist(servers[ 0 ].url, userAccessTokenServer1, 'localhost:' + servers[1].port)
709 await waitJobs(servers)
df0b219d 710
bfbd9128
C
711 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
712 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
df0b219d 713
bfbd9128
C
714 await removeServerFromAccountBlocklist(servers[ 0 ].url, userAccessTokenServer1, 'localhost:' + servers[1].port)
715 await waitJobs(servers)
418d092a 716
bfbd9128
C
717 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
718 }
df0b219d 719
bfbd9128
C
720 {
721 await addAccountToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'root@localhost:' + servers[1].port)
722 await waitJobs(servers)
df0b219d 723
bfbd9128
C
724 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
725 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
df0b219d 726
bfbd9128
C
727 await removeAccountFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'root@localhost:' + servers[1].port)
728 await waitJobs(servers)
df0b219d 729
bfbd9128 730 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
df0b219d 731 }
df0b219d 732
bfbd9128
C
733 {
734 await addServerToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:' + servers[1].port)
735 await waitJobs(servers)
df0b219d 736
bfbd9128
C
737 await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3)
738 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
df0b219d 739
bfbd9128
C
740 await removeServerFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:' + servers[1].port)
741 await waitJobs(servers)
df0b219d 742
bfbd9128 743 await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
df0b219d 744 }
bfbd9128 745 })
df0b219d 746
bfbd9128
C
747 it('Should hide the video if it is NSFW', async function () {
748 const res = await getPlaylistVideos(servers[0].url, userAccessTokenServer1, playlistServer1UUID2, 0, 10, { nsfw: false })
749 expect(res.body.total).to.equal(3)
df0b219d 750
bfbd9128
C
751 const elements: VideoPlaylistElement[] = res.body.data
752 const element = elements.find(e => e.position === 3)
df0b219d 753
bfbd9128
C
754 expect(element).to.exist
755 expect(element.video).to.be.null
756 expect(element.type).to.equal(VideoPlaylistElementType.UNAVAILABLE)
757 })
df0b219d 758
bfbd9128 759 })
df0b219d 760
bfbd9128
C
761 describe('Managing playlist elements', function () {
762
763 it('Should reorder the playlist', async function () {
764 this.timeout(30000)
765
766 {
767 await reorderVideosPlaylist({
768 url: servers[ 0 ].url,
769 token: servers[ 0 ].accessToken,
770 playlistId: playlistServer1Id,
771 elementAttrs: {
772 startPosition: 2,
773 insertAfterPosition: 3
774 }
775 })
776
777 await waitJobs(servers)
778
779 for (const server of servers) {
780 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
781 const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name)
782
783 expect(names).to.deep.equal([
784 'video 0 server 1',
785 'video 2 server 3',
786 'video 1 server 3',
787 'video 3 server 1',
788 'video 4 server 1',
789 'NSFW video'
790 ])
df0b219d
C
791 }
792 }
df0b219d 793
bfbd9128
C
794 {
795 await reorderVideosPlaylist({
796 url: servers[ 0 ].url,
797 token: servers[ 0 ].accessToken,
798 playlistId: playlistServer1Id,
799 elementAttrs: {
800 startPosition: 1,
801 reorderLength: 3,
802 insertAfterPosition: 4
803 }
804 })
805
806 await waitJobs(servers)
807
808 for (const server of servers) {
809 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
810 const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name)
811
812 expect(names).to.deep.equal([
813 'video 3 server 1',
814 'video 0 server 1',
815 'video 2 server 3',
816 'video 1 server 3',
817 'video 4 server 1',
818 'NSFW video'
819 ])
820 }
df0b219d 821 }
df0b219d 822
bfbd9128
C
823 {
824 await reorderVideosPlaylist({
825 url: servers[ 0 ].url,
826 token: servers[ 0 ].accessToken,
827 playlistId: playlistServer1Id,
828 elementAttrs: {
829 startPosition: 6,
830 insertAfterPosition: 3
831 }
832 })
833
834 await waitJobs(servers)
835
836 for (const server of servers) {
837 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
838 const elements: VideoPlaylistElement[] = res.body.data
839 const names = elements.map(v => v.video.name)
840
841 expect(names).to.deep.equal([
842 'video 3 server 1',
843 'video 0 server 1',
844 'video 2 server 3',
845 'NSFW video',
846 'video 1 server 3',
847 'video 4 server 1'
848 ])
849
850 for (let i = 1; i <= elements.length; i++) {
851 expect(elements[ i - 1 ].position).to.equal(i)
852 }
853 }
df0b219d
C
854 }
855 })
856
bfbd9128
C
857 it('Should update startTimestamp/endTimestamp of some elements', async function () {
858 this.timeout(30000)
859
860 await updateVideoPlaylistElement({
861 url: servers[ 0 ].url,
862 token: servers[ 0 ].accessToken,
863 playlistId: playlistServer1Id,
864 playlistElementId: playlistElementServer1Video4,
865 elementAttrs: {
866 startTimestamp: 1
867 }
868 })
df0b219d 869
bfbd9128
C
870 await updateVideoPlaylistElement({
871 url: servers[ 0 ].url,
872 token: servers[ 0 ].accessToken,
873 playlistId: playlistServer1Id,
874 playlistElementId: playlistElementServer1Video5,
875 elementAttrs: {
876 stopTimestamp: null
877 }
878 })
df0b219d 879
bfbd9128 880 await waitJobs(servers)
df0b219d 881
bfbd9128
C
882 for (const server of servers) {
883 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
884 const elements: VideoPlaylistElement[] = res.body.data
418d092a 885
bfbd9128
C
886 expect(elements[ 0 ].video.name).to.equal('video 3 server 1')
887 expect(elements[ 0 ].position).to.equal(1)
888 expect(elements[ 0 ].startTimestamp).to.equal(1)
889 expect(elements[ 0 ].stopTimestamp).to.equal(35)
0b16f5f2 890
bfbd9128
C
891 expect(elements[ 5 ].video.name).to.equal('video 4 server 1')
892 expect(elements[ 5 ].position).to.equal(6)
893 expect(elements[ 5 ].startTimestamp).to.equal(45)
894 expect(elements[ 5 ].stopTimestamp).to.be.null
895 }
896 })
0b16f5f2 897
bfbd9128
C
898 it('Should check videos existence in my playlist', async function () {
899 const videoIds = [
900 servers[ 0 ].videos[ 0 ].id,
901 42000,
902 servers[ 0 ].videos[ 3 ].id,
903 43000,
904 servers[ 0 ].videos[ 4 ].id
905 ]
906 const res = await doVideosExistInMyPlaylist(servers[ 0 ].url, servers[ 0 ].accessToken, videoIds)
907 const obj = res.body as VideoExistInPlaylist
908
909 {
910 const elem = obj[ servers[ 0 ].videos[ 0 ].id ]
911 expect(elem).to.have.lengthOf(1)
912 expect(elem[ 0 ].playlistElementId).to.exist
913 expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
914 expect(elem[ 0 ].startTimestamp).to.equal(15)
915 expect(elem[ 0 ].stopTimestamp).to.equal(28)
916 }
0b16f5f2 917
bfbd9128
C
918 {
919 const elem = obj[ servers[ 0 ].videos[ 3 ].id ]
920 expect(elem).to.have.lengthOf(1)
921 expect(elem[ 0 ].playlistElementId).to.equal(playlistElementServer1Video4)
922 expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
923 expect(elem[ 0 ].startTimestamp).to.equal(1)
924 expect(elem[ 0 ].stopTimestamp).to.equal(35)
925 }
0b16f5f2 926
bfbd9128
C
927 {
928 const elem = obj[ servers[ 0 ].videos[ 4 ].id ]
929 expect(elem).to.have.lengthOf(1)
930 expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
931 expect(elem[ 0 ].startTimestamp).to.equal(45)
932 expect(elem[ 0 ].stopTimestamp).to.equal(null)
933 }
0b16f5f2 934
bfbd9128
C
935 expect(obj[ 42000 ]).to.have.lengthOf(0)
936 expect(obj[ 43000 ]).to.have.lengthOf(0)
937 })
2a10aab3 938
bfbd9128
C
939 it('Should automatically update updatedAt field of playlists', async function () {
940 const server = servers[ 1 ]
941 const videoId = servers[ 1 ].videos[ 5 ].id
2a10aab3 942
bfbd9128
C
943 async function getPlaylistNames () {
944 const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, undefined, '-updatedAt')
2a10aab3 945
bfbd9128
C
946 return (res.body.data as VideoPlaylist[]).map(p => p.displayName)
947 }
2a10aab3 948
bfbd9128
C
949 const elementAttrs = { videoId }
950 const res1 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, elementAttrs })
951 const res2 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, elementAttrs })
2a10aab3 952
bfbd9128
C
953 const element1 = res1.body.videoPlaylistElement.id
954 const element2 = res2.body.videoPlaylistElement.id
2a10aab3 955
bfbd9128
C
956 const names1 = await getPlaylistNames()
957 expect(names1[ 0 ]).to.equal('playlist 3 updated')
958 expect(names1[ 1 ]).to.equal('playlist 2')
2a10aab3 959
bfbd9128
C
960 await removeVideoFromPlaylist({
961 url: server.url,
962 token: server.accessToken,
963 playlistId: playlistServer2Id1,
964 playlistElementId: element1
965 })
2a10aab3 966
bfbd9128
C
967 const names2 = await getPlaylistNames()
968 expect(names2[ 0 ]).to.equal('playlist 2')
969 expect(names2[ 1 ]).to.equal('playlist 3 updated')
2a10aab3 970
bfbd9128
C
971 await removeVideoFromPlaylist({
972 url: server.url,
973 token: server.accessToken,
974 playlistId: playlistServer2Id2,
975 playlistElementId: element2
976 })
df0b219d 977
bfbd9128
C
978 const names3 = await getPlaylistNames()
979 expect(names3[ 0 ]).to.equal('playlist 3 updated')
980 expect(names3[ 1 ]).to.equal('playlist 2')
df0b219d
C
981 })
982
bfbd9128
C
983 it('Should delete some elements', async function () {
984 this.timeout(30000)
df0b219d 985
bfbd9128
C
986 await removeVideoFromPlaylist({
987 url: servers[ 0 ].url,
988 token: servers[ 0 ].accessToken,
989 playlistId: playlistServer1Id,
990 playlistElementId: playlistElementServer1Video4
991 })
df0b219d 992
bfbd9128
C
993 await removeVideoFromPlaylist({
994 url: servers[ 0 ].url,
995 token: servers[ 0 ].accessToken,
996 playlistId: playlistServer1Id,
997 playlistElementId: playlistElementNSFW
998 })
df0b219d 999
bfbd9128 1000 await waitJobs(servers)
df0b219d 1001
bfbd9128
C
1002 for (const server of servers) {
1003 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
418d092a 1004
bfbd9128 1005 expect(res.body.total).to.equal(4)
df0b219d 1006
bfbd9128
C
1007 const elements: VideoPlaylistElement[] = res.body.data
1008 expect(elements).to.have.lengthOf(4)
df0b219d 1009
bfbd9128
C
1010 expect(elements[ 0 ].video.name).to.equal('video 0 server 1')
1011 expect(elements[ 0 ].position).to.equal(1)
df0b219d 1012
bfbd9128
C
1013 expect(elements[ 1 ].video.name).to.equal('video 2 server 3')
1014 expect(elements[ 1 ].position).to.equal(2)
418d092a 1015
bfbd9128
C
1016 expect(elements[ 2 ].video.name).to.equal('video 1 server 3')
1017 expect(elements[ 2 ].position).to.equal(3)
1b319b7a 1018
bfbd9128
C
1019 expect(elements[ 3 ].video.name).to.equal('video 4 server 1')
1020 expect(elements[ 3 ].position).to.equal(4)
1b319b7a
C
1021 }
1022 })
1b319b7a 1023
bfbd9128
C
1024 it('Should be able to create a public playlist, and set it to private', async function () {
1025 this.timeout(30000)
1b319b7a 1026
bfbd9128
C
1027 const res = await createVideoPlaylist({
1028 url: servers[ 0 ].url,
1029 token: servers[ 0 ].accessToken,
1030 playlistAttrs: {
1031 displayName: 'my super public playlist',
1032 privacy: VideoPlaylistPrivacy.PUBLIC,
1033 videoChannelId: servers[ 0 ].videoChannel.id
1034 }
1035 })
1036 const videoPlaylistIds = res.body.videoPlaylist
1b319b7a 1037
bfbd9128 1038 await waitJobs(servers)
1b319b7a 1039
bfbd9128
C
1040 for (const server of servers) {
1041 await getVideoPlaylist(server.url, videoPlaylistIds.uuid, 200)
1042 }
1b319b7a 1043
bfbd9128
C
1044 const playlistAttrs = { privacy: VideoPlaylistPrivacy.PRIVATE }
1045 await updateVideoPlaylist({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, playlistId: videoPlaylistIds.id, playlistAttrs })
1b319b7a 1046
bfbd9128 1047 await waitJobs(servers)
1b319b7a 1048
bfbd9128
C
1049 for (const server of [ servers[ 1 ], servers[ 2 ] ]) {
1050 await getVideoPlaylist(server.url, videoPlaylistIds.uuid, 404)
1051 }
1052 await getVideoPlaylist(servers[ 0 ].url, videoPlaylistIds.uuid, 401)
418d092a 1053
bfbd9128
C
1054 await getVideoPlaylistWithToken(servers[ 0 ].url, servers[ 0 ].accessToken, videoPlaylistIds.uuid, 200)
1055 })
1056 })
df0b219d 1057
bfbd9128 1058 describe('Playlist deletion', function () {
df0b219d 1059
bfbd9128
C
1060 it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () {
1061 this.timeout(30000)
418d092a 1062
bfbd9128 1063 await deleteVideoPlaylist(servers[ 0 ].url, servers[ 0 ].accessToken, playlistServer1Id)
418d092a 1064
bfbd9128 1065 await waitJobs(servers)
418d092a 1066
bfbd9128
C
1067 for (const server of servers) {
1068 await getVideoPlaylist(server.url, playlistServer1UUID, 404)
1069 }
1070 })
418d092a 1071
bfbd9128
C
1072 it('Should have deleted the thumbnail on server 1, 2 and 3', async function () {
1073 this.timeout(30000)
df0b219d 1074
bfbd9128
C
1075 for (const server of servers) {
1076 await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.internalServerNumber)
1077 }
1078 })
df0b219d 1079
bfbd9128
C
1080 it('Should unfollow servers 1 and 2 and hide their playlists', async function () {
1081 this.timeout(30000)
df0b219d 1082
bfbd9128 1083 const finder = data => data.find(p => p.displayName === 'my super playlist')
df0b219d 1084
bfbd9128
C
1085 {
1086 const res = await getVideoPlaylistsList(servers[ 2 ].url, 0, 5)
1087 expect(res.body.total).to.equal(3)
1088 expect(finder(res.body.data)).to.not.be.undefined
1089 }
418d092a 1090
bfbd9128 1091 await unfollow(servers[ 2 ].url, servers[ 2 ].accessToken, servers[ 0 ])
df0b219d 1092
bfbd9128
C
1093 {
1094 const res = await getVideoPlaylistsList(servers[ 2 ].url, 0, 5)
1095 expect(res.body.total).to.equal(1)
418d092a 1096
bfbd9128 1097 expect(finder(res.body.data)).to.be.undefined
df0b219d
C
1098 }
1099 })
df0b219d 1100
bfbd9128
C
1101 it('Should delete a channel and put the associated playlist in private mode', async function () {
1102 this.timeout(30000)
df0b219d 1103
bfbd9128
C
1104 const res = await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'super_channel', displayName: 'super channel' })
1105 const videoChannelId = res.body.videoChannel.id
df0b219d 1106
bfbd9128
C
1107 const res2 = await createVideoPlaylist({
1108 url: servers[ 0 ].url,
1109 token: servers[ 0 ].accessToken,
1110 playlistAttrs: {
1111 displayName: 'channel playlist',
1112 privacy: VideoPlaylistPrivacy.PUBLIC,
1113 videoChannelId
1114 }
1115 })
1116 const videoPlaylistUUID = res2.body.videoPlaylist.uuid
1117
1118 await waitJobs(servers)
df0b219d 1119
bfbd9128 1120 await deleteVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, 'super_channel')
df0b219d 1121
bfbd9128 1122 await waitJobs(servers)
418d092a 1123
bfbd9128
C
1124 const res3 = await getVideoPlaylistWithToken(servers[ 0 ].url, servers[ 0 ].accessToken, videoPlaylistUUID)
1125 expect(res3.body.displayName).to.equal('channel playlist')
1126 expect(res3.body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE)
df0b219d 1127
bfbd9128 1128 await getVideoPlaylist(servers[ 1 ].url, videoPlaylistUUID, 404)
1eddc9a7 1129 })
df0b219d 1130
bfbd9128
C
1131 it('Should delete an account and delete its playlists', async function () {
1132 this.timeout(30000)
418d092a 1133
bfbd9128
C
1134 const user = { username: 'user_1', password: 'password' }
1135 const res = await createUser({
1136 url: servers[ 0 ].url,
1137 accessToken: servers[ 0 ].accessToken,
1138 username: user.username,
1139 password: user.password
1140 })
397d78fb 1141
bfbd9128
C
1142 const userId = res.body.user.id
1143 const userAccessToken = await userLogin(servers[ 0 ], user)
df0b219d 1144
bfbd9128
C
1145 const resChannel = await getMyUserInformation(servers[ 0 ].url, userAccessToken)
1146 const userChannel = (resChannel.body as User).videoChannels[ 0 ]
df0b219d 1147
bfbd9128
C
1148 await createVideoPlaylist({
1149 url: servers[ 0 ].url,
1150 token: userAccessToken,
1151 playlistAttrs: {
1152 displayName: 'playlist to be deleted',
1153 privacy: VideoPlaylistPrivacy.PUBLIC,
1154 videoChannelId: userChannel.id
1155 }
1156 })
df0b219d 1157
bfbd9128
C
1158 await waitJobs(servers)
1159
1160 const finder = data => data.find(p => p.displayName === 'playlist to be deleted')
1161
1162 {
1163 for (const server of [ servers[ 0 ], servers[ 1 ] ]) {
1164 const res = await getVideoPlaylistsList(server.url, 0, 15)
1165 expect(finder(res.body.data)).to.not.be.undefined
1166 }
df0b219d 1167 }
df0b219d 1168
bfbd9128
C
1169 await removeUser(servers[ 0 ].url, userId, servers[ 0 ].accessToken)
1170 await waitJobs(servers)
df0b219d 1171
bfbd9128
C
1172 {
1173 for (const server of [ servers[ 0 ], servers[ 1 ] ]) {
1174 const res = await getVideoPlaylistsList(server.url, 0, 15)
1175 expect(finder(res.body.data)).to.be.undefined
1176 }
df0b219d 1177 }
bfbd9128 1178 })
418d092a
C
1179 })
1180
7c3b7976
C
1181 after(async function () {
1182 await cleanupTests(servers)
418d092a
C
1183 })
1184})