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
38 let videosListBase: any[] = null
40 const getCheckAttributes = () => ({
41 name: 'my super name',
46 description: 'my super description',
47 support: 'my super support text',
50 host: 'localhost:' + server.port
54 tags: [ 'tag1', 'tag2', 'tag3' ],
55 privacy: VideoPrivacy.PUBLIC,
56 commentsEnabled: true,
57 downloadEnabled: true,
59 displayName: 'Main root channel',
64 fixture: 'video_short.webm',
73 const updateCheckAttributes = () => ({
74 name: 'my super video updated',
79 description: 'my super description updated',
80 support: 'my super support text updated',
83 host: 'localhost:' + server.port
86 tags: [ 'tagup1', 'tagup2' ],
87 privacy: VideoPrivacy.PUBLIC,
89 commentsEnabled: false,
90 downloadEnabled: false,
93 displayName: 'Main root channel',
97 fixture: 'video_short3.webm',
106 before(async function () {
109 server = await flushAndRunServer(1)
111 await setAccessTokensToServers([ server ])
114 it('Should list video categories', async function () {
115 const res = await getVideoCategories(server.url)
117 const categories = res.body
118 expect(Object.keys(categories)).to.have.length.above(10)
120 expect(categories[11]).to.equal('News & Politics')
123 it('Should list video licences', async function () {
124 const res = await getVideoLicences(server.url)
126 const licences = res.body
127 expect(Object.keys(licences)).to.have.length.above(5)
129 expect(licences[3]).to.equal('Attribution - No Derivatives')
132 it('Should list video languages', async function () {
133 const res = await getVideoLanguages(server.url)
135 const languages = res.body
136 expect(Object.keys(languages)).to.have.length.above(5)
138 expect(languages['ru']).to.equal('Russian')
141 it('Should list video privacies', async function () {
142 const res = await getVideoPrivacies(server.url)
144 const privacies = res.body
145 expect(Object.keys(privacies)).to.have.length.at.least(3)
147 expect(privacies[3]).to.equal('Private')
150 it('Should not have videos', async function () {
151 const res = await getVideosList(server.url)
153 expect(res.body.total).to.equal(0)
154 expect(res.body.data).to.be.an('array')
155 expect(res.body.data.length).to.equal(0)
158 it('Should upload the video', async function () {
159 const videoAttributes = {
160 name: 'my super name',
164 tags: [ 'tag1', 'tag2', 'tag3' ]
166 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
167 expect(res.body.video).to.not.be.undefined
168 expect(res.body.video.id).to.equal(1)
169 expect(res.body.video.uuid).to.have.length.above(5)
171 videoId = res.body.video.id
172 videoUUID = res.body.video.uuid
175 it('Should get and seed the uploaded video', async function () {
178 const res = await getVideosList(server.url)
180 expect(res.body.total).to.equal(1)
181 expect(res.body.data).to.be.an('array')
182 expect(res.body.data.length).to.equal(1)
184 const video = res.body.data[0]
185 await completeVideoCheck(server.url, video, getCheckAttributes())
188 it('Should get the video by UUID', async function () {
191 const res = await getVideo(server.url, videoUUID)
193 const video = res.body
194 await completeVideoCheck(server.url, video, getCheckAttributes())
197 it('Should have the views updated', async function () {
200 await viewVideo(server.url, videoId)
201 await viewVideo(server.url, videoId)
202 await viewVideo(server.url, videoId)
206 await viewVideo(server.url, videoId)
207 await viewVideo(server.url, videoId)
211 await viewVideo(server.url, videoId)
212 await viewVideo(server.url, videoId)
214 // Wait the repeatable job
217 const res = await getVideo(server.url, videoId)
219 const video = res.body
220 expect(video.views).to.equal(3)
223 it('Should remove the video', async function () {
224 await removeVideo(server.url, server.accessToken, videoId)
226 await checkVideoFilesWereRemoved(videoUUID, 1)
229 it('Should not have videos', async function () {
230 const res = await getVideosList(server.url)
232 expect(res.body.total).to.equal(0)
233 expect(res.body.data).to.be.an('array')
234 expect(res.body.data).to.have.lengthOf(0)
237 it('Should upload 6 videos', async function () {
241 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
242 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
245 const tasks: Promise<any>[] = []
246 for (const video of videos) {
247 const videoAttributes = {
248 name: video + ' name',
249 description: video + ' description',
254 tags: [ 'tag1', 'tag2', 'tag3' ],
258 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
262 await Promise.all(tasks)
265 it('Should have the correct durations', async function () {
266 const res = await getVideosList(server.url)
268 expect(res.body.total).to.equal(6)
269 const videos = res.body.data
270 expect(videos).to.be.an('array')
271 expect(videos).to.have.lengthOf(6)
273 const videosByName = keyBy<{ duration: number }>(videos, 'name')
274 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
275 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
276 expect(videosByName['video_short.webm name'].duration).to.equal(5)
277 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
278 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
279 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
282 it('Should have the correct thumbnails', async function () {
283 const res = await getVideosList(server.url)
285 const videos = res.body.data
287 videosListBase = videos
289 for (const video of videos) {
290 const videoName = video.name.replace(' name', '')
291 await testImage(server.url, videoName, video.thumbnailPath)
295 it('Should list only the two first videos', async function () {
296 const res = await getVideosListPagination(server.url, 0, 2, 'name')
298 const videos = res.body.data
299 expect(res.body.total).to.equal(6)
300 expect(videos.length).to.equal(2)
301 expect(videos[0].name).to.equal(videosListBase[0].name)
302 expect(videos[1].name).to.equal(videosListBase[1].name)
305 it('Should list only the next three videos', async function () {
306 const res = await getVideosListPagination(server.url, 2, 3, 'name')
308 const videos = res.body.data
309 expect(res.body.total).to.equal(6)
310 expect(videos.length).to.equal(3)
311 expect(videos[0].name).to.equal(videosListBase[2].name)
312 expect(videos[1].name).to.equal(videosListBase[3].name)
313 expect(videos[2].name).to.equal(videosListBase[4].name)
316 it('Should list the last video', async function () {
317 const res = await getVideosListPagination(server.url, 5, 6, 'name')
319 const videos = res.body.data
320 expect(res.body.total).to.equal(6)
321 expect(videos.length).to.equal(1)
322 expect(videos[0].name).to.equal(videosListBase[5].name)
325 it('Should not have the total field', async function () {
326 const res = await getVideosListPagination(server.url, 5, 6, 'name', true)
328 const videos = res.body.data
329 expect(res.body.total).to.not.exist
330 expect(videos.length).to.equal(1)
331 expect(videos[0].name).to.equal(videosListBase[5].name)
334 it('Should list and sort by name in descending order', async function () {
335 const res = await getVideosListSort(server.url, '-name')
337 const videos = res.body.data
338 expect(res.body.total).to.equal(6)
339 expect(videos.length).to.equal(6)
340 expect(videos[0].name).to.equal('video_short.webm name')
341 expect(videos[1].name).to.equal('video_short.ogv name')
342 expect(videos[2].name).to.equal('video_short.mp4 name')
343 expect(videos[3].name).to.equal('video_short3.webm name')
344 expect(videos[4].name).to.equal('video_short2.webm name')
345 expect(videos[5].name).to.equal('video_short1.webm name')
347 videoId = videos[3].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 update a video', async function () {
360 name: 'my super video updated',
365 description: 'my super description updated',
366 commentsEnabled: false,
367 downloadEnabled: false,
368 tags: [ 'tagup1', 'tagup2' ]
370 await updateVideo(server.url, server.accessToken, videoId, attributes)
373 it('Should filter by tags and category', async function () {
374 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 4 })
375 expect(res1.body.total).to.equal(1)
376 expect(res1.body.data[0].name).to.equal('my super video updated')
378 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 3 })
379 expect(res2.body.total).to.equal(0)
382 it('Should have the video updated', async function () {
385 const res = await getVideo(server.url, videoId)
386 const video = res.body
388 await completeVideoCheck(server.url, video, updateCheckAttributes())
391 it('Should update only the tags of a video', async function () {
393 tags: [ 'supertag', 'tag1', 'tag2' ]
395 await updateVideo(server.url, server.accessToken, videoId, attributes)
397 const res = await getVideo(server.url, videoId)
398 const video = res.body
400 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes))
403 it('Should update only the description of a video', async function () {
405 description: 'hello everybody'
407 await updateVideo(server.url, server.accessToken, videoId, attributes)
409 const res = await getVideo(server.url, videoId)
410 const video = res.body
412 const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
413 await completeVideoCheck(server.url, video, expectedAttributes)
416 it('Should like a video', async function () {
417 await rateVideo(server.url, server.accessToken, videoId, 'like')
419 const res = await getVideo(server.url, videoId)
420 const video = res.body
422 expect(video.likes).to.equal(1)
423 expect(video.dislikes).to.equal(0)
426 it('Should dislike the same video', async function () {
427 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
429 const res = await getVideo(server.url, videoId)
430 const video = res.body
432 expect(video.likes).to.equal(0)
433 expect(video.dislikes).to.equal(1)
436 after(async function () {
437 await cleanupTests([ server ])