1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } 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 describe('Playlist thumbnail', function () {
17 let servers: PeerTubeServer[] = []
19 let playlistWithoutThumbnailId: number
20 let playlistWithThumbnailId: number
22 let withThumbnailE1: number
23 let withThumbnailE2: number
24 let withoutThumbnailE1: number
25 let withoutThumbnailE2: number
30 async function getPlaylistWithoutThumbnail (server: PeerTubeServer) {
31 const body = await server.playlists.list({ start: 0, count: 10 })
33 return body.data.find(p => p.displayName === 'playlist without thumbnail')
36 async function getPlaylistWithThumbnail (server: PeerTubeServer) {
37 const body = await server.playlists.list({ start: 0, count: 10 })
39 return body.data.find(p => p.displayName === 'playlist with thumbnail')
42 before(async function () {
45 servers = await createMultipleServers(2)
47 // Get the access tokens
48 await setAccessTokensToServers(servers)
49 await setDefaultVideoChannel(servers)
51 for (const server of servers) {
52 await server.config.disableTranscoding()
55 // Server 1 and server 2 follow each other
56 await doubleFollow(servers[0], servers[1])
58 video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).id
59 video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).id
61 await waitJobs(servers)
64 it('Should automatically update the thumbnail when adding an element', async function () {
67 const created = await servers[1].playlists.create({
69 displayName: 'playlist without thumbnail',
70 privacy: VideoPlaylistPrivacy.PUBLIC,
71 videoChannelId: servers[1].store.channel.id
74 playlistWithoutThumbnailId = created.id
76 const added = await servers[1].playlists.addElement({
77 playlistId: playlistWithoutThumbnailId,
78 attributes: { videoId: video1 }
80 withoutThumbnailE1 = added.id
82 await waitJobs(servers)
84 for (const server of servers) {
85 const p = await getPlaylistWithoutThumbnail(server)
86 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
90 it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () {
93 const created = await servers[1].playlists.create({
95 displayName: 'playlist with thumbnail',
96 privacy: VideoPlaylistPrivacy.PUBLIC,
97 videoChannelId: servers[1].store.channel.id,
98 thumbnailfile: 'thumbnail.jpg'
101 playlistWithThumbnailId = created.id
103 const added = await servers[1].playlists.addElement({
104 playlistId: playlistWithThumbnailId,
105 attributes: { videoId: video1 }
107 withThumbnailE1 = added.id
109 await waitJobs(servers)
111 for (const server of servers) {
112 const p = await getPlaylistWithThumbnail(server)
113 await testImage(server.url, 'thumbnail', p.thumbnailPath)
117 it('Should automatically update the thumbnail when moving the first element', async function () {
120 const added = await servers[1].playlists.addElement({
121 playlistId: playlistWithoutThumbnailId,
122 attributes: { videoId: video2 }
124 withoutThumbnailE2 = added.id
126 await servers[1].playlists.reorderElements({
127 playlistId: playlistWithoutThumbnailId,
130 insertAfterPosition: 2
134 await waitJobs(servers)
136 for (const server of servers) {
137 const p = await getPlaylistWithoutThumbnail(server)
138 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
142 it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () {
145 const added = await servers[1].playlists.addElement({
146 playlistId: playlistWithThumbnailId,
147 attributes: { videoId: video2 }
149 withThumbnailE2 = added.id
151 await servers[1].playlists.reorderElements({
152 playlistId: playlistWithThumbnailId,
155 insertAfterPosition: 2
159 await waitJobs(servers)
161 for (const server of servers) {
162 const p = await getPlaylistWithThumbnail(server)
163 await testImage(server.url, 'thumbnail', p.thumbnailPath)
167 it('Should automatically update the thumbnail when deleting the first element', async function () {
170 await servers[1].playlists.removeElement({
171 playlistId: playlistWithoutThumbnailId,
172 elementId: withoutThumbnailE1
175 await waitJobs(servers)
177 for (const server of servers) {
178 const p = await getPlaylistWithoutThumbnail(server)
179 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
183 it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () {
186 await servers[1].playlists.removeElement({
187 playlistId: playlistWithThumbnailId,
188 elementId: withThumbnailE1
191 await waitJobs(servers)
193 for (const server of servers) {
194 const p = await getPlaylistWithThumbnail(server)
195 await testImage(server.url, 'thumbnail', p.thumbnailPath)
199 it('Should the thumbnail when we delete the last element', async function () {
202 await servers[1].playlists.removeElement({
203 playlistId: playlistWithoutThumbnailId,
204 elementId: withoutThumbnailE2
207 await waitJobs(servers)
209 for (const server of servers) {
210 const p = await getPlaylistWithoutThumbnail(server)
211 expect(p.thumbnailPath).to.be.null
215 it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () {
218 await servers[1].playlists.removeElement({
219 playlistId: playlistWithThumbnailId,
220 elementId: withThumbnailE2
223 await waitJobs(servers)
225 for (const server of servers) {
226 const p = await getPlaylistWithThumbnail(server)
227 await testImage(server.url, 'thumbnail', p.thumbnailPath)
231 after(async function () {
232 await cleanupTests(servers)