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