1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 setAccessTokensToServers,
11 setDefaultVideoChannel,
14 } from '../../../../shared/extra-utils'
15 import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
17 const expect = chai.expect
19 describe('Playlist thumbnail', function () {
20 let servers: PeerTubeServer[] = []
22 let playlistWithoutThumbnailId: number
23 let playlistWithThumbnailId: number
25 let withThumbnailE1: number
26 let withThumbnailE2: number
27 let withoutThumbnailE1: number
28 let withoutThumbnailE2: number
33 async function getPlaylistWithoutThumbnail (server: PeerTubeServer) {
34 const body = await server.playlists.list({ start: 0, count: 10 })
36 return body.data.find(p => p.displayName === 'playlist without thumbnail')
39 async function getPlaylistWithThumbnail (server: PeerTubeServer) {
40 const body = await server.playlists.list({ start: 0, count: 10 })
42 return body.data.find(p => p.displayName === 'playlist with thumbnail')
45 before(async function () {
48 servers = await createMultipleServers(2, { transcoding: { enabled: false } })
50 // Get the access tokens
51 await setAccessTokensToServers(servers)
52 await setDefaultVideoChannel(servers)
54 // Server 1 and server 2 follow each other
55 await doubleFollow(servers[0], servers[1])
57 video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).id
58 video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).id
60 await waitJobs(servers)
63 it('Should automatically update the thumbnail when adding an element', async function () {
66 const created = await servers[1].playlists.create({
68 displayName: 'playlist without thumbnail',
69 privacy: VideoPlaylistPrivacy.PUBLIC,
70 videoChannelId: servers[1].store.channel.id
73 playlistWithoutThumbnailId = created.id
75 const added = await servers[1].playlists.addElement({
76 playlistId: playlistWithoutThumbnailId,
77 attributes: { videoId: video1 }
79 withoutThumbnailE1 = added.id
81 await waitJobs(servers)
83 for (const server of servers) {
84 const p = await getPlaylistWithoutThumbnail(server)
85 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
89 it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () {
92 const created = await servers[1].playlists.create({
94 displayName: 'playlist with thumbnail',
95 privacy: VideoPlaylistPrivacy.PUBLIC,
96 videoChannelId: servers[1].store.channel.id,
97 thumbnailfile: 'thumbnail.jpg'
100 playlistWithThumbnailId = created.id
102 const added = await servers[1].playlists.addElement({
103 playlistId: playlistWithThumbnailId,
104 attributes: { videoId: video1 }
106 withThumbnailE1 = added.id
108 await waitJobs(servers)
110 for (const server of servers) {
111 const p = await getPlaylistWithThumbnail(server)
112 await testImage(server.url, 'thumbnail', p.thumbnailPath)
116 it('Should automatically update the thumbnail when moving the first element', async function () {
119 const added = await servers[1].playlists.addElement({
120 playlistId: playlistWithoutThumbnailId,
121 attributes: { videoId: video2 }
123 withoutThumbnailE2 = added.id
125 await servers[1].playlists.reorderElements({
126 playlistId: playlistWithoutThumbnailId,
129 insertAfterPosition: 2
133 await waitJobs(servers)
135 for (const server of servers) {
136 const p = await getPlaylistWithoutThumbnail(server)
137 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
141 it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () {
144 const added = await servers[1].playlists.addElement({
145 playlistId: playlistWithThumbnailId,
146 attributes: { videoId: video2 }
148 withThumbnailE2 = added.id
150 await servers[1].playlists.reorderElements({
151 playlistId: playlistWithThumbnailId,
154 insertAfterPosition: 2
158 await waitJobs(servers)
160 for (const server of servers) {
161 const p = await getPlaylistWithThumbnail(server)
162 await testImage(server.url, 'thumbnail', p.thumbnailPath)
166 it('Should automatically update the thumbnail when deleting the first element', async function () {
169 await servers[1].playlists.removeElement({
170 playlistId: playlistWithoutThumbnailId,
171 elementId: withoutThumbnailE1
174 await waitJobs(servers)
176 for (const server of servers) {
177 const p = await getPlaylistWithoutThumbnail(server)
178 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
182 it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () {
185 await servers[1].playlists.removeElement({
186 playlistId: playlistWithThumbnailId,
187 elementId: withThumbnailE1
190 await waitJobs(servers)
192 for (const server of servers) {
193 const p = await getPlaylistWithThumbnail(server)
194 await testImage(server.url, 'thumbnail', p.thumbnailPath)
198 it('Should the thumbnail when we delete the last element', async function () {
201 await servers[1].playlists.removeElement({
202 playlistId: playlistWithoutThumbnailId,
203 elementId: withoutThumbnailE2
206 await waitJobs(servers)
208 for (const server of servers) {
209 const p = await getPlaylistWithoutThumbnail(server)
210 expect(p.thumbnailPath).to.be.null
214 it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () {
217 await servers[1].playlists.removeElement({
218 playlistId: playlistWithThumbnailId,
219 elementId: withThumbnailE2
222 await waitJobs(servers)
224 for (const server of servers) {
225 const p = await getPlaylistWithThumbnail(server)
226 await testImage(server.url, 'thumbnail', p.thumbnailPath)
230 after(async function () {
231 await cleanupTests(servers)