1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { testImage } from '@server/tests/shared'
5 import { VideoPlaylistPrivacy } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
14 } from '@shared/server-commands'
16 const expect = chai.expect
18 describe('Playlist thumbnail', function () {
19 let servers: PeerTubeServer[] = []
21 let playlistWithoutThumbnailId: number
22 let playlistWithThumbnailId: number
24 let withThumbnailE1: number
25 let withThumbnailE2: number
26 let withoutThumbnailE1: number
27 let withoutThumbnailE2: number
32 async function getPlaylistWithoutThumbnail (server: PeerTubeServer) {
33 const body = await server.playlists.list({ start: 0, count: 10 })
35 return body.data.find(p => p.displayName === 'playlist without thumbnail')
38 async function getPlaylistWithThumbnail (server: PeerTubeServer) {
39 const body = await server.playlists.list({ start: 0, count: 10 })
41 return body.data.find(p => p.displayName === 'playlist with thumbnail')
44 before(async function () {
47 servers = await createMultipleServers(2)
49 // Get the access tokens
50 await setAccessTokensToServers(servers)
51 await setDefaultVideoChannel(servers)
53 for (const server of servers) {
54 await server.config.disableTranscoding()
57 // Server 1 and server 2 follow each other
58 await doubleFollow(servers[0], servers[1])
60 video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).id
61 video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).id
63 await waitJobs(servers)
66 it('Should automatically update the thumbnail when adding an element', async function () {
69 const created = await servers[1].playlists.create({
71 displayName: 'playlist without thumbnail',
72 privacy: VideoPlaylistPrivacy.PUBLIC,
73 videoChannelId: servers[1].store.channel.id
76 playlistWithoutThumbnailId = created.id
78 const added = await servers[1].playlists.addElement({
79 playlistId: playlistWithoutThumbnailId,
80 attributes: { videoId: video1 }
82 withoutThumbnailE1 = added.id
84 await waitJobs(servers)
86 for (const server of servers) {
87 const p = await getPlaylistWithoutThumbnail(server)
88 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
92 it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () {
95 const created = await servers[1].playlists.create({
97 displayName: 'playlist with thumbnail',
98 privacy: VideoPlaylistPrivacy.PUBLIC,
99 videoChannelId: servers[1].store.channel.id,
100 thumbnailfile: 'thumbnail.jpg'
103 playlistWithThumbnailId = created.id
105 const added = await servers[1].playlists.addElement({
106 playlistId: playlistWithThumbnailId,
107 attributes: { videoId: video1 }
109 withThumbnailE1 = added.id
111 await waitJobs(servers)
113 for (const server of servers) {
114 const p = await getPlaylistWithThumbnail(server)
115 await testImage(server.url, 'thumbnail', p.thumbnailPath)
119 it('Should automatically update the thumbnail when moving the first element', async function () {
122 const added = await servers[1].playlists.addElement({
123 playlistId: playlistWithoutThumbnailId,
124 attributes: { videoId: video2 }
126 withoutThumbnailE2 = added.id
128 await servers[1].playlists.reorderElements({
129 playlistId: playlistWithoutThumbnailId,
132 insertAfterPosition: 2
136 await waitJobs(servers)
138 for (const server of servers) {
139 const p = await getPlaylistWithoutThumbnail(server)
140 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
144 it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () {
147 const added = await servers[1].playlists.addElement({
148 playlistId: playlistWithThumbnailId,
149 attributes: { videoId: video2 }
151 withThumbnailE2 = added.id
153 await servers[1].playlists.reorderElements({
154 playlistId: playlistWithThumbnailId,
157 insertAfterPosition: 2
161 await waitJobs(servers)
163 for (const server of servers) {
164 const p = await getPlaylistWithThumbnail(server)
165 await testImage(server.url, 'thumbnail', p.thumbnailPath)
169 it('Should automatically update the thumbnail when deleting the first element', async function () {
172 await servers[1].playlists.removeElement({
173 playlistId: playlistWithoutThumbnailId,
174 elementId: withoutThumbnailE1
177 await waitJobs(servers)
179 for (const server of servers) {
180 const p = await getPlaylistWithoutThumbnail(server)
181 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
185 it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () {
188 await servers[1].playlists.removeElement({
189 playlistId: playlistWithThumbnailId,
190 elementId: withThumbnailE1
193 await waitJobs(servers)
195 for (const server of servers) {
196 const p = await getPlaylistWithThumbnail(server)
197 await testImage(server.url, 'thumbnail', p.thumbnailPath)
201 it('Should the thumbnail when we delete the last element', async function () {
204 await servers[1].playlists.removeElement({
205 playlistId: playlistWithoutThumbnailId,
206 elementId: withoutThumbnailE2
209 await waitJobs(servers)
211 for (const server of servers) {
212 const p = await getPlaylistWithoutThumbnail(server)
213 expect(p.thumbnailPath).to.be.null
217 it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () {
220 await servers[1].playlists.removeElement({
221 playlistId: playlistWithThumbnailId,
222 elementId: withThumbnailE2
225 await waitJobs(servers)
227 for (const server of servers) {
228 const p = await getPlaylistWithThumbnail(server)
229 await testImage(server.url, 'thumbnail', p.thumbnailPath)
233 after(async function () {
234 await cleanupTests(servers)