]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-playlist-thumbnails.ts
emit more specific status codes on video upload (#3423)
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-playlist-thumbnails.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
65af03a2
C
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 addVideoInPlaylist,
7 cleanupTests,
8 createVideoPlaylist,
9 doubleFollow,
10 flushAndRunMultipleServers,
a1587156
C
11 getVideoPlaylistsList,
12 removeVideoFromPlaylist,
13 reorderVideosPlaylist,
65af03a2
C
14 ServerInfo,
15 setAccessTokensToServers,
16 setDefaultVideoChannel,
17 testImage,
18 uploadVideoAndGetId,
a1587156 19 waitJobs
65af03a2
C
20} from '../../../../shared/extra-utils'
21import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
22
23const expect = chai.expect
24
25describe('Playlist thumbnail', function () {
26 let servers: ServerInfo[] = []
27
28 let playlistWithoutThumbnail: number
29 let playlistWithThumbnail: number
30
31 let withThumbnailE1: number
32 let withThumbnailE2: number
33 let withoutThumbnailE1: number
34 let withoutThumbnailE2: number
35
36 let video1: number
37 let video2: number
38
39 async function getPlaylistWithoutThumbnail (server: ServerInfo) {
40 const res = await getVideoPlaylistsList(server.url, 0, 10)
41
42 return res.body.data.find(p => p.displayName === 'playlist without thumbnail')
43 }
44
45 async function getPlaylistWithThumbnail (server: ServerInfo) {
46 const res = await getVideoPlaylistsList(server.url, 0, 10)
47
48 return res.body.data.find(p => p.displayName === 'playlist with thumbnail')
49 }
50
51 before(async function () {
52 this.timeout(120000)
53
54 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
55
56 // Get the access tokens
57 await setAccessTokensToServers(servers)
58 await setDefaultVideoChannel(servers)
59
60 // Server 1 and server 2 follow each other
61 await doubleFollow(servers[0], servers[1])
62
63 video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).id
64 video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).id
65
66 await waitJobs(servers)
67 })
68
69 it('Should automatically update the thumbnail when adding an element', async function () {
70 this.timeout(30000)
71
72 const res = await createVideoPlaylist({
a1587156
C
73 url: servers[1].url,
74 token: servers[1].accessToken,
65af03a2
C
75 playlistAttrs: {
76 displayName: 'playlist without thumbnail',
77 privacy: VideoPlaylistPrivacy.PUBLIC,
a1587156 78 videoChannelId: servers[1].videoChannel.id
65af03a2
C
79 }
80 })
81 playlistWithoutThumbnail = res.body.videoPlaylist.id
82
83 const res2 = await addVideoInPlaylist({
a1587156
C
84 url: servers[1].url,
85 token: servers[1].accessToken,
65af03a2
C
86 playlistId: playlistWithoutThumbnail,
87 elementAttrs: { videoId: video1 }
88 })
89 withoutThumbnailE1 = res2.body.videoPlaylistElement.id
90
91 await waitJobs(servers)
92
93 for (const server of servers) {
94 const p = await getPlaylistWithoutThumbnail(server)
95 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
96 }
97 })
98
99 it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () {
100 this.timeout(30000)
101
102 const res = await createVideoPlaylist({
a1587156
C
103 url: servers[1].url,
104 token: servers[1].accessToken,
65af03a2
C
105 playlistAttrs: {
106 displayName: 'playlist with thumbnail',
107 privacy: VideoPlaylistPrivacy.PUBLIC,
a1587156 108 videoChannelId: servers[1].videoChannel.id,
65af03a2
C
109 thumbnailfile: 'thumbnail.jpg'
110 }
111 })
112 playlistWithThumbnail = res.body.videoPlaylist.id
113
114 const res2 = await addVideoInPlaylist({
a1587156
C
115 url: servers[1].url,
116 token: servers[1].accessToken,
65af03a2
C
117 playlistId: playlistWithThumbnail,
118 elementAttrs: { videoId: video1 }
119 })
120 withThumbnailE1 = res2.body.videoPlaylistElement.id
121
122 await waitJobs(servers)
123
124 for (const server of servers) {
125 const p = await getPlaylistWithThumbnail(server)
126 await testImage(server.url, 'thumbnail', p.thumbnailPath)
127 }
128 })
129
130 it('Should automatically update the thumbnail when moving the first element', async function () {
131 this.timeout(30000)
132
133 const res = await addVideoInPlaylist({
a1587156
C
134 url: servers[1].url,
135 token: servers[1].accessToken,
65af03a2
C
136 playlistId: playlistWithoutThumbnail,
137 elementAttrs: { videoId: video2 }
138 })
139 withoutThumbnailE2 = res.body.videoPlaylistElement.id
140
141 await reorderVideosPlaylist({
142 url: servers[1].url,
143 token: servers[1].accessToken,
144 playlistId: playlistWithoutThumbnail,
145 elementAttrs: {
146 startPosition: 1,
147 insertAfterPosition: 2
148 }
149 })
150
151 await waitJobs(servers)
152
153 for (const server of servers) {
154 const p = await getPlaylistWithoutThumbnail(server)
155 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
156 }
157 })
158
159 it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () {
160 this.timeout(30000)
161
162 const res = await addVideoInPlaylist({
a1587156
C
163 url: servers[1].url,
164 token: servers[1].accessToken,
65af03a2
C
165 playlistId: playlistWithThumbnail,
166 elementAttrs: { videoId: video2 }
167 })
168 withThumbnailE2 = res.body.videoPlaylistElement.id
169
170 await reorderVideosPlaylist({
171 url: servers[1].url,
172 token: servers[1].accessToken,
173 playlistId: playlistWithThumbnail,
174 elementAttrs: {
175 startPosition: 1,
176 insertAfterPosition: 2
177 }
178 })
179
180 await waitJobs(servers)
181
182 for (const server of servers) {
183 const p = await getPlaylistWithThumbnail(server)
184 await testImage(server.url, 'thumbnail', p.thumbnailPath)
185 }
186 })
187
188 it('Should automatically update the thumbnail when deleting the first element', async function () {
189 this.timeout(30000)
190
191 await removeVideoFromPlaylist({
a1587156
C
192 url: servers[1].url,
193 token: servers[1].accessToken,
65af03a2
C
194 playlistId: playlistWithoutThumbnail,
195 playlistElementId: withoutThumbnailE1
196 })
197
198 await waitJobs(servers)
199
200 for (const server of servers) {
201 const p = await getPlaylistWithoutThumbnail(server)
202 await testImage(server.url, 'thumbnail-playlist', p.thumbnailPath)
203 }
204 })
205
206 it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () {
207 this.timeout(30000)
208
209 await removeVideoFromPlaylist({
a1587156
C
210 url: servers[1].url,
211 token: servers[1].accessToken,
65af03a2
C
212 playlistId: playlistWithThumbnail,
213 playlistElementId: withThumbnailE1
214 })
215
216 await waitJobs(servers)
217
218 for (const server of servers) {
219 const p = await getPlaylistWithThumbnail(server)
220 await testImage(server.url, 'thumbnail', p.thumbnailPath)
221 }
222 })
223
224 it('Should the thumbnail when we delete the last element', async function () {
225 this.timeout(30000)
226
227 await removeVideoFromPlaylist({
a1587156
C
228 url: servers[1].url,
229 token: servers[1].accessToken,
65af03a2
C
230 playlistId: playlistWithoutThumbnail,
231 playlistElementId: withoutThumbnailE2
232 })
233
234 await waitJobs(servers)
235
236 for (const server of servers) {
237 const p = await getPlaylistWithoutThumbnail(server)
238 expect(p.thumbnailPath).to.be.null
239 }
240 })
241
242 it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () {
243 this.timeout(30000)
244
245 await removeVideoFromPlaylist({
a1587156
C
246 url: servers[1].url,
247 token: servers[1].accessToken,
65af03a2
C
248 playlistId: playlistWithThumbnail,
249 playlistElementId: withThumbnailE2
250 })
251
252 await waitJobs(servers)
253
254 for (const server of servers) {
255 const p = await getPlaylistWithThumbnail(server)
256 await testImage(server.url, 'thumbnail', p.thumbnailPath)
257 }
258 })
259
260 after(async function () {
261 await cleanupTests(servers)
262 })
263})