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