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