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,
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,
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:9001'
86 tags: [ 'tagup1', 'tagup2' ],
87 privacy: VideoPrivacy.PUBLIC,
89 commentsEnabled: false,
92 displayName: 'Main root channel',
96 fixture: 'video_short3.webm',
105 before(async function () {
110 server = await runServer(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')
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 () {
242 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
243 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
246 const tasks: Promise<any>[] = []
247 for (const video of videos) {
248 const videoAttributes = {
249 name: video + ' name',
250 description: video + ' description',
255 tags: [ 'tag1', 'tag2', 'tag3' ],
259 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
263 await Promise.all(tasks)
266 it('Should have the correct durations', async function () {
267 const res = await getVideosList(server.url)
269 expect(res.body.total).to.equal(6)
270 const videos = res.body.data
271 expect(videos).to.be.an('array')
272 expect(videos).to.have.lengthOf(6)
274 const videosByName = keyBy<{ duration: number }>(videos, 'name')
275 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
276 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
277 expect(videosByName['video_short.webm name'].duration).to.equal(5)
278 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
279 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
280 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
283 it('Should have the correct thumbnails', async function () {
284 const res = await getVideosList(server.url)
286 const videos = res.body.data
288 videosListBase = videos
290 for (const video of videos) {
291 const videoName = video.name.replace(' name', '')
292 await testImage(server.url, videoName, video.thumbnailPath)
296 it('Should list only the two first videos', async function () {
297 const res = await getVideosListPagination(server.url, 0, 2, 'name')
299 const videos = res.body.data
300 expect(res.body.total).to.equal(6)
301 expect(videos.length).to.equal(2)
302 expect(videos[0].name).to.equal(videosListBase[0].name)
303 expect(videos[1].name).to.equal(videosListBase[1].name)
306 it('Should list only the next three videos', async function () {
307 const res = await getVideosListPagination(server.url, 2, 3, 'name')
309 const videos = res.body.data
310 expect(res.body.total).to.equal(6)
311 expect(videos.length).to.equal(3)
312 expect(videos[0].name).to.equal(videosListBase[2].name)
313 expect(videos[1].name).to.equal(videosListBase[3].name)
314 expect(videos[2].name).to.equal(videosListBase[4].name)
317 it('Should list the last video', async function () {
318 const res = await getVideosListPagination(server.url, 5, 6, 'name')
320 const videos = res.body.data
321 expect(res.body.total).to.equal(6)
322 expect(videos.length).to.equal(1)
323 expect(videos[0].name).to.equal(videosListBase[5].name)
326 it('Should list and sort by name in descending order', async function () {
327 const res = await getVideosListSort(server.url, '-name')
329 const videos = res.body.data
330 expect(res.body.total).to.equal(6)
331 expect(videos.length).to.equal(6)
332 expect(videos[0].name).to.equal('video_short.webm name')
333 expect(videos[1].name).to.equal('video_short.ogv name')
334 expect(videos[2].name).to.equal('video_short.mp4 name')
335 expect(videos[3].name).to.equal('video_short3.webm name')
336 expect(videos[4].name).to.equal('video_short2.webm name')
337 expect(videos[5].name).to.equal('video_short1.webm name')
339 videoId = videos[3].uuid
342 it('Should list and sort by trending in descending order', async function () {
343 const res = await getVideosListPagination(server.url, 0, 2, '-trending')
345 const videos = res.body.data
346 expect(res.body.total).to.equal(6)
347 expect(videos.length).to.equal(2)
350 it('Should update a video', async function () {
352 name: 'my super video updated',
357 description: 'my super description updated',
358 commentsEnabled: false,
359 tags: [ 'tagup1', 'tagup2' ]
361 await updateVideo(server.url, server.accessToken, videoId, attributes)
364 it('Should filter by tags and category', async function () {
365 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 4 })
366 expect(res1.body.total).to.equal(1)
367 expect(res1.body.data[0].name).to.equal('my super video updated')
369 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 3 })
370 expect(res2.body.total).to.equal(0)
373 it('Should have the video updated', async function () {
376 const res = await getVideo(server.url, videoId)
377 const video = res.body
379 await completeVideoCheck(server.url, video, updateCheckAttributes)
382 it('Should update only the tags of a video', async function () {
384 tags: [ 'supertag', 'tag1', 'tag2' ]
386 await updateVideo(server.url, server.accessToken, videoId, attributes)
388 const res = await getVideo(server.url, videoId)
389 const video = res.body
391 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
394 it('Should update only the description of a video', async function () {
396 description: 'hello everybody'
398 await updateVideo(server.url, server.accessToken, videoId, attributes)
400 const res = await getVideo(server.url, videoId)
401 const video = res.body
403 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
406 it('Should like a video', async function () {
407 await rateVideo(server.url, server.accessToken, videoId, 'like')
409 const res = await getVideo(server.url, videoId)
410 const video = res.body
412 expect(video.likes).to.equal(1)
413 expect(video.dislikes).to.equal(0)
416 it('Should dislike the same video', async function () {
417 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
419 const res = await getVideo(server.url, videoId)
420 const video = res.body
422 expect(video.likes).to.equal(0)
423 expect(video.dislikes).to.equal(1)
426 after(async function () {
427 killallServers([ server ])
429 // Keep the logs if the test failed