1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { testImage } from '@server/tests/shared'
6 import { VideoPlaylistPrivacy } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
15 } from '@shared/server-commands'
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)
50 // Get the access tokens
51 await setAccessTokensToServers(servers)
52 await setDefaultVideoChannel(servers)
54 for (const server of servers) {
55 await server.config.disableTranscoding()
58 // Server 1 and server 2 follow each other
59 await doubleFollow(servers[0], servers[1])
61 video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).id
62 video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).id
64 await waitJobs(servers)
67 it('Should automatically update the thumbnail when adding an element', async function () {
70 const created = await servers[1].playlists.create({
72 displayName: 'playlist without thumbnail',
73 privacy: VideoPlaylistPrivacy.PUBLIC,
74 videoChannelId: servers[1].store.channel.id
77 playlistWithoutThumbnailId = created.id
79 const added = await servers[1].playlists.addElement({
80 playlistId: playlistWithoutThumbnailId,
81 attributes: { videoId: video1 }
83 withoutThumbnailE1 = added.id
85 await waitJobs(servers)
87 for (const server of servers) {
88 const p = await getPlaylistWithoutThumbnail(server)
89 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
93 it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () {
96 const created = await servers[1].playlists.create({
98 displayName: 'playlist with thumbnail',
99 privacy: VideoPlaylistPrivacy.PUBLIC,
100 videoChannelId: servers[1].store.channel.id,
101 thumbnailfile: 'thumbnail.jpg'
104 playlistWithThumbnailId = created.id
106 const added = await servers[1].playlists.addElement({
107 playlistId: playlistWithThumbnailId,
108 attributes: { videoId: video1 }
110 withThumbnailE1 = added.id
112 await waitJobs(servers)
114 for (const server of servers) {
115 const p = await getPlaylistWithThumbnail(server)
116 await testImage(server.url, 'thumbnail', p.thumbnailPath)
120 it('Should automatically update the thumbnail when moving the first element', async function () {
123 const added = await servers[1].playlists.addElement({
124 playlistId: playlistWithoutThumbnailId,
125 attributes: { videoId: video2 }
127 withoutThumbnailE2 = added.id
129 await servers[1].playlists.reorderElements({
130 playlistId: playlistWithoutThumbnailId,
133 insertAfterPosition: 2
137 await waitJobs(servers)
139 for (const server of servers) {
140 const p = await getPlaylistWithoutThumbnail(server)
141 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
145 it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () {
148 const added = await servers[1].playlists.addElement({
149 playlistId: playlistWithThumbnailId,
150 attributes: { videoId: video2 }
152 withThumbnailE2 = added.id
154 await servers[1].playlists.reorderElements({
155 playlistId: playlistWithThumbnailId,
158 insertAfterPosition: 2
162 await waitJobs(servers)
164 for (const server of servers) {
165 const p = await getPlaylistWithThumbnail(server)
166 await testImage(server.url, 'thumbnail', p.thumbnailPath)
170 it('Should automatically update the thumbnail when deleting the first element', async function () {
173 await servers[1].playlists.removeElement({
174 playlistId: playlistWithoutThumbnailId,
175 elementId: withoutThumbnailE1
178 await waitJobs(servers)
180 for (const server of servers) {
181 const p = await getPlaylistWithoutThumbnail(server)
182 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
186 it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () {
189 await servers[1].playlists.removeElement({
190 playlistId: playlistWithThumbnailId,
191 elementId: withThumbnailE1
194 await waitJobs(servers)
196 for (const server of servers) {
197 const p = await getPlaylistWithThumbnail(server)
198 await testImage(server.url, 'thumbnail', p.thumbnailPath)
202 it('Should the thumbnail when we delete the last element', async function () {
205 await servers[1].playlists.removeElement({
206 playlistId: playlistWithoutThumbnailId,
207 elementId: withoutThumbnailE2
210 await waitJobs(servers)
212 for (const server of servers) {
213 const p = await getPlaylistWithoutThumbnail(server)
214 expect(p.thumbnailPath).to.be.null
218 it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () {
221 await servers[1].playlists.removeElement({
222 playlistId: playlistWithThumbnailId,
223 elementId: withThumbnailE2
226 await waitJobs(servers)
228 for (const server of servers) {
229 const p = await getPlaylistWithThumbnail(server)
230 await testImage(server.url, 'thumbnail', p.thumbnailPath)
234 after(async function () {
235 await cleanupTests(servers)