]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
418d092a C |
2 | |
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
418d092a C |
5 | import { |
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 |
46 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' |
47 | import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model' | |
bfbd9128 | 48 | import { VideoPrivacy } from '../../../../shared/models/videos' |
df0b219d | 49 | import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' |
0b16f5f2 | 50 | import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' |
397d78fb | 51 | import { User } from '../../../../shared/models/users' |
bfbd9128 C |
52 | import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../../shared/models/videos/playlist/video-playlist-element.model' |
53 | import { | |
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 | |
64 | const expect = chai.expect | |
65 | ||
bfbd9128 C |
66 | async 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 |
90 | describe('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 | |
555 | } | |
df0b219d | 556 | |
bfbd9128 C |
557 | await waitJobs(servers) |
558 | }) | |
df0b219d | 559 | |
bfbd9128 C |
560 | it('Should correctly list playlist videos', async function () { |
561 | this.timeout(30000) | |
df0b219d | 562 | |
bfbd9128 C |
563 | for (const server of servers) { |
564 | const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) | |
418d092a | 565 | |
bfbd9128 | 566 | expect(res.body.total).to.equal(6) |
df0b219d | 567 | |
bfbd9128 C |
568 | const videoElements: VideoPlaylistElement[] = res.body.data |
569 | expect(videoElements).to.have.lengthOf(6) | |
df0b219d | 570 | |
a1587156 C |
571 | expect(videoElements[0].video.name).to.equal('video 0 server 1') |
572 | expect(videoElements[0].position).to.equal(1) | |
573 | expect(videoElements[0].startTimestamp).to.equal(15) | |
574 | expect(videoElements[0].stopTimestamp).to.equal(28) | |
df0b219d | 575 | |
a1587156 C |
576 | expect(videoElements[1].video.name).to.equal('video 1 server 3') |
577 | expect(videoElements[1].position).to.equal(2) | |
578 | expect(videoElements[1].startTimestamp).to.equal(35) | |
579 | expect(videoElements[1].stopTimestamp).to.be.null | |
df0b219d | 580 | |
a1587156 C |
581 | expect(videoElements[2].video.name).to.equal('video 2 server 3') |
582 | expect(videoElements[2].position).to.equal(3) | |
583 | expect(videoElements[2].startTimestamp).to.be.null | |
584 | expect(videoElements[2].stopTimestamp).to.be.null | |
df0b219d | 585 | |
a1587156 C |
586 | expect(videoElements[3].video.name).to.equal('video 3 server 1') |
587 | expect(videoElements[3].position).to.equal(4) | |
588 | expect(videoElements[3].startTimestamp).to.be.null | |
589 | expect(videoElements[3].stopTimestamp).to.equal(35) | |
df0b219d | 590 | |
a1587156 C |
591 | expect(videoElements[4].video.name).to.equal('video 4 server 1') |
592 | expect(videoElements[4].position).to.equal(5) | |
593 | expect(videoElements[4].startTimestamp).to.equal(45) | |
594 | expect(videoElements[4].stopTimestamp).to.equal(60) | |
418d092a | 595 | |
a1587156 C |
596 | expect(videoElements[5].video.name).to.equal('NSFW video') |
597 | expect(videoElements[5].position).to.equal(6) | |
598 | expect(videoElements[5].startTimestamp).to.equal(5) | |
599 | expect(videoElements[5].stopTimestamp).to.be.null | |
df0b219d | 600 | |
bfbd9128 C |
601 | const res3 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 2) |
602 | expect(res3.body.data).to.have.lengthOf(2) | |
df0b219d C |
603 | } |
604 | }) | |
bfbd9128 | 605 | }) |
df0b219d | 606 | |
bfbd9128 C |
607 | describe('Element type', function () { |
608 | let groupUser1: ServerInfo[] | |
609 | let groupWithoutToken1: ServerInfo[] | |
610 | let group1: ServerInfo[] | |
611 | let group2: ServerInfo[] | |
df0b219d | 612 | |
bfbd9128 C |
613 | let video1: string |
614 | let video2: string | |
615 | let video3: string | |
df0b219d | 616 | |
bfbd9128 C |
617 | before(async function () { |
618 | this.timeout(30000) | |
df0b219d | 619 | |
a1587156 C |
620 | groupUser1 = [ Object.assign({}, servers[0], { accessToken: userAccessTokenServer1 }) ] |
621 | groupWithoutToken1 = [ Object.assign({}, servers[0], { accessToken: undefined }) ] | |
622 | group1 = [ servers[0] ] | |
623 | group2 = [ servers[1], servers[2] ] | |
df0b219d | 624 | |
bfbd9128 | 625 | const res = await createVideoPlaylist({ |
a1587156 | 626 | url: servers[0].url, |
bfbd9128 C |
627 | token: userAccessTokenServer1, |
628 | playlistAttrs: { | |
629 | displayName: 'playlist 56', | |
630 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
a1587156 | 631 | videoChannelId: servers[0].videoChannel.id |
bfbd9128 C |
632 | } |
633 | }) | |
418d092a | 634 | |
bfbd9128 C |
635 | const playlistServer1Id2 = res.body.videoPlaylist.id |
636 | playlistServer1UUID2 = res.body.videoPlaylist.uuid | |
df0b219d | 637 | |
bfbd9128 | 638 | const addVideo = (elementAttrs: any) => { |
a1587156 | 639 | return addVideoInPlaylist({ url: servers[0].url, token: userAccessTokenServer1, playlistId: playlistServer1Id2, elementAttrs }) |
bfbd9128 | 640 | } |
df0b219d | 641 | |
bfbd9128 C |
642 | video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userAccessTokenServer1 })).uuid |
643 | video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid | |
644 | video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid | |
df0b219d | 645 | |
bfbd9128 C |
646 | await addVideo({ videoId: video1, startTimestamp: 15, stopTimestamp: 28 }) |
647 | await addVideo({ videoId: video2, startTimestamp: 35 }) | |
648 | await addVideo({ videoId: video3 }) | |
df0b219d | 649 | |
bfbd9128 C |
650 | await waitJobs(servers) |
651 | }) | |
df0b219d | 652 | |
bfbd9128 C |
653 | it('Should update the element type if the video is private', async function () { |
654 | this.timeout(20000) | |
df0b219d | 655 | |
bfbd9128 C |
656 | const name = 'video 89' |
657 | const position = 1 | |
df0b219d | 658 | |
bfbd9128 | 659 | { |
a1587156 | 660 | await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PRIVATE }) |
bfbd9128 | 661 | await waitJobs(servers) |
418d092a | 662 | |
bfbd9128 C |
663 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
664 | await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.PRIVATE, position, name, 3) | |
665 | await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.PRIVATE, position, name, 3) | |
666 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3) | |
667 | } | |
df0b219d | 668 | |
bfbd9128 | 669 | { |
a1587156 | 670 | await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PUBLIC }) |
bfbd9128 | 671 | await waitJobs(servers) |
418d092a | 672 | |
bfbd9128 C |
673 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
674 | await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | |
675 | await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | |
676 | // We deleted the video, so even if we recreated it, the old entry is still deleted | |
677 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3) | |
df0b219d C |
678 | } |
679 | }) | |
680 | ||
bfbd9128 C |
681 | it('Should update the element type if the video is blacklisted', async function () { |
682 | this.timeout(20000) | |
df0b219d | 683 | |
bfbd9128 C |
684 | const name = 'video 89' |
685 | const position = 1 | |
df0b219d | 686 | |
bfbd9128 | 687 | { |
a1587156 | 688 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video1, 'reason', true) |
bfbd9128 | 689 | await waitJobs(servers) |
418d092a | 690 | |
bfbd9128 C |
691 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
692 | await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) | |
693 | await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) | |
694 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3) | |
695 | } | |
df0b219d | 696 | |
bfbd9128 | 697 | { |
a1587156 | 698 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video1) |
bfbd9128 | 699 | await waitJobs(servers) |
df0b219d | 700 | |
bfbd9128 C |
701 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
702 | await checkPlaylistElementType(groupWithoutToken1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | |
703 | await checkPlaylistElementType(group1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | |
704 | // We deleted the video (because unfederated), so even if we recreated it, the old entry is still deleted | |
705 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.DELETED, position, name, 3) | |
706 | } | |
707 | }) | |
df0b219d | 708 | |
bfbd9128 C |
709 | it('Should update the element type if the account or server of the video is blocked', async function () { |
710 | this.timeout(90000) | |
df0b219d | 711 | |
bfbd9128 C |
712 | const name = 'video 90' |
713 | const position = 2 | |
df0b219d | 714 | |
bfbd9128 | 715 | { |
a1587156 | 716 | await addAccountToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port) |
bfbd9128 | 717 | await waitJobs(servers) |
df0b219d | 718 | |
bfbd9128 C |
719 | await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) |
720 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) | |
df0b219d | 721 | |
a1587156 | 722 | await removeAccountFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port) |
bfbd9128 | 723 | await waitJobs(servers) |
df0b219d | 724 | |
bfbd9128 C |
725 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
726 | } | |
df0b219d | 727 | |
bfbd9128 | 728 | { |
a1587156 | 729 | await addServerToAccountBlocklist(servers[0].url, userAccessTokenServer1, '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 removeServerFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port) |
bfbd9128 | 736 | await waitJobs(servers) |
418d092a | 737 | |
bfbd9128 C |
738 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
739 | } | |
df0b219d | 740 | |
bfbd9128 | 741 | { |
a1587156 | 742 | await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@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 removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port) |
bfbd9128 | 749 | await waitJobs(servers) |
df0b219d | 750 | |
bfbd9128 | 751 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
df0b219d | 752 | } |
df0b219d | 753 | |
bfbd9128 | 754 | { |
a1587156 | 755 | await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, '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 removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) |
bfbd9128 | 762 | await waitJobs(servers) |
df0b219d | 763 | |
bfbd9128 | 764 | await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) |
df0b219d | 765 | } |
bfbd9128 | 766 | }) |
df0b219d | 767 | |
bfbd9128 C |
768 | it('Should hide the video if it is NSFW', async function () { |
769 | const res = await getPlaylistVideos(servers[0].url, userAccessTokenServer1, playlistServer1UUID2, 0, 10, { nsfw: false }) | |
770 | expect(res.body.total).to.equal(3) | |
df0b219d | 771 | |
bfbd9128 C |
772 | const elements: VideoPlaylistElement[] = res.body.data |
773 | const element = elements.find(e => e.position === 3) | |
df0b219d | 774 | |
bfbd9128 C |
775 | expect(element).to.exist |
776 | expect(element.video).to.be.null | |
777 | expect(element.type).to.equal(VideoPlaylistElementType.UNAVAILABLE) | |
778 | }) | |
df0b219d | 779 | |
bfbd9128 | 780 | }) |
df0b219d | 781 | |
bfbd9128 C |
782 | describe('Managing playlist elements', function () { |
783 | ||
784 | it('Should reorder the playlist', async function () { | |
785 | this.timeout(30000) | |
786 | ||
787 | { | |
788 | await reorderVideosPlaylist({ | |
a1587156 C |
789 | url: servers[0].url, |
790 | token: servers[0].accessToken, | |
bfbd9128 C |
791 | playlistId: playlistServer1Id, |
792 | elementAttrs: { | |
793 | startPosition: 2, | |
794 | insertAfterPosition: 3 | |
795 | } | |
796 | }) | |
797 | ||
798 | await waitJobs(servers) | |
799 | ||
800 | for (const server of servers) { | |
801 | const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) | |
802 | const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name) | |
803 | ||
804 | expect(names).to.deep.equal([ | |
805 | 'video 0 server 1', | |
806 | 'video 2 server 3', | |
807 | 'video 1 server 3', | |
808 | 'video 3 server 1', | |
809 | 'video 4 server 1', | |
810 | 'NSFW video' | |
811 | ]) | |
df0b219d C |
812 | } |
813 | } | |
df0b219d | 814 | |
bfbd9128 C |
815 | { |
816 | await reorderVideosPlaylist({ | |
a1587156 C |
817 | url: servers[0].url, |
818 | token: servers[0].accessToken, | |
bfbd9128 C |
819 | playlistId: playlistServer1Id, |
820 | elementAttrs: { | |
821 | startPosition: 1, | |
822 | reorderLength: 3, | |
823 | insertAfterPosition: 4 | |
824 | } | |
825 | }) | |
826 | ||
827 | await waitJobs(servers) | |
828 | ||
829 | for (const server of servers) { | |
830 | const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) | |
831 | const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name) | |
832 | ||
833 | expect(names).to.deep.equal([ | |
834 | 'video 3 server 1', | |
835 | 'video 0 server 1', | |
836 | 'video 2 server 3', | |
837 | 'video 1 server 3', | |
838 | 'video 4 server 1', | |
839 | 'NSFW video' | |
840 | ]) | |
841 | } | |
df0b219d | 842 | } |
df0b219d | 843 | |
bfbd9128 C |
844 | { |
845 | await reorderVideosPlaylist({ | |
a1587156 C |
846 | url: servers[0].url, |
847 | token: servers[0].accessToken, | |
bfbd9128 C |
848 | playlistId: playlistServer1Id, |
849 | elementAttrs: { | |
850 | startPosition: 6, | |
851 | insertAfterPosition: 3 | |
852 | } | |
853 | }) | |
854 | ||
855 | await waitJobs(servers) | |
856 | ||
857 | for (const server of servers) { | |
858 | const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) | |
859 | const elements: VideoPlaylistElement[] = res.body.data | |
860 | const names = elements.map(v => v.video.name) | |
861 | ||
862 | expect(names).to.deep.equal([ | |
863 | 'video 3 server 1', | |
864 | 'video 0 server 1', | |
865 | 'video 2 server 3', | |
866 | 'NSFW video', | |
867 | 'video 1 server 3', | |
868 | 'video 4 server 1' | |
869 | ]) | |
870 | ||
871 | for (let i = 1; i <= elements.length; i++) { | |
a1587156 | 872 | expect(elements[i - 1].position).to.equal(i) |
bfbd9128 C |
873 | } |
874 | } | |
df0b219d C |
875 | } |
876 | }) | |
877 | ||
bfbd9128 C |
878 | it('Should update startTimestamp/endTimestamp of some elements', async function () { |
879 | this.timeout(30000) | |
880 | ||
881 | await updateVideoPlaylistElement({ | |
a1587156 C |
882 | url: servers[0].url, |
883 | token: servers[0].accessToken, | |
bfbd9128 C |
884 | playlistId: playlistServer1Id, |
885 | playlistElementId: playlistElementServer1Video4, | |
886 | elementAttrs: { | |
887 | startTimestamp: 1 | |
888 | } | |
889 | }) | |
df0b219d | 890 | |
bfbd9128 | 891 | await updateVideoPlaylistElement({ |
a1587156 C |
892 | url: servers[0].url, |
893 | token: servers[0].accessToken, | |
bfbd9128 C |
894 | playlistId: playlistServer1Id, |
895 | playlistElementId: playlistElementServer1Video5, | |
896 | elementAttrs: { | |
897 | stopTimestamp: null | |
898 | } | |
899 | }) | |
df0b219d | 900 | |
bfbd9128 | 901 | await waitJobs(servers) |
df0b219d | 902 | |
bfbd9128 C |
903 | for (const server of servers) { |
904 | const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) | |
905 | const elements: VideoPlaylistElement[] = res.body.data | |
418d092a | 906 | |
a1587156 C |
907 | expect(elements[0].video.name).to.equal('video 3 server 1') |
908 | expect(elements[0].position).to.equal(1) | |
909 | expect(elements[0].startTimestamp).to.equal(1) | |
910 | expect(elements[0].stopTimestamp).to.equal(35) | |
0b16f5f2 | 911 | |
a1587156 C |
912 | expect(elements[5].video.name).to.equal('video 4 server 1') |
913 | expect(elements[5].position).to.equal(6) | |
914 | expect(elements[5].startTimestamp).to.equal(45) | |
915 | expect(elements[5].stopTimestamp).to.be.null | |
bfbd9128 C |
916 | } |
917 | }) | |
0b16f5f2 | 918 | |
bfbd9128 C |
919 | it('Should check videos existence in my playlist', async function () { |
920 | const videoIds = [ | |
a1587156 | 921 | servers[0].videos[0].id, |
bfbd9128 | 922 | 42000, |
a1587156 | 923 | servers[0].videos[3].id, |
bfbd9128 | 924 | 43000, |
a1587156 | 925 | servers[0].videos[4].id |
bfbd9128 | 926 | ] |
a1587156 | 927 | const res = await doVideosExistInMyPlaylist(servers[0].url, servers[0].accessToken, videoIds) |
bfbd9128 C |
928 | const obj = res.body as VideoExistInPlaylist |
929 | ||
930 | { | |
a1587156 | 931 | const elem = obj[servers[0].videos[0].id] |
bfbd9128 | 932 | expect(elem).to.have.lengthOf(1) |
a1587156 C |
933 | expect(elem[0].playlistElementId).to.exist |
934 | expect(elem[0].playlistId).to.equal(playlistServer1Id) | |
935 | expect(elem[0].startTimestamp).to.equal(15) | |
936 | expect(elem[0].stopTimestamp).to.equal(28) | |
bfbd9128 | 937 | } |
0b16f5f2 | 938 | |
bfbd9128 | 939 | { |
a1587156 | 940 | const elem = obj[servers[0].videos[3].id] |
bfbd9128 | 941 | expect(elem).to.have.lengthOf(1) |
a1587156 C |
942 | expect(elem[0].playlistElementId).to.equal(playlistElementServer1Video4) |
943 | expect(elem[0].playlistId).to.equal(playlistServer1Id) | |
944 | expect(elem[0].startTimestamp).to.equal(1) | |
945 | expect(elem[0].stopTimestamp).to.equal(35) | |
bfbd9128 | 946 | } |
0b16f5f2 | 947 | |
bfbd9128 | 948 | { |
a1587156 | 949 | const elem = obj[servers[0].videos[4].id] |
bfbd9128 | 950 | expect(elem).to.have.lengthOf(1) |
a1587156 C |
951 | expect(elem[0].playlistId).to.equal(playlistServer1Id) |
952 | expect(elem[0].startTimestamp).to.equal(45) | |
953 | expect(elem[0].stopTimestamp).to.equal(null) | |
bfbd9128 | 954 | } |
0b16f5f2 | 955 | |
a1587156 C |
956 | expect(obj[42000]).to.have.lengthOf(0) |
957 | expect(obj[43000]).to.have.lengthOf(0) | |
bfbd9128 | 958 | }) |
2a10aab3 | 959 | |
bfbd9128 | 960 | it('Should automatically update updatedAt field of playlists', async function () { |
a1587156 C |
961 | const server = servers[1] |
962 | const videoId = servers[1].videos[5].id | |
2a10aab3 | 963 | |
bfbd9128 C |
964 | async function getPlaylistNames () { |
965 | const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, undefined, '-updatedAt') | |
2a10aab3 | 966 | |
bfbd9128 C |
967 | return (res.body.data as VideoPlaylist[]).map(p => p.displayName) |
968 | } | |
2a10aab3 | 969 | |
bfbd9128 C |
970 | const elementAttrs = { videoId } |
971 | const res1 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, elementAttrs }) | |
972 | const res2 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, elementAttrs }) | |
2a10aab3 | 973 | |
bfbd9128 C |
974 | const element1 = res1.body.videoPlaylistElement.id |
975 | const element2 = res2.body.videoPlaylistElement.id | |
2a10aab3 | 976 | |
bfbd9128 | 977 | const names1 = await getPlaylistNames() |
a1587156 C |
978 | expect(names1[0]).to.equal('playlist 3 updated') |
979 | expect(names1[1]).to.equal('playlist 2') | |
2a10aab3 | 980 | |
bfbd9128 C |
981 | await removeVideoFromPlaylist({ |
982 | url: server.url, | |
983 | token: server.accessToken, | |
984 | playlistId: playlistServer2Id1, | |
985 | playlistElementId: element1 | |
986 | }) | |
2a10aab3 | 987 | |
bfbd9128 | 988 | const names2 = await getPlaylistNames() |
a1587156 C |
989 | expect(names2[0]).to.equal('playlist 2') |
990 | expect(names2[1]).to.equal('playlist 3 updated') | |
2a10aab3 | 991 | |
bfbd9128 C |
992 | await removeVideoFromPlaylist({ |
993 | url: server.url, | |
994 | token: server.accessToken, | |
995 | playlistId: playlistServer2Id2, | |
996 | playlistElementId: element2 | |
997 | }) | |
df0b219d | 998 | |
bfbd9128 | 999 | const names3 = await getPlaylistNames() |
a1587156 C |
1000 | expect(names3[0]).to.equal('playlist 3 updated') |
1001 | expect(names3[1]).to.equal('playlist 2') | |
df0b219d C |
1002 | }) |
1003 | ||
bfbd9128 C |
1004 | it('Should delete some elements', async function () { |
1005 | this.timeout(30000) | |
df0b219d | 1006 | |
bfbd9128 | 1007 | await removeVideoFromPlaylist({ |
a1587156 C |
1008 | url: servers[0].url, |
1009 | token: servers[0].accessToken, | |
bfbd9128 C |
1010 | playlistId: playlistServer1Id, |
1011 | playlistElementId: playlistElementServer1Video4 | |
1012 | }) | |
df0b219d | 1013 | |
bfbd9128 | 1014 | await removeVideoFromPlaylist({ |
a1587156 C |
1015 | url: servers[0].url, |
1016 | token: servers[0].accessToken, | |
bfbd9128 C |
1017 | playlistId: playlistServer1Id, |
1018 | playlistElementId: playlistElementNSFW | |
1019 | }) | |
df0b219d | 1020 | |
bfbd9128 | 1021 | await waitJobs(servers) |
df0b219d | 1022 | |
bfbd9128 C |
1023 | for (const server of servers) { |
1024 | const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) | |
418d092a | 1025 | |
bfbd9128 | 1026 | expect(res.body.total).to.equal(4) |
df0b219d | 1027 | |
bfbd9128 C |
1028 | const elements: VideoPlaylistElement[] = res.body.data |
1029 | expect(elements).to.have.lengthOf(4) | |
df0b219d | 1030 | |
a1587156 C |
1031 | expect(elements[0].video.name).to.equal('video 0 server 1') |
1032 | expect(elements[0].position).to.equal(1) | |
df0b219d | 1033 | |
a1587156 C |
1034 | expect(elements[1].video.name).to.equal('video 2 server 3') |
1035 | expect(elements[1].position).to.equal(2) | |
418d092a | 1036 | |
a1587156 C |
1037 | expect(elements[2].video.name).to.equal('video 1 server 3') |
1038 | expect(elements[2].position).to.equal(3) | |
1b319b7a | 1039 | |
a1587156 C |
1040 | expect(elements[3].video.name).to.equal('video 4 server 1') |
1041 | expect(elements[3].position).to.equal(4) | |
1b319b7a C |
1042 | } |
1043 | }) | |
1b319b7a | 1044 | |
bfbd9128 C |
1045 | it('Should be able to create a public playlist, and set it to private', async function () { |
1046 | this.timeout(30000) | |
1b319b7a | 1047 | |
bfbd9128 | 1048 | const res = await createVideoPlaylist({ |
a1587156 C |
1049 | url: servers[0].url, |
1050 | token: servers[0].accessToken, | |
bfbd9128 C |
1051 | playlistAttrs: { |
1052 | displayName: 'my super public playlist', | |
1053 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
a1587156 | 1054 | videoChannelId: servers[0].videoChannel.id |
bfbd9128 C |
1055 | } |
1056 | }) | |
1057 | const videoPlaylistIds = res.body.videoPlaylist | |
1b319b7a | 1058 | |
bfbd9128 | 1059 | await waitJobs(servers) |
1b319b7a | 1060 | |
bfbd9128 C |
1061 | for (const server of servers) { |
1062 | await getVideoPlaylist(server.url, videoPlaylistIds.uuid, 200) | |
1063 | } | |
1b319b7a | 1064 | |
bfbd9128 | 1065 | const playlistAttrs = { privacy: VideoPlaylistPrivacy.PRIVATE } |
a1587156 | 1066 | await updateVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: videoPlaylistIds.id, playlistAttrs }) |
1b319b7a | 1067 | |
bfbd9128 | 1068 | await waitJobs(servers) |
1b319b7a | 1069 | |
a1587156 | 1070 | for (const server of [ servers[1], servers[2] ]) { |
bfbd9128 C |
1071 | await getVideoPlaylist(server.url, videoPlaylistIds.uuid, 404) |
1072 | } | |
a1587156 | 1073 | await getVideoPlaylist(servers[0].url, videoPlaylistIds.uuid, 401) |
418d092a | 1074 | |
a1587156 | 1075 | await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistIds.uuid, 200) |
bfbd9128 C |
1076 | }) |
1077 | }) | |
df0b219d | 1078 | |
bfbd9128 | 1079 | describe('Playlist deletion', function () { |
df0b219d | 1080 | |
bfbd9128 C |
1081 | it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () { |
1082 | this.timeout(30000) | |
418d092a | 1083 | |
a1587156 | 1084 | await deleteVideoPlaylist(servers[0].url, servers[0].accessToken, playlistServer1Id) |
418d092a | 1085 | |
bfbd9128 | 1086 | await waitJobs(servers) |
418d092a | 1087 | |
bfbd9128 C |
1088 | for (const server of servers) { |
1089 | await getVideoPlaylist(server.url, playlistServer1UUID, 404) | |
1090 | } | |
1091 | }) | |
418d092a | 1092 | |
bfbd9128 C |
1093 | it('Should have deleted the thumbnail on server 1, 2 and 3', async function () { |
1094 | this.timeout(30000) | |
df0b219d | 1095 | |
bfbd9128 C |
1096 | for (const server of servers) { |
1097 | await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.internalServerNumber) | |
1098 | } | |
1099 | }) | |
df0b219d | 1100 | |
bfbd9128 C |
1101 | it('Should unfollow servers 1 and 2 and hide their playlists', async function () { |
1102 | this.timeout(30000) | |
df0b219d | 1103 | |
bfbd9128 | 1104 | const finder = data => data.find(p => p.displayName === 'my super playlist') |
df0b219d | 1105 | |
bfbd9128 | 1106 | { |
a1587156 | 1107 | const res = await getVideoPlaylistsList(servers[2].url, 0, 5) |
bfbd9128 C |
1108 | expect(res.body.total).to.equal(3) |
1109 | expect(finder(res.body.data)).to.not.be.undefined | |
1110 | } | |
418d092a | 1111 | |
a1587156 | 1112 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) |
df0b219d | 1113 | |
bfbd9128 | 1114 | { |
a1587156 | 1115 | const res = await getVideoPlaylistsList(servers[2].url, 0, 5) |
bfbd9128 | 1116 | expect(res.body.total).to.equal(1) |
418d092a | 1117 | |
bfbd9128 | 1118 | expect(finder(res.body.data)).to.be.undefined |
df0b219d C |
1119 | } |
1120 | }) | |
df0b219d | 1121 | |
bfbd9128 C |
1122 | it('Should delete a channel and put the associated playlist in private mode', async function () { |
1123 | this.timeout(30000) | |
df0b219d | 1124 | |
a1587156 | 1125 | const res = await addVideoChannel(servers[0].url, servers[0].accessToken, { name: 'super_channel', displayName: 'super channel' }) |
bfbd9128 | 1126 | const videoChannelId = res.body.videoChannel.id |
df0b219d | 1127 | |
bfbd9128 | 1128 | const res2 = await createVideoPlaylist({ |
a1587156 C |
1129 | url: servers[0].url, |
1130 | token: servers[0].accessToken, | |
bfbd9128 C |
1131 | playlistAttrs: { |
1132 | displayName: 'channel playlist', | |
1133 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
1134 | videoChannelId | |
1135 | } | |
1136 | }) | |
1137 | const videoPlaylistUUID = res2.body.videoPlaylist.uuid | |
1138 | ||
1139 | await waitJobs(servers) | |
df0b219d | 1140 | |
a1587156 | 1141 | await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'super_channel') |
df0b219d | 1142 | |
bfbd9128 | 1143 | await waitJobs(servers) |
418d092a | 1144 | |
a1587156 | 1145 | const res3 = await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistUUID) |
bfbd9128 C |
1146 | expect(res3.body.displayName).to.equal('channel playlist') |
1147 | expect(res3.body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE) | |
df0b219d | 1148 | |
a1587156 | 1149 | await getVideoPlaylist(servers[1].url, videoPlaylistUUID, 404) |
1eddc9a7 | 1150 | }) |
df0b219d | 1151 | |
bfbd9128 C |
1152 | it('Should delete an account and delete its playlists', async function () { |
1153 | this.timeout(30000) | |
418d092a | 1154 | |
bfbd9128 C |
1155 | const user = { username: 'user_1', password: 'password' } |
1156 | const res = await createUser({ | |
a1587156 C |
1157 | url: servers[0].url, |
1158 | accessToken: servers[0].accessToken, | |
bfbd9128 C |
1159 | username: user.username, |
1160 | password: user.password | |
1161 | }) | |
397d78fb | 1162 | |
bfbd9128 | 1163 | const userId = res.body.user.id |
a1587156 | 1164 | const userAccessToken = await userLogin(servers[0], user) |
df0b219d | 1165 | |
a1587156 C |
1166 | const resChannel = await getMyUserInformation(servers[0].url, userAccessToken) |
1167 | const userChannel = (resChannel.body as User).videoChannels[0] | |
df0b219d | 1168 | |
bfbd9128 | 1169 | await createVideoPlaylist({ |
a1587156 | 1170 | url: servers[0].url, |
bfbd9128 C |
1171 | token: userAccessToken, |
1172 | playlistAttrs: { | |
1173 | displayName: 'playlist to be deleted', | |
1174 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
1175 | videoChannelId: userChannel.id | |
1176 | } | |
1177 | }) | |
df0b219d | 1178 | |
bfbd9128 C |
1179 | await waitJobs(servers) |
1180 | ||
1181 | const finder = data => data.find(p => p.displayName === 'playlist to be deleted') | |
1182 | ||
1183 | { | |
a1587156 | 1184 | for (const server of [ servers[0], servers[1] ]) { |
bfbd9128 C |
1185 | const res = await getVideoPlaylistsList(server.url, 0, 15) |
1186 | expect(finder(res.body.data)).to.not.be.undefined | |
1187 | } | |
df0b219d | 1188 | } |
df0b219d | 1189 | |
a1587156 | 1190 | await removeUser(servers[0].url, userId, servers[0].accessToken) |
bfbd9128 | 1191 | await waitJobs(servers) |
df0b219d | 1192 | |
bfbd9128 | 1193 | { |
a1587156 | 1194 | for (const server of [ servers[0], servers[1] ]) { |
bfbd9128 C |
1195 | const res = await getVideoPlaylistsList(server.url, 0, 15) |
1196 | expect(finder(res.body.data)).to.be.undefined | |
1197 | } | |
df0b219d | 1198 | } |
bfbd9128 | 1199 | }) |
418d092a C |
1200 | }) |
1201 | ||
7c3b7976 C |
1202 | after(async function () { |
1203 | await cleanupTests(servers) | |
418d092a C |
1204 | }) |
1205 | }) |