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 () {
162 const videoAttributes = {
163 name: 'my super name',
167 tags: [ 'tag1', 'tag2', 'tag3' ]
169 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
170 expect(res.body.video).to.not.be.undefined
171 expect(res.body.video.id).to.equal(1)
172 expect(res.body.video.uuid).to.have.length.above(5)
174 videoId = res.body.video.id
175 videoUUID = res.body.video.uuid
178 it('Should get and seed the uploaded video', async function () {
181 const res = await getVideosList(server.url)
183 expect(res.body.total).to.equal(1)
184 expect(res.body.data).to.be.an('array')
185 expect(res.body.data.length).to.equal(1)
187 const video = res.body.data[0]
188 await completeVideoCheck(server.url, video, getCheckAttributes())
191 it('Should get the video by UUID', async function () {
194 const res = await getVideo(server.url, videoUUID)
196 const video = res.body
197 await completeVideoCheck(server.url, video, getCheckAttributes())
200 it('Should have the views updated', async function () {
203 await viewVideo(server.url, videoId)
204 await viewVideo(server.url, videoId)
205 await viewVideo(server.url, videoId)
209 await viewVideo(server.url, videoId)
210 await viewVideo(server.url, videoId)
214 await viewVideo(server.url, videoId)
215 await viewVideo(server.url, videoId)
217 // Wait the repeatable job
220 const res = await getVideo(server.url, videoId)
222 const video = res.body
223 expect(video.views).to.equal(3)
226 it('Should remove the video', async function () {
227 await removeVideo(server.url, server.accessToken, videoId)
229 await checkVideoFilesWereRemoved(videoUUID, 1)
232 it('Should not have videos', async function () {
233 const res = await getVideosList(server.url)
235 expect(res.body.total).to.equal(0)
236 expect(res.body.data).to.be.an('array')
237 expect(res.body.data).to.have.lengthOf(0)
240 it('Should upload 6 videos', async function () {
243 const videos = new Set([
244 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
245 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
248 for (const video of videos) {
249 const videoAttributes = {
250 name: video + ' name',
251 description: video + ' description',
256 tags: [ 'tag1', 'tag2', 'tag3' ],
260 await uploadVideo(server.url, server.accessToken, videoAttributes)
264 it('Should have the correct durations', async function () {
265 const res = await getVideosList(server.url)
267 expect(res.body.total).to.equal(6)
268 const videos = res.body.data
269 expect(videos).to.be.an('array')
270 expect(videos).to.have.lengthOf(6)
272 const videosByName = keyBy<{ duration: number }>(videos, 'name')
273 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
274 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
275 expect(videosByName['video_short.webm name'].duration).to.equal(5)
276 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
277 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
278 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
281 it('Should have the correct thumbnails', async function () {
282 const res = await getVideosList(server.url)
284 const videos = res.body.data
286 videosListBase = videos
288 for (const video of videos) {
289 const videoName = video.name.replace(' name', '')
290 await testImage(server.url, videoName, video.thumbnailPath)
294 it('Should list only the two first videos', async function () {
295 const res = await getVideosListPagination(server.url, 0, 2, 'name')
297 const videos = res.body.data
298 expect(res.body.total).to.equal(6)
299 expect(videos.length).to.equal(2)
300 expect(videos[0].name).to.equal(videosListBase[0].name)
301 expect(videos[1].name).to.equal(videosListBase[1].name)
304 it('Should list only the next three videos', async function () {
305 const res = await getVideosListPagination(server.url, 2, 3, 'name')
307 const videos = res.body.data
308 expect(res.body.total).to.equal(6)
309 expect(videos.length).to.equal(3)
310 expect(videos[0].name).to.equal(videosListBase[2].name)
311 expect(videos[1].name).to.equal(videosListBase[3].name)
312 expect(videos[2].name).to.equal(videosListBase[4].name)
315 it('Should list the last video', async function () {
316 const res = await getVideosListPagination(server.url, 5, 6, 'name')
318 const videos = res.body.data
319 expect(res.body.total).to.equal(6)
320 expect(videos.length).to.equal(1)
321 expect(videos[0].name).to.equal(videosListBase[5].name)
324 it('Should not have the total field', async function () {
325 const res = await getVideosListPagination(server.url, 5, 6, 'name', true)
327 const videos = res.body.data
328 expect(res.body.total).to.not.exist
329 expect(videos.length).to.equal(1)
330 expect(videos[0].name).to.equal(videosListBase[5].name)
333 it('Should list and sort by name in descending order', async function () {
334 const res = await getVideosListSort(server.url, '-name')
336 const videos = res.body.data
337 expect(res.body.total).to.equal(6)
338 expect(videos.length).to.equal(6)
339 expect(videos[0].name).to.equal('video_short.webm name')
340 expect(videos[1].name).to.equal('video_short.ogv name')
341 expect(videos[2].name).to.equal('video_short.mp4 name')
342 expect(videos[3].name).to.equal('video_short3.webm name')
343 expect(videos[4].name).to.equal('video_short2.webm name')
344 expect(videos[5].name).to.equal('video_short1.webm name')
346 videoId = videos[3].uuid
347 videoId2 = videos[5].uuid
350 it('Should list and sort by trending in descending order', async function () {
351 const res = await getVideosListPagination(server.url, 0, 2, '-trending')
353 const videos = res.body.data
354 expect(res.body.total).to.equal(6)
355 expect(videos.length).to.equal(2)
358 it('Should list and sort by hotness in descending order', async function () {
359 const res = await getVideosListPagination(server.url, 0, 2, '-hot')
361 const videos = res.body.data
362 expect(res.body.total).to.equal(6)
363 expect(videos.length).to.equal(2)
366 it('Should list and sort by best in descending order', async function () {
367 const res = await getVideosListPagination(server.url, 0, 2, '-best')
369 const videos = res.body.data
370 expect(res.body.total).to.equal(6)
371 expect(videos.length).to.equal(2)
374 it('Should update a video', async function () {
376 name: 'my super video updated',
381 description: 'my super description updated',
382 commentsEnabled: false,
383 downloadEnabled: false,
384 tags: [ 'tagup1', 'tagup2' ]
386 await updateVideo(server.url, server.accessToken, videoId, attributes)
389 it('Should filter by tags and category', async function () {
390 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] })
391 expect(res1.body.total).to.equal(1)
392 expect(res1.body.data[0].name).to.equal('my super video updated')
394 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] })
395 expect(res2.body.total).to.equal(0)
398 it('Should have the video updated', async function () {
401 const res = await getVideo(server.url, videoId)
402 const video = res.body
404 await completeVideoCheck(server.url, video, updateCheckAttributes())
407 it('Should update only the tags of a video', async function () {
409 tags: [ 'supertag', 'tag1', 'tag2' ]
411 await updateVideo(server.url, server.accessToken, videoId, attributes)
413 const res = await getVideo(server.url, videoId)
414 const video = res.body
416 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes))
419 it('Should update only the description of a video', async function () {
421 description: 'hello everybody'
423 await updateVideo(server.url, server.accessToken, videoId, attributes)
425 const res = await getVideo(server.url, videoId)
426 const video = res.body
428 const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
429 await completeVideoCheck(server.url, video, expectedAttributes)
432 it('Should like a video', async function () {
433 await rateVideo(server.url, server.accessToken, videoId, 'like')
435 const res = await getVideo(server.url, videoId)
436 const video = res.body
438 expect(video.likes).to.equal(1)
439 expect(video.dislikes).to.equal(0)
442 it('Should dislike the same video', async function () {
443 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
445 const res = await getVideo(server.url, videoId)
446 const video = res.body
448 expect(video.likes).to.equal(0)
449 expect(video.dislikes).to.equal(1)
452 it('Should sort by originallyPublishedAt', async function () {
456 const now = new Date()
457 const attributes = { originallyPublishedAt: now.toISOString() }
458 await updateVideo(server.url, server.accessToken, videoId, attributes)
460 const res = await getVideosListSort(server.url, '-originallyPublishedAt')
461 const names = res.body.data.map(v => v.name)
463 expect(names[0]).to.equal('my super video updated')
464 expect(names[1]).to.equal('video_short2.webm name')
465 expect(names[2]).to.equal('video_short1.webm name')
466 expect(names[3]).to.equal('video_short.webm name')
467 expect(names[4]).to.equal('video_short.ogv name')
468 expect(names[5]).to.equal('video_short.mp4 name')
472 const now = new Date()
473 const attributes = { originallyPublishedAt: now.toISOString() }
474 await updateVideo(server.url, server.accessToken, videoId2, attributes)
476 const res = await getVideosListSort(server.url, '-originallyPublishedAt')
477 const names = res.body.data.map(v => v.name)
479 expect(names[0]).to.equal('video_short1.webm name')
480 expect(names[1]).to.equal('my super video updated')
481 expect(names[2]).to.equal('video_short2.webm name')
482 expect(names[3]).to.equal('video_short.webm name')
483 expect(names[4]).to.equal('video_short.ogv name')
484 expect(names[5]).to.equal('video_short.mp4 name')
489 after(async function () {
490 await cleanupTests([ server ])