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