]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/video-playlist-thumbnails.ts
Introduce playlist command
[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 {
6 cleanupTests,
7 doubleFollow,
8 flushAndRunMultipleServers,
9 ServerInfo,
10 setAccessTokensToServers,
11 setDefaultVideoChannel,
12 testImage,
13 uploadVideoAndGetId,
14 waitJobs
15 } from '../../../../shared/extra-utils'
16 import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
17
18 const expect = chai.expect
19
20 describe('Playlist thumbnail', function () {
21 let servers: ServerInfo[] = []
22
23 let playlistWithoutThumbnailId: number
24 let playlistWithThumbnailId: number
25
26 let withThumbnailE1: number
27 let withThumbnailE2: number
28 let withoutThumbnailE1: number
29 let withoutThumbnailE2: number
30
31 let video1: number
32 let video2: number
33
34 async function getPlaylistWithoutThumbnail (server: ServerInfo) {
35 const body = await server.playlistsCommand.list({ start: 0, count: 10 })
36
37 return body.data.find(p => p.displayName === 'playlist without thumbnail')
38 }
39
40 async function getPlaylistWithThumbnail (server: ServerInfo) {
41 const body = await server.playlistsCommand.list({ start: 0, count: 10 })
42
43 return body.data.find(p => p.displayName === 'playlist with thumbnail')
44 }
45
46 before(async function () {
47 this.timeout(120000)
48
49 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
50
51 // Get the access tokens
52 await setAccessTokensToServers(servers)
53 await setDefaultVideoChannel(servers)
54
55 // Server 1 and server 2 follow each other
56 await doubleFollow(servers[0], servers[1])
57
58 video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).id
59 video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).id
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
67 const created = await servers[1].playlistsCommand.create({
68 attributes: {
69 displayName: 'playlist without thumbnail',
70 privacy: VideoPlaylistPrivacy.PUBLIC,
71 videoChannelId: servers[1].videoChannel.id
72 }
73 })
74 playlistWithoutThumbnailId = created.id
75
76 const added = await servers[1].playlistsCommand.addElement({
77 playlistId: playlistWithoutThumbnailId,
78 attributes: { videoId: video1 }
79 })
80 withoutThumbnailE1 = added.id
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
93 const created = await servers[1].playlistsCommand.create({
94 attributes: {
95 displayName: 'playlist with thumbnail',
96 privacy: VideoPlaylistPrivacy.PUBLIC,
97 videoChannelId: servers[1].videoChannel.id,
98 thumbnailfile: 'thumbnail.jpg'
99 }
100 })
101 playlistWithThumbnailId = created.id
102
103 const added = await servers[1].playlistsCommand.addElement({
104 playlistId: playlistWithThumbnailId,
105 attributes: { videoId: video1 }
106 })
107 withThumbnailE1 = added.id
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
120 const added = await servers[1].playlistsCommand.addElement({
121 playlistId: playlistWithoutThumbnailId,
122 attributes: { videoId: video2 }
123 })
124 withoutThumbnailE2 = added.id
125
126 await servers[1].playlistsCommand.reorderElements({
127 playlistId: playlistWithoutThumbnailId,
128 attributes: {
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
145 const added = await servers[1].playlistsCommand.addElement({
146 playlistId: playlistWithThumbnailId,
147 attributes: { videoId: video2 }
148 })
149 withThumbnailE2 = added.id
150
151 await servers[1].playlistsCommand.reorderElements({
152 playlistId: playlistWithThumbnailId,
153 attributes: {
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
170 await servers[1].playlistsCommand.removeElement({
171 playlistId: playlistWithoutThumbnailId,
172 elementId: withoutThumbnailE1
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
186 await servers[1].playlistsCommand.removeElement({
187 playlistId: playlistWithThumbnailId,
188 elementId: withThumbnailE1
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
202 await servers[1].playlistsCommand.removeElement({
203 playlistId: playlistWithoutThumbnailId,
204 elementId: withoutThumbnailE2
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
218 await servers[1].playlistsCommand.removeElement({
219 playlistId: playlistWithThumbnailId,
220 elementId: withThumbnailE2
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 })