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 update a video', async function () {
368 name: 'my super video updated',
373 description: 'my super description updated',
374 commentsEnabled: false,
375 downloadEnabled: false,
376 tags: [ 'tagup1', 'tagup2' ]
378 await updateVideo(server.url, server.accessToken, videoId, attributes)
381 it('Should filter by tags and category', async function () {
382 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 4 })
383 expect(res1.body.total).to.equal(1)
384 expect(res1.body.data[0].name).to.equal('my super video updated')
386 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 3 })
387 expect(res2.body.total).to.equal(0)
390 it('Should have the video updated', async function () {
393 const res = await getVideo(server.url, videoId)
394 const video = res.body
396 await completeVideoCheck(server.url, video, updateCheckAttributes())
399 it('Should update only the tags of a video', async function () {
401 tags: [ 'supertag', 'tag1', 'tag2' ]
403 await updateVideo(server.url, server.accessToken, videoId, attributes)
405 const res = await getVideo(server.url, videoId)
406 const video = res.body
408 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes))
411 it('Should update only the description of a video', async function () {
413 description: 'hello everybody'
415 await updateVideo(server.url, server.accessToken, videoId, attributes)
417 const res = await getVideo(server.url, videoId)
418 const video = res.body
420 const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
421 await completeVideoCheck(server.url, video, expectedAttributes)
424 it('Should like a video', async function () {
425 await rateVideo(server.url, server.accessToken, videoId, 'like')
427 const res = await getVideo(server.url, videoId)
428 const video = res.body
430 expect(video.likes).to.equal(1)
431 expect(video.dislikes).to.equal(0)
434 it('Should dislike the same video', async function () {
435 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
437 const res = await getVideo(server.url, videoId)
438 const video = res.body
440 expect(video.likes).to.equal(0)
441 expect(video.dislikes).to.equal(1)
444 it('Should sort by originallyPublishedAt', async function () {
448 const now = new Date()
449 const attributes = { originallyPublishedAt: now.toISOString() }
450 await updateVideo(server.url, server.accessToken, videoId, attributes)
452 const res = await getVideosListSort(server.url, '-originallyPublishedAt')
453 const names = res.body.data.map(v => v.name)
455 expect(names[0]).to.equal('my super video updated')
456 expect(names[1]).to.equal('video_short2.webm name')
457 expect(names[2]).to.equal('video_short1.webm name')
458 expect(names[3]).to.equal('video_short.webm name')
459 expect(names[4]).to.equal('video_short.ogv name')
460 expect(names[5]).to.equal('video_short.mp4 name')
464 const now = new Date()
465 const attributes = { originallyPublishedAt: now.toISOString() }
466 await updateVideo(server.url, server.accessToken, videoId2, attributes)
468 const res = await getVideosListSort(server.url, '-originallyPublishedAt')
469 const names = res.body.data.map(v => v.name)
471 expect(names[0]).to.equal('video_short1.webm name')
472 expect(names[1]).to.equal('my super video updated')
473 expect(names[2]).to.equal('video_short2.webm name')
474 expect(names[3]).to.equal('video_short.webm name')
475 expect(names[4]).to.equal('video_short.ogv name')
476 expect(names[5]).to.equal('video_short.mp4 name')
481 after(async function () {
482 await cleanupTests([ server ])