1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
10 flushAndRunMultipleServers,
11 getVideoPlaylistsList, removeVideoFromPlaylist,
13 setAccessTokensToServers,
14 setDefaultVideoChannel,
19 } from '../../../../shared/extra-utils'
20 import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
22 const expect = chai.expect
24 describe('Playlist thumbnail', function () {
25 let servers: ServerInfo[] = []
27 let playlistWithoutThumbnail: number
28 let playlistWithThumbnail: number
30 let withThumbnailE1: number
31 let withThumbnailE2: number
32 let withoutThumbnailE1: number
33 let withoutThumbnailE2: number
38 async function getPlaylistWithoutThumbnail (server: ServerInfo) {
39 const res = await getVideoPlaylistsList(server.url, 0, 10)
41 return res.body.data.find(p => p.displayName === 'playlist without thumbnail')
44 async function getPlaylistWithThumbnail (server: ServerInfo) {
45 const res = await getVideoPlaylistsList(server.url, 0, 10)
47 return res.body.data.find(p => p.displayName === 'playlist with thumbnail')
50 before(async function () {
53 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
55 // Get the access tokens
56 await setAccessTokensToServers(servers)
57 await setDefaultVideoChannel(servers)
59 // Server 1 and server 2 follow each other
60 await doubleFollow(servers[0], servers[1])
62 video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).id
63 video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).id
65 await waitJobs(servers)
68 it('Should automatically update the thumbnail when adding an element', async function () {
71 const res = await createVideoPlaylist({
72 url: servers[ 1 ].url,
73 token: servers[ 1 ].accessToken,
75 displayName: 'playlist without thumbnail',
76 privacy: VideoPlaylistPrivacy.PUBLIC,
77 videoChannelId: servers[ 1 ].videoChannel.id
80 playlistWithoutThumbnail = res.body.videoPlaylist.id
82 const res2 = await addVideoInPlaylist({
83 url: servers[ 1 ].url,
84 token: servers[ 1 ].accessToken,
85 playlistId: playlistWithoutThumbnail,
86 elementAttrs: { videoId: video1 }
88 withoutThumbnailE1 = res2.body.videoPlaylistElement.id
90 await waitJobs(servers)
92 for (const server of servers) {
93 const p = await getPlaylistWithoutThumbnail(server)
94 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
98 it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () {
101 const res = await createVideoPlaylist({
102 url: servers[ 1 ].url,
103 token: servers[ 1 ].accessToken,
105 displayName: 'playlist with thumbnail',
106 privacy: VideoPlaylistPrivacy.PUBLIC,
107 videoChannelId: servers[ 1 ].videoChannel.id,
108 thumbnailfile: 'thumbnail.jpg'
111 playlistWithThumbnail = res.body.videoPlaylist.id
113 const res2 = await addVideoInPlaylist({
114 url: servers[ 1 ].url,
115 token: servers[ 1 ].accessToken,
116 playlistId: playlistWithThumbnail,
117 elementAttrs: { videoId: video1 }
119 withThumbnailE1 = res2.body.videoPlaylistElement.id
121 await waitJobs(servers)
123 for (const server of servers) {
124 const p = await getPlaylistWithThumbnail(server)
125 await testImage(server.url, 'thumbnail', p.thumbnailPath)
129 it('Should automatically update the thumbnail when moving the first element', async function () {
132 const res = await addVideoInPlaylist({
133 url: servers[ 1 ].url,
134 token: servers[ 1 ].accessToken,
135 playlistId: playlistWithoutThumbnail,
136 elementAttrs: { videoId: video2 }
138 withoutThumbnailE2 = res.body.videoPlaylistElement.id
140 await reorderVideosPlaylist({
142 token: servers[1].accessToken,
143 playlistId: playlistWithoutThumbnail,
146 insertAfterPosition: 2
150 await waitJobs(servers)
152 for (const server of servers) {
153 const p = await getPlaylistWithoutThumbnail(server)
154 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
158 it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () {
161 const res = await addVideoInPlaylist({
162 url: servers[ 1 ].url,
163 token: servers[ 1 ].accessToken,
164 playlistId: playlistWithThumbnail,
165 elementAttrs: { videoId: video2 }
167 withThumbnailE2 = res.body.videoPlaylistElement.id
169 await reorderVideosPlaylist({
171 token: servers[1].accessToken,
172 playlistId: playlistWithThumbnail,
175 insertAfterPosition: 2
179 await waitJobs(servers)
181 for (const server of servers) {
182 const p = await getPlaylistWithThumbnail(server)
183 await testImage(server.url, 'thumbnail', p.thumbnailPath)
187 it('Should automatically update the thumbnail when deleting the first element', async function () {
190 await removeVideoFromPlaylist({
191 url: servers[ 1 ].url,
192 token: servers[ 1 ].accessToken,
193 playlistId: playlistWithoutThumbnail,
194 playlistElementId: withoutThumbnailE1
197 await waitJobs(servers)
199 for (const server of servers) {
200 const p = await getPlaylistWithoutThumbnail(server)
201 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
205 it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () {
208 await removeVideoFromPlaylist({
209 url: servers[ 1 ].url,
210 token: servers[ 1 ].accessToken,
211 playlistId: playlistWithThumbnail,
212 playlistElementId: withThumbnailE1
215 await waitJobs(servers)
217 for (const server of servers) {
218 const p = await getPlaylistWithThumbnail(server)
219 await testImage(server.url, 'thumbnail', p.thumbnailPath)
223 it('Should the thumbnail when we delete the last element', async function () {
226 await removeVideoFromPlaylist({
227 url: servers[ 1 ].url,
228 token: servers[ 1 ].accessToken,
229 playlistId: playlistWithoutThumbnail,
230 playlistElementId: withoutThumbnailE2
233 await waitJobs(servers)
235 for (const server of servers) {
236 const p = await getPlaylistWithoutThumbnail(server)
237 expect(p.thumbnailPath).to.be.null
241 it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () {
244 await removeVideoFromPlaylist({
245 url: servers[ 1 ].url,
246 token: servers[ 1 ].accessToken,
247 playlistId: playlistWithThumbnail,
248 playlistElementId: withThumbnailE2
251 await waitJobs(servers)
253 for (const server of servers) {
254 const p = await getPlaylistWithThumbnail(server)
255 await testImage(server.url, 'thumbnail', p.thumbnailPath)
259 after(async function () {
260 await cleanupTests(servers)