1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
10 flushAndRunMultipleServers,
11 getVideoPlaylistsList,
12 removeVideoFromPlaylist,
13 reorderVideosPlaylist,
15 setAccessTokensToServers,
16 setDefaultVideoChannel,
20 } from '../../../../shared/extra-utils'
21 import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
23 const expect = chai.expect
25 describe('Playlist thumbnail', function () {
26 let servers: ServerInfo[] = []
28 let playlistWithoutThumbnail: number
29 let playlistWithThumbnail: number
31 let withThumbnailE1: number
32 let withThumbnailE2: number
33 let withoutThumbnailE1: number
34 let withoutThumbnailE2: number
39 async function getPlaylistWithoutThumbnail (server: ServerInfo) {
40 const res = await getVideoPlaylistsList(server.url, 0, 10)
42 return res.body.data.find(p => p.displayName === 'playlist without thumbnail')
45 async function getPlaylistWithThumbnail (server: ServerInfo) {
46 const res = await getVideoPlaylistsList(server.url, 0, 10)
48 return res.body.data.find(p => p.displayName === 'playlist with thumbnail')
51 before(async function () {
54 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
56 // Get the access tokens
57 await setAccessTokensToServers(servers)
58 await setDefaultVideoChannel(servers)
60 // Server 1 and server 2 follow each other
61 await doubleFollow(servers[0], servers[1])
63 video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).id
64 video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).id
66 await waitJobs(servers)
69 it('Should automatically update the thumbnail when adding an element', async function () {
72 const res = await createVideoPlaylist({
74 token: servers[1].accessToken,
76 displayName: 'playlist without thumbnail',
77 privacy: VideoPlaylistPrivacy.PUBLIC,
78 videoChannelId: servers[1].videoChannel.id
81 playlistWithoutThumbnail = res.body.videoPlaylist.id
83 const res2 = await addVideoInPlaylist({
85 token: servers[1].accessToken,
86 playlistId: playlistWithoutThumbnail,
87 elementAttrs: { videoId: video1 }
89 withoutThumbnailE1 = res2.body.videoPlaylistElement.id
91 await waitJobs(servers)
93 for (const server of servers) {
94 const p = await getPlaylistWithoutThumbnail(server)
95 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
99 it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () {
102 const res = await createVideoPlaylist({
104 token: servers[1].accessToken,
106 displayName: 'playlist with thumbnail',
107 privacy: VideoPlaylistPrivacy.PUBLIC,
108 videoChannelId: servers[1].videoChannel.id,
109 thumbnailfile: 'thumbnail.jpg'
112 playlistWithThumbnail = res.body.videoPlaylist.id
114 const res2 = await addVideoInPlaylist({
116 token: servers[1].accessToken,
117 playlistId: playlistWithThumbnail,
118 elementAttrs: { videoId: video1 }
120 withThumbnailE1 = res2.body.videoPlaylistElement.id
122 await waitJobs(servers)
124 for (const server of servers) {
125 const p = await getPlaylistWithThumbnail(server)
126 await testImage(server.url, 'thumbnail', p.thumbnailPath)
130 it('Should automatically update the thumbnail when moving the first element', async function () {
133 const res = await addVideoInPlaylist({
135 token: servers[1].accessToken,
136 playlistId: playlistWithoutThumbnail,
137 elementAttrs: { videoId: video2 }
139 withoutThumbnailE2 = res.body.videoPlaylistElement.id
141 await reorderVideosPlaylist({
143 token: servers[1].accessToken,
144 playlistId: playlistWithoutThumbnail,
147 insertAfterPosition: 2
151 await waitJobs(servers)
153 for (const server of servers) {
154 const p = await getPlaylistWithoutThumbnail(server)
155 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
159 it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () {
162 const res = await addVideoInPlaylist({
164 token: servers[1].accessToken,
165 playlistId: playlistWithThumbnail,
166 elementAttrs: { videoId: video2 }
168 withThumbnailE2 = res.body.videoPlaylistElement.id
170 await reorderVideosPlaylist({
172 token: servers[1].accessToken,
173 playlistId: playlistWithThumbnail,
176 insertAfterPosition: 2
180 await waitJobs(servers)
182 for (const server of servers) {
183 const p = await getPlaylistWithThumbnail(server)
184 await testImage(server.url, 'thumbnail', p.thumbnailPath)
188 it('Should automatically update the thumbnail when deleting the first element', async function () {
191 await removeVideoFromPlaylist({
193 token: servers[1].accessToken,
194 playlistId: playlistWithoutThumbnail,
195 playlistElementId: withoutThumbnailE1
198 await waitJobs(servers)
200 for (const server of servers) {
201 const p = await getPlaylistWithoutThumbnail(server)
202 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
206 it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () {
209 await removeVideoFromPlaylist({
211 token: servers[1].accessToken,
212 playlistId: playlistWithThumbnail,
213 playlistElementId: withThumbnailE1
216 await waitJobs(servers)
218 for (const server of servers) {
219 const p = await getPlaylistWithThumbnail(server)
220 await testImage(server.url, 'thumbnail', p.thumbnailPath)
224 it('Should the thumbnail when we delete the last element', async function () {
227 await removeVideoFromPlaylist({
229 token: servers[1].accessToken,
230 playlistId: playlistWithoutThumbnail,
231 playlistElementId: withoutThumbnailE2
234 await waitJobs(servers)
236 for (const server of servers) {
237 const p = await getPlaylistWithoutThumbnail(server)
238 expect(p.thumbnailPath).to.be.null
242 it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () {
245 await removeVideoFromPlaylist({
247 token: servers[1].accessToken,
248 playlistId: playlistWithThumbnail,
249 playlistElementId: withThumbnailE2
252 await waitJobs(servers)
254 for (const server of servers) {
255 const p = await getPlaylistWithThumbnail(server)
256 await testImage(server.url, 'thumbnail', p.thumbnailPath)
260 after(async function () {
261 await cleanupTests(servers)