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