]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/tests/api/videos/single-server.ts
Remove low timeouts
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / single-server.ts
... / ...
CommitLineData
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { checkVideoFilesWereRemoved, completeVideoCheck, testImage } from '@server/tests/shared'
5import { wait } from '@shared/core-utils'
6import { Video, VideoPrivacy } from '@shared/models'
7import {
8 cleanupTests,
9 createSingleServer,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 setDefaultAccountAvatar,
13 setDefaultChannelAvatar,
14 waitJobs
15} from '@shared/server-commands'
16
17describe('Test a single server', function () {
18
19 function runSuite (mode: 'legacy' | 'resumable') {
20 let server: PeerTubeServer = null
21 let videoId: number | string
22 let videoId2: string
23 let videoUUID = ''
24 let videosListBase: any[] = null
25
26 const getCheckAttributes = () => ({
27 name: 'my super name',
28 category: 2,
29 licence: 6,
30 language: 'zh',
31 nsfw: true,
32 description: 'my super description',
33 support: 'my super support text',
34 account: {
35 name: 'root',
36 host: server.host
37 },
38 isLocal: true,
39 duration: 5,
40 tags: [ 'tag1', 'tag2', 'tag3' ],
41 privacy: VideoPrivacy.PUBLIC,
42 commentsEnabled: true,
43 downloadEnabled: true,
44 channel: {
45 displayName: 'Main root channel',
46 name: 'root_channel',
47 description: '',
48 isLocal: true
49 },
50 fixture: 'video_short.webm',
51 files: [
52 {
53 resolution: 720,
54 size: 218910
55 }
56 ]
57 })
58
59 const updateCheckAttributes = () => ({
60 name: 'my super video updated',
61 category: 4,
62 licence: 2,
63 language: 'ar',
64 nsfw: false,
65 description: 'my super description updated',
66 support: 'my super support text updated',
67 account: {
68 name: 'root',
69 host: server.host
70 },
71 isLocal: true,
72 tags: [ 'tagup1', 'tagup2' ],
73 privacy: VideoPrivacy.PUBLIC,
74 duration: 5,
75 commentsEnabled: false,
76 downloadEnabled: false,
77 channel: {
78 name: 'root_channel',
79 displayName: 'Main root channel',
80 description: '',
81 isLocal: true
82 },
83 fixture: 'video_short3.webm',
84 files: [
85 {
86 resolution: 720,
87 size: 292677
88 }
89 ]
90 })
91
92 before(async function () {
93 this.timeout(30000)
94
95 server = await createSingleServer(1)
96
97 await setAccessTokensToServers([ server ])
98 await setDefaultChannelAvatar(server)
99 await setDefaultAccountAvatar(server)
100 })
101
102 it('Should list video categories', async function () {
103 const categories = await server.videos.getCategories()
104 expect(Object.keys(categories)).to.have.length.above(10)
105
106 expect(categories[11]).to.equal('News & Politics')
107 })
108
109 it('Should list video licences', async function () {
110 const licences = await server.videos.getLicences()
111 expect(Object.keys(licences)).to.have.length.above(5)
112
113 expect(licences[3]).to.equal('Attribution - No Derivatives')
114 })
115
116 it('Should list video languages', async function () {
117 const languages = await server.videos.getLanguages()
118 expect(Object.keys(languages)).to.have.length.above(5)
119
120 expect(languages['ru']).to.equal('Russian')
121 })
122
123 it('Should list video privacies', async function () {
124 const privacies = await server.videos.getPrivacies()
125 expect(Object.keys(privacies)).to.have.length.at.least(3)
126
127 expect(privacies[3]).to.equal('Private')
128 })
129
130 it('Should not have videos', async function () {
131 const { data, total } = await server.videos.list()
132
133 expect(total).to.equal(0)
134 expect(data).to.be.an('array')
135 expect(data.length).to.equal(0)
136 })
137
138 it('Should upload the video', async function () {
139 const attributes = {
140 name: 'my super name',
141 category: 2,
142 nsfw: true,
143 licence: 6,
144 tags: [ 'tag1', 'tag2', 'tag3' ]
145 }
146 const video = await server.videos.upload({ attributes, mode })
147 expect(video).to.not.be.undefined
148 expect(video.id).to.equal(1)
149 expect(video.uuid).to.have.length.above(5)
150
151 videoId = video.id
152 videoUUID = video.uuid
153 })
154
155 it('Should get and seed the uploaded video', async function () {
156 this.timeout(5000)
157
158 const { data, total } = await server.videos.list()
159
160 expect(total).to.equal(1)
161 expect(data).to.be.an('array')
162 expect(data.length).to.equal(1)
163
164 const video = data[0]
165 await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: getCheckAttributes() })
166 })
167
168 it('Should get the video by UUID', async function () {
169 this.timeout(5000)
170
171 const video = await server.videos.get({ id: videoUUID })
172 await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: getCheckAttributes() })
173 })
174
175 it('Should have the views updated', async function () {
176 this.timeout(20000)
177
178 await server.views.simulateView({ id: videoId })
179 await server.views.simulateView({ id: videoId })
180 await server.views.simulateView({ id: videoId })
181
182 await wait(1500)
183
184 await server.views.simulateView({ id: videoId })
185 await server.views.simulateView({ id: videoId })
186
187 await wait(1500)
188
189 await server.views.simulateView({ id: videoId })
190 await server.views.simulateView({ id: videoId })
191
192 await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
193
194 const video = await server.videos.get({ id: videoId })
195 expect(video.views).to.equal(3)
196 })
197
198 it('Should remove the video', async function () {
199 const video = await server.videos.get({ id: videoId })
200 await server.videos.remove({ id: videoId })
201
202 await checkVideoFilesWereRemoved({ video, server })
203 })
204
205 it('Should not have videos', async function () {
206 const { total, data } = await server.videos.list()
207
208 expect(total).to.equal(0)
209 expect(data).to.be.an('array')
210 expect(data).to.have.lengthOf(0)
211 })
212
213 it('Should upload 6 videos', async function () {
214 this.timeout(120000)
215
216 const videos = new Set([
217 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
218 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
219 ])
220
221 for (const video of videos) {
222 const attributes = {
223 name: video + ' name',
224 description: video + ' description',
225 category: 2,
226 licence: 1,
227 language: 'en',
228 nsfw: true,
229 tags: [ 'tag1', 'tag2', 'tag3' ],
230 fixture: video
231 }
232
233 await server.videos.upload({ attributes, mode })
234 }
235 })
236
237 it('Should have the correct durations', async function () {
238 const { total, data } = await server.videos.list()
239
240 expect(total).to.equal(6)
241 expect(data).to.be.an('array')
242 expect(data).to.have.lengthOf(6)
243
244 const videosByName: { [ name: string ]: Video } = {}
245 data.forEach(v => { videosByName[v.name] = v })
246
247 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
248 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
249 expect(videosByName['video_short.webm name'].duration).to.equal(5)
250 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
251 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
252 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
253 })
254
255 it('Should have the correct thumbnails', async function () {
256 const { data } = await server.videos.list()
257
258 // For the next test
259 videosListBase = data
260
261 for (const video of data) {
262 const videoName = video.name.replace(' name', '')
263 await testImage(server.url, videoName, video.thumbnailPath)
264 }
265 })
266
267 it('Should list only the two first videos', async function () {
268 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: 'name' })
269
270 expect(total).to.equal(6)
271 expect(data.length).to.equal(2)
272 expect(data[0].name).to.equal(videosListBase[0].name)
273 expect(data[1].name).to.equal(videosListBase[1].name)
274 })
275
276 it('Should list only the next three videos', async function () {
277 const { total, data } = await server.videos.list({ start: 2, count: 3, sort: 'name' })
278
279 expect(total).to.equal(6)
280 expect(data.length).to.equal(3)
281 expect(data[0].name).to.equal(videosListBase[2].name)
282 expect(data[1].name).to.equal(videosListBase[3].name)
283 expect(data[2].name).to.equal(videosListBase[4].name)
284 })
285
286 it('Should list the last video', async function () {
287 const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name' })
288
289 expect(total).to.equal(6)
290 expect(data.length).to.equal(1)
291 expect(data[0].name).to.equal(videosListBase[5].name)
292 })
293
294 it('Should not have the total field', async function () {
295 const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name', skipCount: true })
296
297 expect(total).to.not.exist
298 expect(data.length).to.equal(1)
299 expect(data[0].name).to.equal(videosListBase[5].name)
300 })
301
302 it('Should list and sort by name in descending order', async function () {
303 const { total, data } = await server.videos.list({ sort: '-name' })
304
305 expect(total).to.equal(6)
306 expect(data.length).to.equal(6)
307 expect(data[0].name).to.equal('video_short.webm name')
308 expect(data[1].name).to.equal('video_short.ogv name')
309 expect(data[2].name).to.equal('video_short.mp4 name')
310 expect(data[3].name).to.equal('video_short3.webm name')
311 expect(data[4].name).to.equal('video_short2.webm name')
312 expect(data[5].name).to.equal('video_short1.webm name')
313
314 videoId = data[3].uuid
315 videoId2 = data[5].uuid
316 })
317
318 it('Should list and sort by trending in descending order', async function () {
319 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-trending' })
320
321 expect(total).to.equal(6)
322 expect(data.length).to.equal(2)
323 })
324
325 it('Should list and sort by hotness in descending order', async function () {
326 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-hot' })
327
328 expect(total).to.equal(6)
329 expect(data.length).to.equal(2)
330 })
331
332 it('Should list and sort by best in descending order', async function () {
333 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-best' })
334
335 expect(total).to.equal(6)
336 expect(data.length).to.equal(2)
337 })
338
339 it('Should update a video', async function () {
340 const attributes = {
341 name: 'my super video updated',
342 category: 4,
343 licence: 2,
344 language: 'ar',
345 nsfw: false,
346 description: 'my super description updated',
347 commentsEnabled: false,
348 downloadEnabled: false,
349 tags: [ 'tagup1', 'tagup2' ]
350 }
351 await server.videos.update({ id: videoId, attributes })
352 })
353
354 it('Should have the video updated', async function () {
355 this.timeout(60000)
356
357 await waitJobs([ server ])
358
359 const video = await server.videos.get({ id: videoId })
360
361 await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: updateCheckAttributes() })
362 })
363
364 it('Should update only the tags of a video', async function () {
365 const attributes = {
366 tags: [ 'supertag', 'tag1', 'tag2' ]
367 }
368 await server.videos.update({ id: videoId, attributes })
369
370 const video = await server.videos.get({ id: videoId })
371
372 await completeVideoCheck({
373 server,
374 originServer: server,
375 videoUUID: video.uuid,
376 attributes: Object.assign(updateCheckAttributes(), attributes)
377 })
378 })
379
380 it('Should update only the description of a video', async function () {
381 const attributes = {
382 description: 'hello everybody'
383 }
384 await server.videos.update({ id: videoId, attributes })
385
386 const video = await server.videos.get({ id: videoId })
387
388 await completeVideoCheck({
389 server,
390 originServer: server,
391 videoUUID: video.uuid,
392 attributes: Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
393 })
394 })
395
396 it('Should like a video', async function () {
397 await server.videos.rate({ id: videoId, rating: 'like' })
398
399 const video = await server.videos.get({ id: videoId })
400
401 expect(video.likes).to.equal(1)
402 expect(video.dislikes).to.equal(0)
403 })
404
405 it('Should dislike the same video', async function () {
406 await server.videos.rate({ id: videoId, rating: 'dislike' })
407
408 const video = await server.videos.get({ id: videoId })
409
410 expect(video.likes).to.equal(0)
411 expect(video.dislikes).to.equal(1)
412 })
413
414 it('Should sort by originallyPublishedAt', async function () {
415 {
416 const now = new Date()
417 const attributes = { originallyPublishedAt: now.toISOString() }
418 await server.videos.update({ id: videoId, attributes })
419
420 const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
421 const names = data.map(v => v.name)
422
423 expect(names[0]).to.equal('my super video updated')
424 expect(names[1]).to.equal('video_short2.webm name')
425 expect(names[2]).to.equal('video_short1.webm name')
426 expect(names[3]).to.equal('video_short.webm name')
427 expect(names[4]).to.equal('video_short.ogv name')
428 expect(names[5]).to.equal('video_short.mp4 name')
429 }
430
431 {
432 const now = new Date()
433 const attributes = { originallyPublishedAt: now.toISOString() }
434 await server.videos.update({ id: videoId2, attributes })
435
436 const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
437 const names = data.map(v => v.name)
438
439 expect(names[0]).to.equal('video_short1.webm name')
440 expect(names[1]).to.equal('my super video updated')
441 expect(names[2]).to.equal('video_short2.webm name')
442 expect(names[3]).to.equal('video_short.webm name')
443 expect(names[4]).to.equal('video_short.ogv name')
444 expect(names[5]).to.equal('video_short.mp4 name')
445 }
446 })
447
448 after(async function () {
449 await cleanupTests([ server ])
450 })
451 }
452
453 describe('Legacy upload', function () {
454 runSuite('legacy')
455 })
456
457 describe('Resumable upload', function () {
458 runSuite('resumable')
459 })
460})