]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
65af03a2 2
e6346d59 3import * as chai 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
C
15
16const expect = chai.expect
17
18describe('Playlist thumbnail', function () {
254d3579 19 let servers: PeerTubeServer[] = []
65af03a2 20
e6346d59
C
21 let playlistWithoutThumbnailId: number
22 let playlistWithThumbnailId: number
65af03a2
C
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
254d3579 32 async function getPlaylistWithoutThumbnail (server: PeerTubeServer) {
89d241a7 33 const body = await server.playlists.list({ start: 0, count: 10 })
65af03a2 34
e6346d59 35 return body.data.find(p => p.displayName === 'playlist without thumbnail')
65af03a2
C
36 }
37
254d3579 38 async function getPlaylistWithThumbnail (server: PeerTubeServer) {
89d241a7 39 const body = await server.playlists.list({ start: 0, count: 10 })
65af03a2 40
e6346d59 41 return body.data.find(p => p.displayName === 'playlist with thumbnail')
65af03a2
C
42 }
43
44 before(async function () {
45 this.timeout(120000)
46
c729caf6 47 servers = await createMultipleServers(2)
65af03a2
C
48
49 // Get the access tokens
50 await setAccessTokensToServers(servers)
51 await setDefaultVideoChannel(servers)
52
c729caf6
C
53 for (const server of servers) {
54 await server.config.disableTranscoding()
55 }
56
65af03a2
C
57 // Server 1 and server 2 follow each other
58 await doubleFollow(servers[0], servers[1])
59
89d241a7
C
60 video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).id
61 video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).id
65af03a2
C
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
89d241a7 69 const created = await servers[1].playlists.create({
e6346d59 70 attributes: {
65af03a2
C
71 displayName: 'playlist without thumbnail',
72 privacy: VideoPlaylistPrivacy.PUBLIC,
89d241a7 73 videoChannelId: servers[1].store.channel.id
65af03a2
C
74 }
75 })
e6346d59 76 playlistWithoutThumbnailId = created.id
65af03a2 77
89d241a7 78 const added = await servers[1].playlists.addElement({
e6346d59
C
79 playlistId: playlistWithoutThumbnailId,
80 attributes: { videoId: video1 }
65af03a2 81 })
e6346d59 82 withoutThumbnailE1 = added.id
65af03a2
C
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
89d241a7 95 const created = await servers[1].playlists.create({
e6346d59 96 attributes: {
65af03a2
C
97 displayName: 'playlist with thumbnail',
98 privacy: VideoPlaylistPrivacy.PUBLIC,
89d241a7 99 videoChannelId: servers[1].store.channel.id,
65af03a2
C
100 thumbnailfile: 'thumbnail.jpg'
101 }
102 })
e6346d59 103 playlistWithThumbnailId = created.id
65af03a2 104
89d241a7 105 const added = await servers[1].playlists.addElement({
e6346d59
C
106 playlistId: playlistWithThumbnailId,
107 attributes: { videoId: video1 }
65af03a2 108 })
e6346d59 109 withThumbnailE1 = added.id
65af03a2
C
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
89d241a7 122 const added = await servers[1].playlists.addElement({
e6346d59
C
123 playlistId: playlistWithoutThumbnailId,
124 attributes: { videoId: video2 }
65af03a2 125 })
e6346d59 126 withoutThumbnailE2 = added.id
65af03a2 127
89d241a7 128 await servers[1].playlists.reorderElements({
e6346d59
C
129 playlistId: playlistWithoutThumbnailId,
130 attributes: {
65af03a2
C
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
89d241a7 147 const added = await servers[1].playlists.addElement({
e6346d59
C
148 playlistId: playlistWithThumbnailId,
149 attributes: { videoId: video2 }
65af03a2 150 })
e6346d59 151 withThumbnailE2 = added.id
65af03a2 152
89d241a7 153 await servers[1].playlists.reorderElements({
e6346d59
C
154 playlistId: playlistWithThumbnailId,
155 attributes: {
65af03a2
C
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
89d241a7 172 await servers[1].playlists.removeElement({
e6346d59
C
173 playlistId: playlistWithoutThumbnailId,
174 elementId: withoutThumbnailE1
65af03a2
C
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
89d241a7 188 await servers[1].playlists.removeElement({
e6346d59
C
189 playlistId: playlistWithThumbnailId,
190 elementId: withThumbnailE1
65af03a2
C
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
89d241a7 204 await servers[1].playlists.removeElement({
e6346d59
C
205 playlistId: playlistWithoutThumbnailId,
206 elementId: withoutThumbnailE2
65af03a2
C
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
89d241a7 220 await servers[1].playlists.removeElement({
e6346d59
C
221 playlistId: playlistWithThumbnailId,
222 elementId: withThumbnailE2
65af03a2
C
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})