1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { keyBy } from 'lodash'
6 import { VideoPrivacy } from '../../../../shared/models/videos'
8 checkVideoFilesWereRemoved,
17 getVideosListPagination,
25 setAccessTokensToServers,
31 } from '../../../../shared/utils'
33 const expect = chai.expect
35 describe('Test a single server', function () {
36 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:9001'
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:9001'
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 () {
112 server = await runServer(1)
114 await setAccessTokensToServers([ server ])
117 it('Should list video categories', async function () {
118 const res = await getVideoCategories(server.url)
120 const categories = res.body
121 expect(Object.keys(categories)).to.have.length.above(10)
123 expect(categories[11]).to.equal('News & Politics')
126 it('Should list video licences', async function () {
127 const res = await getVideoLicences(server.url)
129 const licences = res.body
130 expect(Object.keys(licences)).to.have.length.above(5)
132 expect(licences[3]).to.equal('Attribution - No Derivatives')
135 it('Should list video languages', async function () {
136 const res = await getVideoLanguages(server.url)
138 const languages = res.body
139 expect(Object.keys(languages)).to.have.length.above(5)
141 expect(languages['ru']).to.equal('Russian')
144 it('Should list video privacies', async function () {
145 const res = await getVideoPrivacies(server.url)
147 const privacies = res.body
148 expect(Object.keys(privacies)).to.have.length.at.least(3)
150 expect(privacies[3]).to.equal('Private')
153 it('Should not have videos', async function () {
154 const res = await getVideosList(server.url)
156 expect(res.body.total).to.equal(0)
157 expect(res.body.data).to.be.an('array')
158 expect(res.body.data.length).to.equal(0)
161 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 () {
244 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
245 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
248 const tasks: Promise<any>[] = []
249 for (const video of videos) {
250 const videoAttributes = {
251 name: video + ' name',
252 description: video + ' description',
257 tags: [ 'tag1', 'tag2', 'tag3' ],
261 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
265 await Promise.all(tasks)
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 list and sort by name in descending order', async function () {
329 const res = await getVideosListSort(server.url, '-name')
331 const videos = res.body.data
332 expect(res.body.total).to.equal(6)
333 expect(videos.length).to.equal(6)
334 expect(videos[0].name).to.equal('video_short.webm name')
335 expect(videos[1].name).to.equal('video_short.ogv name')
336 expect(videos[2].name).to.equal('video_short.mp4 name')
337 expect(videos[3].name).to.equal('video_short3.webm name')
338 expect(videos[4].name).to.equal('video_short2.webm name')
339 expect(videos[5].name).to.equal('video_short1.webm name')
341 videoId = videos[3].uuid
344 it('Should list and sort by trending in descending order', async function () {
345 const res = await getVideosListPagination(server.url, 0, 2, '-trending')
347 const videos = res.body.data
348 expect(res.body.total).to.equal(6)
349 expect(videos.length).to.equal(2)
352 it('Should update a video', async function () {
354 name: 'my super video updated',
359 description: 'my super description updated',
360 commentsEnabled: false,
361 downloadEnabled: false,
362 tags: [ 'tagup1', 'tagup2' ]
364 await updateVideo(server.url, server.accessToken, videoId, attributes)
367 it('Should filter by tags and category', async function () {
368 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 4 })
369 expect(res1.body.total).to.equal(1)
370 expect(res1.body.data[0].name).to.equal('my super video updated')
372 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 3 })
373 expect(res2.body.total).to.equal(0)
376 it('Should have the video updated', async function () {
379 const res = await getVideo(server.url, videoId)
380 const video = res.body
382 await completeVideoCheck(server.url, video, updateCheckAttributes)
385 it('Should update only the tags of a video', async function () {
387 tags: [ 'supertag', 'tag1', 'tag2' ]
389 await updateVideo(server.url, server.accessToken, videoId, attributes)
391 const res = await getVideo(server.url, videoId)
392 const video = res.body
394 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
397 it('Should update only the description of a video', async function () {
399 description: 'hello everybody'
401 await updateVideo(server.url, server.accessToken, videoId, attributes)
403 const res = await getVideo(server.url, videoId)
404 const video = res.body
406 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
409 it('Should like a video', async function () {
410 await rateVideo(server.url, server.accessToken, videoId, 'like')
412 const res = await getVideo(server.url, videoId)
413 const video = res.body
415 expect(video.likes).to.equal(1)
416 expect(video.dislikes).to.equal(0)
419 it('Should dislike the same video', async function () {
420 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
422 const res = await getVideo(server.url, videoId)
423 const video = res.body
425 expect(video.likes).to.equal(0)
426 expect(video.dislikes).to.equal(1)
429 after(async function () {
430 killallServers([ server ])
432 // Keep the logs if the test failed