1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { keyBy } from 'lodash'
6 import { VideoPrivacy } from '../../../../shared/models/videos'
8 checkVideoFilesWereRemoved,
18 getVideosListPagination,
24 setAccessTokensToServers,
30 } from '../../../../shared/extra-utils'
32 const expect = chai.expect
34 describe('Test a single server', function () {
35 let server: ServerInfo = null
39 let videosListBase: any[] = null
41 const getCheckAttributes = () => ({
42 name: 'my super name',
47 description: 'my super description',
48 support: 'my super support text',
51 host: 'localhost:' + server.port
55 tags: [ 'tag1', 'tag2', 'tag3' ],
56 privacy: VideoPrivacy.PUBLIC,
57 commentsEnabled: true,
58 downloadEnabled: true,
60 displayName: 'Main root channel',
65 fixture: 'video_short.webm',
74 const updateCheckAttributes = () => ({
75 name: 'my super video updated',
80 description: 'my super description updated',
81 support: 'my super support text updated',
84 host: 'localhost:' + server.port
87 tags: [ 'tagup1', 'tagup2' ],
88 privacy: VideoPrivacy.PUBLIC,
90 commentsEnabled: false,
91 downloadEnabled: false,
94 displayName: 'Main root channel',
98 fixture: 'video_short3.webm',
107 before(async function () {
110 server = await flushAndRunServer(1)
112 await setAccessTokensToServers([ server ])
115 it('Should list video categories', async function () {
116 const res = await getVideoCategories(server.url)
118 const categories = res.body
119 expect(Object.keys(categories)).to.have.length.above(10)
121 expect(categories[11]).to.equal('News & Politics')
124 it('Should list video licences', async function () {
125 const res = await getVideoLicences(server.url)
127 const licences = res.body
128 expect(Object.keys(licences)).to.have.length.above(5)
130 expect(licences[3]).to.equal('Attribution - No Derivatives')
133 it('Should list video languages', async function () {
134 const res = await getVideoLanguages(server.url)
136 const languages = res.body
137 expect(Object.keys(languages)).to.have.length.above(5)
139 expect(languages['ru']).to.equal('Russian')
142 it('Should list video privacies', async function () {
143 const res = await getVideoPrivacies(server.url)
145 const privacies = res.body
146 expect(Object.keys(privacies)).to.have.length.at.least(3)
148 expect(privacies[3]).to.equal('Private')
151 it('Should not have videos', async function () {
152 const res = await getVideosList(server.url)
154 expect(res.body.total).to.equal(0)
155 expect(res.body.data).to.be.an('array')
156 expect(res.body.data.length).to.equal(0)
159 it('Should upload the video', async function () {
160 const videoAttributes = {
161 name: 'my super name',
165 tags: [ 'tag1', 'tag2', 'tag3' ]
167 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
168 expect(res.body.video).to.not.be.undefined
169 expect(res.body.video.id).to.equal(1)
170 expect(res.body.video.uuid).to.have.length.above(5)
172 videoId = res.body.video.id
173 videoUUID = res.body.video.uuid
176 it('Should get and seed the uploaded video', async function () {
179 const res = await getVideosList(server.url)
181 expect(res.body.total).to.equal(1)
182 expect(res.body.data).to.be.an('array')
183 expect(res.body.data.length).to.equal(1)
185 const video = res.body.data[0]
186 await completeVideoCheck(server.url, video, getCheckAttributes())
189 it('Should get the video by UUID', async function () {
192 const res = await getVideo(server.url, videoUUID)
194 const video = res.body
195 await completeVideoCheck(server.url, video, getCheckAttributes())
198 it('Should have the views updated', async function () {
201 await viewVideo(server.url, videoId)
202 await viewVideo(server.url, videoId)
203 await viewVideo(server.url, videoId)
207 await viewVideo(server.url, videoId)
208 await viewVideo(server.url, videoId)
212 await viewVideo(server.url, videoId)
213 await viewVideo(server.url, videoId)
215 // Wait the repeatable job
218 const res = await getVideo(server.url, videoId)
220 const video = res.body
221 expect(video.views).to.equal(3)
224 it('Should remove the video', async function () {
225 await removeVideo(server.url, server.accessToken, videoId)
227 await checkVideoFilesWereRemoved(videoUUID, 1)
230 it('Should not have videos', async function () {
231 const res = await getVideosList(server.url)
233 expect(res.body.total).to.equal(0)
234 expect(res.body.data).to.be.an('array')
235 expect(res.body.data).to.have.lengthOf(0)
238 it('Should upload 6 videos', async function () {
241 const videos = new Set([
242 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
243 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
246 for (const video of videos) {
247 const videoAttributes = {
248 name: video + ' name',
249 description: video + ' description',
254 tags: [ 'tag1', 'tag2', 'tag3' ],
258 await uploadVideo(server.url, server.accessToken, videoAttributes)
262 it('Should have the correct durations', async function () {
263 const res = await getVideosList(server.url)
265 expect(res.body.total).to.equal(6)
266 const videos = res.body.data
267 expect(videos).to.be.an('array')
268 expect(videos).to.have.lengthOf(6)
270 const videosByName = keyBy<{ duration: number }>(videos, 'name')
271 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
272 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
273 expect(videosByName['video_short.webm name'].duration).to.equal(5)
274 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
275 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
276 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
279 it('Should have the correct thumbnails', async function () {
280 const res = await getVideosList(server.url)
282 const videos = res.body.data
284 videosListBase = videos
286 for (const video of videos) {
287 const videoName = video.name.replace(' name', '')
288 await testImage(server.url, videoName, video.thumbnailPath)
292 it('Should list only the two first videos', async function () {
293 const res = await getVideosListPagination(server.url, 0, 2, 'name')
295 const videos = res.body.data
296 expect(res.body.total).to.equal(6)
297 expect(videos.length).to.equal(2)
298 expect(videos[0].name).to.equal(videosListBase[0].name)
299 expect(videos[1].name).to.equal(videosListBase[1].name)
302 it('Should list only the next three videos', async function () {
303 const res = await getVideosListPagination(server.url, 2, 3, 'name')
305 const videos = res.body.data
306 expect(res.body.total).to.equal(6)
307 expect(videos.length).to.equal(3)
308 expect(videos[0].name).to.equal(videosListBase[2].name)
309 expect(videos[1].name).to.equal(videosListBase[3].name)
310 expect(videos[2].name).to.equal(videosListBase[4].name)
313 it('Should list the last video', async function () {
314 const res = await getVideosListPagination(server.url, 5, 6, 'name')
316 const videos = res.body.data
317 expect(res.body.total).to.equal(6)
318 expect(videos.length).to.equal(1)
319 expect(videos[0].name).to.equal(videosListBase[5].name)
322 it('Should not have the total field', async function () {
323 const res = await getVideosListPagination(server.url, 5, 6, 'name', true)
325 const videos = res.body.data
326 expect(res.body.total).to.not.exist
327 expect(videos.length).to.equal(1)
328 expect(videos[0].name).to.equal(videosListBase[5].name)
331 it('Should list and sort by name in descending order', async function () {
332 const res = await getVideosListSort(server.url, '-name')
334 const videos = res.body.data
335 expect(res.body.total).to.equal(6)
336 expect(videos.length).to.equal(6)
337 expect(videos[0].name).to.equal('video_short.webm name')
338 expect(videos[1].name).to.equal('video_short.ogv name')
339 expect(videos[2].name).to.equal('video_short.mp4 name')
340 expect(videos[3].name).to.equal('video_short3.webm name')
341 expect(videos[4].name).to.equal('video_short2.webm name')
342 expect(videos[5].name).to.equal('video_short1.webm name')
344 videoId = videos[3].uuid
345 videoId2 = videos[5].uuid
348 it('Should list and sort by trending in descending order', async function () {
349 const res = await getVideosListPagination(server.url, 0, 2, '-trending')
351 const videos = res.body.data
352 expect(res.body.total).to.equal(6)
353 expect(videos.length).to.equal(2)
356 it('Should update a video', async function () {
358 name: 'my super video updated',
363 description: 'my super description updated',
364 commentsEnabled: false,
365 downloadEnabled: false,
366 tags: [ 'tagup1', 'tagup2' ]
368 await updateVideo(server.url, server.accessToken, videoId, attributes)
371 it('Should filter by tags and category', async function () {
372 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 4 })
373 expect(res1.body.total).to.equal(1)
374 expect(res1.body.data[0].name).to.equal('my super video updated')
376 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 3 })
377 expect(res2.body.total).to.equal(0)
380 it('Should have the video updated', async function () {
383 const res = await getVideo(server.url, videoId)
384 const video = res.body
386 await completeVideoCheck(server.url, video, updateCheckAttributes())
389 it('Should update only the tags of a video', async function () {
391 tags: [ 'supertag', 'tag1', 'tag2' ]
393 await updateVideo(server.url, server.accessToken, videoId, attributes)
395 const res = await getVideo(server.url, videoId)
396 const video = res.body
398 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes))
401 it('Should update only the description of a video', async function () {
403 description: 'hello everybody'
405 await updateVideo(server.url, server.accessToken, videoId, attributes)
407 const res = await getVideo(server.url, videoId)
408 const video = res.body
410 const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
411 await completeVideoCheck(server.url, video, expectedAttributes)
414 it('Should like a video', async function () {
415 await rateVideo(server.url, server.accessToken, videoId, 'like')
417 const res = await getVideo(server.url, videoId)
418 const video = res.body
420 expect(video.likes).to.equal(1)
421 expect(video.dislikes).to.equal(0)
424 it('Should dislike the same video', async function () {
425 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
427 const res = await getVideo(server.url, videoId)
428 const video = res.body
430 expect(video.likes).to.equal(0)
431 expect(video.dislikes).to.equal(1)
434 it('Should sort by originallyPublishedAt', async function () {
438 const now = new Date()
439 const attributes = { originallyPublishedAt: now.toISOString() }
440 await updateVideo(server.url, server.accessToken, videoId, attributes)
442 const res = await getVideosListSort(server.url, '-originallyPublishedAt')
443 const names = res.body.data.map(v => v.name)
445 expect(names[0]).to.equal('my super video updated')
446 expect(names[1]).to.equal('video_short2.webm name')
447 expect(names[2]).to.equal('video_short1.webm name')
448 expect(names[3]).to.equal('video_short.webm name')
449 expect(names[4]).to.equal('video_short.ogv name')
450 expect(names[5]).to.equal('video_short.mp4 name')
454 const now = new Date()
455 const attributes = { originallyPublishedAt: now.toISOString() }
456 await updateVideo(server.url, server.accessToken, videoId2, attributes)
458 const res = await getVideosListSort(server.url, '-originallyPublishedAt')
459 const names = res.body.data.map(v => v.name)
461 expect(names[0]).to.equal('video_short1.webm name')
462 expect(names[1]).to.equal('my super video updated')
463 expect(names[2]).to.equal('video_short2.webm name')
464 expect(names[3]).to.equal('video_short.webm name')
465 expect(names[4]).to.equal('video_short.ogv name')
466 expect(names[5]).to.equal('video_short.mp4 name')
471 after(async function () {
472 await cleanupTests([ server ])