1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { keyBy } from 'lodash'
8 checkVideoFilesWereRemoved,
18 getVideosListPagination,
24 setAccessTokensToServers,
30 } from '../../../../shared/extra-utils'
31 import { VideoPrivacy } from '../../../../shared/models/videos'
32 import { HttpStatusCode } from '@shared/core-utils'
34 const expect = chai.expect
36 describe('Test a single server', function () {
38 function runSuite (mode: 'legacy' | 'resumable') {
39 let server: ServerInfo = null
43 let videosListBase: any[] = null
45 const getCheckAttributes = () => ({
46 name: 'my super name',
51 description: 'my super description',
52 support: 'my super support text',
55 host: 'localhost:' + server.port
59 tags: [ 'tag1', 'tag2', 'tag3' ],
60 privacy: VideoPrivacy.PUBLIC,
61 commentsEnabled: true,
62 downloadEnabled: true,
64 displayName: 'Main root channel',
69 fixture: 'video_short.webm',
78 const updateCheckAttributes = () => ({
79 name: 'my super video updated',
84 description: 'my super description updated',
85 support: 'my super support text updated',
88 host: 'localhost:' + server.port
91 tags: [ 'tagup1', 'tagup2' ],
92 privacy: VideoPrivacy.PUBLIC,
94 commentsEnabled: false,
95 downloadEnabled: false,
98 displayName: 'Main root channel',
102 fixture: 'video_short3.webm',
111 before(async function () {
114 server = await flushAndRunServer(1)
116 await setAccessTokensToServers([ server ])
119 it('Should list video categories', async function () {
120 const res = await getVideoCategories(server.url)
122 const categories = res.body
123 expect(Object.keys(categories)).to.have.length.above(10)
125 expect(categories[11]).to.equal('News & Politics')
128 it('Should list video licences', async function () {
129 const res = await getVideoLicences(server.url)
131 const licences = res.body
132 expect(Object.keys(licences)).to.have.length.above(5)
134 expect(licences[3]).to.equal('Attribution - No Derivatives')
137 it('Should list video languages', async function () {
138 const res = await getVideoLanguages(server.url)
140 const languages = res.body
141 expect(Object.keys(languages)).to.have.length.above(5)
143 expect(languages['ru']).to.equal('Russian')
146 it('Should list video privacies', async function () {
147 const res = await getVideoPrivacies(server.url)
149 const privacies = res.body
150 expect(Object.keys(privacies)).to.have.length.at.least(3)
152 expect(privacies[3]).to.equal('Private')
155 it('Should not have videos', async function () {
156 const res = await getVideosList(server.url)
158 expect(res.body.total).to.equal(0)
159 expect(res.body.data).to.be.an('array')
160 expect(res.body.data.length).to.equal(0)
163 it('Should upload the video', async function () {
166 const videoAttributes = {
167 name: 'my super name',
171 tags: [ 'tag1', 'tag2', 'tag3' ]
173 const res = await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode)
174 expect(res.body.video).to.not.be.undefined
175 expect(res.body.video.id).to.equal(1)
176 expect(res.body.video.uuid).to.have.length.above(5)
178 videoId = res.body.video.id
179 videoUUID = res.body.video.uuid
182 it('Should get and seed the uploaded video', async function () {
185 const res = await getVideosList(server.url)
187 expect(res.body.total).to.equal(1)
188 expect(res.body.data).to.be.an('array')
189 expect(res.body.data.length).to.equal(1)
191 const video = res.body.data[0]
192 await completeVideoCheck(server.url, video, getCheckAttributes())
195 it('Should get the video by UUID', async function () {
198 const res = await getVideo(server.url, videoUUID)
200 const video = res.body
201 await completeVideoCheck(server.url, video, getCheckAttributes())
204 it('Should have the views updated', async function () {
207 await viewVideo(server.url, videoId)
208 await viewVideo(server.url, videoId)
209 await viewVideo(server.url, videoId)
213 await viewVideo(server.url, videoId)
214 await viewVideo(server.url, videoId)
218 await viewVideo(server.url, videoId)
219 await viewVideo(server.url, videoId)
221 // Wait the repeatable job
224 const res = await getVideo(server.url, videoId)
226 const video = res.body
227 expect(video.views).to.equal(3)
230 it('Should remove the video', async function () {
231 await removeVideo(server.url, server.accessToken, videoId)
233 await checkVideoFilesWereRemoved(videoUUID, server)
236 it('Should not have videos', async function () {
237 const res = await getVideosList(server.url)
239 expect(res.body.total).to.equal(0)
240 expect(res.body.data).to.be.an('array')
241 expect(res.body.data).to.have.lengthOf(0)
244 it('Should upload 6 videos', async function () {
247 const videos = new Set([
248 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
249 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
252 for (const video of videos) {
253 const videoAttributes = {
254 name: video + ' name',
255 description: video + ' description',
260 tags: [ 'tag1', 'tag2', 'tag3' ],
264 await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode)
268 it('Should have the correct durations', async function () {
269 const res = await getVideosList(server.url)
271 expect(res.body.total).to.equal(6)
272 const videos = res.body.data
273 expect(videos).to.be.an('array')
274 expect(videos).to.have.lengthOf(6)
276 const videosByName = keyBy<{ duration: number }>(videos, 'name')
277 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
278 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
279 expect(videosByName['video_short.webm name'].duration).to.equal(5)
280 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
281 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
282 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
285 it('Should have the correct thumbnails', async function () {
286 const res = await getVideosList(server.url)
288 const videos = res.body.data
290 videosListBase = videos
292 for (const video of videos) {
293 const videoName = video.name.replace(' name', '')
294 await testImage(server.url, videoName, video.thumbnailPath)
298 it('Should list only the two first videos', async function () {
299 const res = await getVideosListPagination(server.url, 0, 2, 'name')
301 const videos = res.body.data
302 expect(res.body.total).to.equal(6)
303 expect(videos.length).to.equal(2)
304 expect(videos[0].name).to.equal(videosListBase[0].name)
305 expect(videos[1].name).to.equal(videosListBase[1].name)
308 it('Should list only the next three videos', async function () {
309 const res = await getVideosListPagination(server.url, 2, 3, 'name')
311 const videos = res.body.data
312 expect(res.body.total).to.equal(6)
313 expect(videos.length).to.equal(3)
314 expect(videos[0].name).to.equal(videosListBase[2].name)
315 expect(videos[1].name).to.equal(videosListBase[3].name)
316 expect(videos[2].name).to.equal(videosListBase[4].name)
319 it('Should list the last video', async function () {
320 const res = await getVideosListPagination(server.url, 5, 6, 'name')
322 const videos = res.body.data
323 expect(res.body.total).to.equal(6)
324 expect(videos.length).to.equal(1)
325 expect(videos[0].name).to.equal(videosListBase[5].name)
328 it('Should not have the total field', async function () {
329 const res = await getVideosListPagination(server.url, 5, 6, 'name', true)
331 const videos = res.body.data
332 expect(res.body.total).to.not.exist
333 expect(videos.length).to.equal(1)
334 expect(videos[0].name).to.equal(videosListBase[5].name)
337 it('Should list and sort by name in descending order', async function () {
338 const res = await getVideosListSort(server.url, '-name')
340 const videos = res.body.data
341 expect(res.body.total).to.equal(6)
342 expect(videos.length).to.equal(6)
343 expect(videos[0].name).to.equal('video_short.webm name')
344 expect(videos[1].name).to.equal('video_short.ogv name')
345 expect(videos[2].name).to.equal('video_short.mp4 name')
346 expect(videos[3].name).to.equal('video_short3.webm name')
347 expect(videos[4].name).to.equal('video_short2.webm name')
348 expect(videos[5].name).to.equal('video_short1.webm name')
350 videoId = videos[3].uuid
351 videoId2 = videos[5].uuid
354 it('Should list and sort by trending in descending order', async function () {
355 const res = await getVideosListPagination(server.url, 0, 2, '-trending')
357 const videos = res.body.data
358 expect(res.body.total).to.equal(6)
359 expect(videos.length).to.equal(2)
362 it('Should list and sort by hotness in descending order', async function () {
363 const res = await getVideosListPagination(server.url, 0, 2, '-hot')
365 const videos = res.body.data
366 expect(res.body.total).to.equal(6)
367 expect(videos.length).to.equal(2)
370 it('Should list and sort by best in descending order', async function () {
371 const res = await getVideosListPagination(server.url, 0, 2, '-best')
373 const videos = res.body.data
374 expect(res.body.total).to.equal(6)
375 expect(videos.length).to.equal(2)
378 it('Should update a video', async function () {
380 name: 'my super video updated',
385 description: 'my super description updated',
386 commentsEnabled: false,
387 downloadEnabled: false,
388 tags: [ 'tagup1', 'tagup2' ]
390 await updateVideo(server.url, server.accessToken, videoId, attributes)
393 it('Should filter by tags and category', async function () {
394 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] })
395 expect(res1.body.total).to.equal(1)
396 expect(res1.body.data[0].name).to.equal('my super video updated')
398 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] })
399 expect(res2.body.total).to.equal(0)
402 it('Should have the video updated', async function () {
405 const res = await getVideo(server.url, videoId)
406 const video = res.body
408 await completeVideoCheck(server.url, video, updateCheckAttributes())
411 it('Should update only the tags of a video', async function () {
413 tags: [ 'supertag', 'tag1', 'tag2' ]
415 await updateVideo(server.url, server.accessToken, videoId, attributes)
417 const res = await getVideo(server.url, videoId)
418 const video = res.body
420 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes))
423 it('Should update only the description of a video', async function () {
425 description: 'hello everybody'
427 await updateVideo(server.url, server.accessToken, videoId, attributes)
429 const res = await getVideo(server.url, videoId)
430 const video = res.body
432 const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
433 await completeVideoCheck(server.url, video, expectedAttributes)
436 it('Should like a video', async function () {
437 await rateVideo(server.url, server.accessToken, videoId, 'like')
439 const res = await getVideo(server.url, videoId)
440 const video = res.body
442 expect(video.likes).to.equal(1)
443 expect(video.dislikes).to.equal(0)
446 it('Should dislike the same video', async function () {
447 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
449 const res = await getVideo(server.url, videoId)
450 const video = res.body
452 expect(video.likes).to.equal(0)
453 expect(video.dislikes).to.equal(1)
456 it('Should sort by originallyPublishedAt', async function () {
458 const now = new Date()
459 const attributes = { originallyPublishedAt: now.toISOString() }
460 await updateVideo(server.url, server.accessToken, videoId, attributes)
462 const res = await getVideosListSort(server.url, '-originallyPublishedAt')
463 const names = res.body.data.map(v => v.name)
465 expect(names[0]).to.equal('my super video updated')
466 expect(names[1]).to.equal('video_short2.webm name')
467 expect(names[2]).to.equal('video_short1.webm name')
468 expect(names[3]).to.equal('video_short.webm name')
469 expect(names[4]).to.equal('video_short.ogv name')
470 expect(names[5]).to.equal('video_short.mp4 name')
474 const now = new Date()
475 const attributes = { originallyPublishedAt: now.toISOString() }
476 await updateVideo(server.url, server.accessToken, videoId2, attributes)
478 const res = await getVideosListSort(server.url, '-originallyPublishedAt')
479 const names = res.body.data.map(v => v.name)
481 expect(names[0]).to.equal('video_short1.webm name')
482 expect(names[1]).to.equal('my super video updated')
483 expect(names[2]).to.equal('video_short2.webm name')
484 expect(names[3]).to.equal('video_short.webm name')
485 expect(names[4]).to.equal('video_short.ogv name')
486 expect(names[5]).to.equal('video_short.mp4 name')
490 after(async function () {
491 await cleanupTests([ server ])
495 describe('Legacy upload', function () {
499 describe('Resumable upload', function () {
500 runSuite('resumable')