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 name: 'Default root channel',
63 fixture: 'video_short.webm',
72 const updateCheckAttributes = {
73 name: 'my super video updated',
78 description: 'my super description updated',
79 support: 'my super support text updated',
82 host: 'localhost:9001'
85 tags: [ 'tagup1', 'tagup2' ],
86 privacy: VideoPrivacy.PUBLIC,
88 commentsEnabled: false,
90 name: 'Default root channel',
94 fixture: 'video_short3.webm',
103 before(async function () {
108 server = await runServer(1)
110 await setAccessTokensToServers([ server ])
113 it('Should list video categories', async function () {
114 const res = await getVideoCategories(server.url)
116 const categories = res.body
117 expect(Object.keys(categories)).to.have.length.above(10)
119 expect(categories[11]).to.equal('News')
122 it('Should list video licences', async function () {
123 const res = await getVideoLicences(server.url)
125 const licences = res.body
126 expect(Object.keys(licences)).to.have.length.above(5)
128 expect(licences[3]).to.equal('Attribution - No Derivatives')
131 it('Should list video languages', async function () {
132 const res = await getVideoLanguages(server.url)
134 const languages = res.body
135 expect(Object.keys(languages)).to.have.length.above(5)
137 expect(languages['ru']).to.equal('Russian')
140 it('Should list video privacies', async function () {
141 const res = await getVideoPrivacies(server.url)
143 const privacies = res.body
144 expect(Object.keys(privacies)).to.have.length.at.least(3)
146 expect(privacies[3]).to.equal('Private')
149 it('Should not have videos', async function () {
150 const res = await getVideosList(server.url)
152 expect(res.body.total).to.equal(0)
153 expect(res.body.data).to.be.an('array')
154 expect(res.body.data.length).to.equal(0)
157 it('Should upload the video', async function () {
158 const videoAttributes = {
159 name: 'my super name',
163 tags: [ 'tag1', 'tag2', 'tag3' ]
165 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
166 expect(res.body.video).to.not.be.undefined
167 expect(res.body.video.id).to.equal(1)
168 expect(res.body.video.uuid).to.have.length.above(5)
170 videoId = res.body.video.id
171 videoUUID = res.body.video.uuid
174 it('Should get and seed the uploaded video', async function () {
177 const res = await getVideosList(server.url)
179 expect(res.body.total).to.equal(1)
180 expect(res.body.data).to.be.an('array')
181 expect(res.body.data.length).to.equal(1)
183 const video = res.body.data[0]
184 await completeVideoCheck(server.url, video, getCheckAttributes)
187 it('Should get the video by UUID', async function () {
190 const res = await getVideo(server.url, videoUUID)
192 const video = res.body
193 await completeVideoCheck(server.url, video, getCheckAttributes)
196 it('Should have the views updated', async function () {
199 await viewVideo(server.url, videoId)
200 await viewVideo(server.url, videoId)
201 await viewVideo(server.url, videoId)
205 await viewVideo(server.url, videoId)
206 await viewVideo(server.url, videoId)
210 await viewVideo(server.url, videoId)
211 await viewVideo(server.url, videoId)
213 const res = await getVideo(server.url, videoId)
215 const video = res.body
216 expect(video.views).to.equal(3)
219 it('Should remove the video', async function () {
220 await removeVideo(server.url, server.accessToken, videoId)
222 await checkVideoFilesWereRemoved(videoUUID, 1)
225 it('Should not have videos', async function () {
226 const res = await getVideosList(server.url)
228 expect(res.body.total).to.equal(0)
229 expect(res.body.data).to.be.an('array')
230 expect(res.body.data).to.have.lengthOf(0)
233 it('Should upload 6 videos', async function () {
237 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
238 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
241 const tasks: Promise<any>[] = []
242 for (const video of videos) {
243 const videoAttributes = {
244 name: video + ' name',
245 description: video + ' description',
250 tags: [ 'tag1', 'tag2', 'tag3' ],
254 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
258 await Promise.all(tasks)
261 it('Should have the correct durations', async function () {
262 const res = await getVideosList(server.url)
264 expect(res.body.total).to.equal(6)
265 const videos = res.body.data
266 expect(videos).to.be.an('array')
267 expect(videos).to.have.lengthOf(6)
269 const videosByName = keyBy<{ duration: number }>(videos, 'name')
270 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
271 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
272 expect(videosByName['video_short.webm name'].duration).to.equal(5)
273 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
274 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
275 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
278 it('Should have the correct thumbnails', async function () {
279 const res = await getVideosList(server.url)
281 const videos = res.body.data
283 videosListBase = videos
285 for (const video of videos) {
286 const videoName = video.name.replace(' name', '')
287 await testImage(server.url, videoName, video.thumbnailPath)
291 it('Should list only the two first videos', async function () {
292 const res = await getVideosListPagination(server.url, 0, 2, 'name')
294 const videos = res.body.data
295 expect(res.body.total).to.equal(6)
296 expect(videos.length).to.equal(2)
297 expect(videos[0].name).to.equal(videosListBase[0].name)
298 expect(videos[1].name).to.equal(videosListBase[1].name)
301 it('Should list only the next three videos', async function () {
302 const res = await getVideosListPagination(server.url, 2, 3, 'name')
304 const videos = res.body.data
305 expect(res.body.total).to.equal(6)
306 expect(videos.length).to.equal(3)
307 expect(videos[0].name).to.equal(videosListBase[2].name)
308 expect(videos[1].name).to.equal(videosListBase[3].name)
309 expect(videos[2].name).to.equal(videosListBase[4].name)
312 it('Should list the last video', async function () {
313 const res = await getVideosListPagination(server.url, 5, 6, 'name')
315 const videos = res.body.data
316 expect(res.body.total).to.equal(6)
317 expect(videos.length).to.equal(1)
318 expect(videos[0].name).to.equal(videosListBase[5].name)
321 it('Should list and sort by name in descending order', async function () {
322 const res = await getVideosListSort(server.url, '-name')
324 const videos = res.body.data
325 expect(res.body.total).to.equal(6)
326 expect(videos.length).to.equal(6)
327 expect(videos[0].name).to.equal('video_short.webm name')
328 expect(videos[1].name).to.equal('video_short.ogv name')
329 expect(videos[2].name).to.equal('video_short.mp4 name')
330 expect(videos[3].name).to.equal('video_short3.webm name')
331 expect(videos[4].name).to.equal('video_short2.webm name')
332 expect(videos[5].name).to.equal('video_short1.webm name')
334 videoId = videos[3].uuid
337 it('Should update a video', async function () {
339 name: 'my super video updated',
344 description: 'my super description updated',
345 commentsEnabled: false,
346 tags: [ 'tagup1', 'tagup2' ]
348 await updateVideo(server.url, server.accessToken, videoId, attributes)
351 it('Should filter by tags and category', async function () {
352 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 4 })
353 expect(res1.body.total).to.equal(1)
354 expect(res1.body.data[0].name).to.equal('my super video updated')
356 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 3 })
357 expect(res2.body.total).to.equal(0)
360 it('Should have the video updated', async function () {
363 const res = await getVideo(server.url, videoId)
364 const video = res.body
366 await completeVideoCheck(server.url, video, updateCheckAttributes)
369 it('Should update only the tags of a video', async function () {
371 tags: [ 'supertag', 'tag1', 'tag2' ]
373 await updateVideo(server.url, server.accessToken, videoId, attributes)
375 const res = await getVideo(server.url, videoId)
376 const video = res.body
378 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
381 it('Should update only the description of a video', async function () {
383 description: 'hello everybody'
385 await updateVideo(server.url, server.accessToken, videoId, attributes)
387 const res = await getVideo(server.url, videoId)
388 const video = res.body
390 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
393 it('Should like a video', async function () {
394 await rateVideo(server.url, server.accessToken, videoId, 'like')
396 const res = await getVideo(server.url, videoId)
397 const video = res.body
399 expect(video.likes).to.equal(1)
400 expect(video.dislikes).to.equal(0)
403 it('Should dislike the same video', async function () {
404 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
406 const res = await getVideo(server.url, videoId)
407 const video = res.body
409 expect(video.likes).to.equal(0)
410 expect(video.dislikes).to.equal(1)
413 after(async function () {
414 killallServers([ server ])
416 // Keep the logs if the test failed