]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/video-playlist-thumbnails.ts
Fix live constraints tests
[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 'mocha'
4 import * as chai from 'chai'
5 import { testImage } from '@server/tests/shared'
6 import { VideoPlaylistPrivacy } from '@shared/models'
7 import {
8 cleanupTests,
9 createMultipleServers,
10 doubleFollow,
11 PeerTubeServer,
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
14 waitJobs
15 } from '@shared/server-commands'
16
17 const expect = chai.expect
18
19 describe('Playlist thumbnail', function () {
20 let servers: PeerTubeServer[] = []
21
22 let playlistWithoutThumbnailId: number
23 let playlistWithThumbnailId: number
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
33 async function getPlaylistWithoutThumbnail (server: PeerTubeServer) {
34 const body = await server.playlists.list({ start: 0, count: 10 })
35
36 return body.data.find(p => p.displayName === 'playlist without thumbnail')
37 }
38
39 async function getPlaylistWithThumbnail (server: PeerTubeServer) {
40 const body = await server.playlists.list({ start: 0, count: 10 })
41
42 return body.data.find(p => p.displayName === 'playlist with thumbnail')
43 }
44
45 before(async function () {
46 this.timeout(120000)
47
48 servers = await createMultipleServers(2)
49
50 // Get the access tokens
51 await setAccessTokensToServers(servers)
52 await setDefaultVideoChannel(servers)
53
54 for (const server of servers) {
55 await server.config.disableTranscoding()
56 }
57
58 // Server 1 and server 2 follow each other
59 await doubleFollow(servers[0], servers[1])
60
61 video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).id
62 video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).id
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
70 const created = await servers[1].playlists.create({
71 attributes: {
72 displayName: 'playlist without thumbnail',
73 privacy: VideoPlaylistPrivacy.PUBLIC,
74 videoChannelId: servers[1].store.channel.id
75 }
76 })
77 playlistWithoutThumbnailId = created.id
78
79 const added = await servers[1].playlists.addElement({
80 playlistId: playlistWithoutThumbnailId,
81 attributes: { videoId: video1 }
82 })
83 withoutThumbnailE1 = added.id
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
96 const created = await servers[1].playlists.create({
97 attributes: {
98 displayName: 'playlist with thumbnail',
99 privacy: VideoPlaylistPrivacy.PUBLIC,
100 videoChannelId: servers[1].store.channel.id,
101 thumbnailfile: 'thumbnail.jpg'
102 }
103 })
104 playlistWithThumbnailId = created.id
105
106 const added = await servers[1].playlists.addElement({
107 playlistId: playlistWithThumbnailId,
108 attributes: { videoId: video1 }
109 })
110 withThumbnailE1 = added.id
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
123 const added = await servers[1].playlists.addElement({
124 playlistId: playlistWithoutThumbnailId,
125 attributes: { videoId: video2 }
126 })
127 withoutThumbnailE2 = added.id
128
129 await servers[1].playlists.reorderElements({
130 playlistId: playlistWithoutThumbnailId,
131 attributes: {
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
148 const added = await servers[1].playlists.addElement({
149 playlistId: playlistWithThumbnailId,
150 attributes: { videoId: video2 }
151 })
152 withThumbnailE2 = added.id
153
154 await servers[1].playlists.reorderElements({
155 playlistId: playlistWithThumbnailId,
156 attributes: {
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
173 await servers[1].playlists.removeElement({
174 playlistId: playlistWithoutThumbnailId,
175 elementId: withoutThumbnailE1
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
189 await servers[1].playlists.removeElement({
190 playlistId: playlistWithThumbnailId,
191 elementId: withThumbnailE1
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
205 await servers[1].playlists.removeElement({
206 playlistId: playlistWithoutThumbnailId,
207 elementId: withoutThumbnailE2
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
221 await servers[1].playlists.removeElement({
222 playlistId: playlistWithThumbnailId,
223 elementId: withThumbnailE2
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 })