]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/video-playlist-thumbnails.ts
We don't need to import mocha
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-playlist-thumbnails.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import * as chai from 'chai'
4 import { testImage } from '@server/tests/shared'
5 import { VideoPlaylistPrivacy } from '@shared/models'
6 import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
13 waitJobs
14 } from '@shared/server-commands'
15
16 const expect = chai.expect
17
18 describe('Playlist thumbnail', function () {
19 let servers: PeerTubeServer[] = []
20
21 let playlistWithoutThumbnailId: number
22 let playlistWithThumbnailId: number
23
24 let withThumbnailE1: number
25 let withThumbnailE2: number
26 let withoutThumbnailE1: number
27 let withoutThumbnailE2: number
28
29 let video1: number
30 let video2: number
31
32 async function getPlaylistWithoutThumbnail (server: PeerTubeServer) {
33 const body = await server.playlists.list({ start: 0, count: 10 })
34
35 return body.data.find(p => p.displayName === 'playlist without thumbnail')
36 }
37
38 async function getPlaylistWithThumbnail (server: PeerTubeServer) {
39 const body = await server.playlists.list({ start: 0, count: 10 })
40
41 return body.data.find(p => p.displayName === 'playlist with thumbnail')
42 }
43
44 before(async function () {
45 this.timeout(120000)
46
47 servers = await createMultipleServers(2)
48
49 // Get the access tokens
50 await setAccessTokensToServers(servers)
51 await setDefaultVideoChannel(servers)
52
53 for (const server of servers) {
54 await server.config.disableTranscoding()
55 }
56
57 // Server 1 and server 2 follow each other
58 await doubleFollow(servers[0], servers[1])
59
60 video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).id
61 video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).id
62
63 await waitJobs(servers)
64 })
65
66 it('Should automatically update the thumbnail when adding an element', async function () {
67 this.timeout(30000)
68
69 const created = await servers[1].playlists.create({
70 attributes: {
71 displayName: 'playlist without thumbnail',
72 privacy: VideoPlaylistPrivacy.PUBLIC,
73 videoChannelId: servers[1].store.channel.id
74 }
75 })
76 playlistWithoutThumbnailId = created.id
77
78 const added = await servers[1].playlists.addElement({
79 playlistId: playlistWithoutThumbnailId,
80 attributes: { videoId: video1 }
81 })
82 withoutThumbnailE1 = added.id
83
84 await waitJobs(servers)
85
86 for (const server of servers) {
87 const p = await getPlaylistWithoutThumbnail(server)
88 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
89 }
90 })
91
92 it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () {
93 this.timeout(30000)
94
95 const created = await servers[1].playlists.create({
96 attributes: {
97 displayName: 'playlist with thumbnail',
98 privacy: VideoPlaylistPrivacy.PUBLIC,
99 videoChannelId: servers[1].store.channel.id,
100 thumbnailfile: 'thumbnail.jpg'
101 }
102 })
103 playlistWithThumbnailId = created.id
104
105 const added = await servers[1].playlists.addElement({
106 playlistId: playlistWithThumbnailId,
107 attributes: { videoId: video1 }
108 })
109 withThumbnailE1 = added.id
110
111 await waitJobs(servers)
112
113 for (const server of servers) {
114 const p = await getPlaylistWithThumbnail(server)
115 await testImage(server.url, 'thumbnail', p.thumbnailPath)
116 }
117 })
118
119 it('Should automatically update the thumbnail when moving the first element', async function () {
120 this.timeout(30000)
121
122 const added = await servers[1].playlists.addElement({
123 playlistId: playlistWithoutThumbnailId,
124 attributes: { videoId: video2 }
125 })
126 withoutThumbnailE2 = added.id
127
128 await servers[1].playlists.reorderElements({
129 playlistId: playlistWithoutThumbnailId,
130 attributes: {
131 startPosition: 1,
132 insertAfterPosition: 2
133 }
134 })
135
136 await waitJobs(servers)
137
138 for (const server of servers) {
139 const p = await getPlaylistWithoutThumbnail(server)
140 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
141 }
142 })
143
144 it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () {
145 this.timeout(30000)
146
147 const added = await servers[1].playlists.addElement({
148 playlistId: playlistWithThumbnailId,
149 attributes: { videoId: video2 }
150 })
151 withThumbnailE2 = added.id
152
153 await servers[1].playlists.reorderElements({
154 playlistId: playlistWithThumbnailId,
155 attributes: {
156 startPosition: 1,
157 insertAfterPosition: 2
158 }
159 })
160
161 await waitJobs(servers)
162
163 for (const server of servers) {
164 const p = await getPlaylistWithThumbnail(server)
165 await testImage(server.url, 'thumbnail', p.thumbnailPath)
166 }
167 })
168
169 it('Should automatically update the thumbnail when deleting the first element', async function () {
170 this.timeout(30000)
171
172 await servers[1].playlists.removeElement({
173 playlistId: playlistWithoutThumbnailId,
174 elementId: withoutThumbnailE1
175 })
176
177 await waitJobs(servers)
178
179 for (const server of servers) {
180 const p = await getPlaylistWithoutThumbnail(server)
181 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
182 }
183 })
184
185 it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () {
186 this.timeout(30000)
187
188 await servers[1].playlists.removeElement({
189 playlistId: playlistWithThumbnailId,
190 elementId: withThumbnailE1
191 })
192
193 await waitJobs(servers)
194
195 for (const server of servers) {
196 const p = await getPlaylistWithThumbnail(server)
197 await testImage(server.url, 'thumbnail', p.thumbnailPath)
198 }
199 })
200
201 it('Should the thumbnail when we delete the last element', async function () {
202 this.timeout(30000)
203
204 await servers[1].playlists.removeElement({
205 playlistId: playlistWithoutThumbnailId,
206 elementId: withoutThumbnailE2
207 })
208
209 await waitJobs(servers)
210
211 for (const server of servers) {
212 const p = await getPlaylistWithoutThumbnail(server)
213 expect(p.thumbnailPath).to.be.null
214 }
215 })
216
217 it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () {
218 this.timeout(30000)
219
220 await servers[1].playlists.removeElement({
221 playlistId: playlistWithThumbnailId,
222 elementId: withThumbnailE2
223 })
224
225 await waitJobs(servers)
226
227 for (const server of servers) {
228 const p = await getPlaylistWithThumbnail(server)
229 await testImage(server.url, 'thumbnail', p.thumbnailPath)
230 }
231 })
232
233 after(async function () {
234 await cleanupTests(servers)
235 })
236 })