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, completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences,
9 getVideoPrivacies, getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer,
10 searchVideo, searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testImage, updateVideo, uploadVideo,
14 const expect = chai.expect
16 describe('Test a single server', function () {
17 let server: ServerInfo = null
20 let videosListBase: any[] = null
22 const getCheckAttributes = {
23 name: 'my super name',
28 description: 'my super description',
29 support: 'my super support text',
30 host: 'localhost:9001',
34 tags: [ 'tag1', 'tag2', 'tag3' ],
35 privacy: VideoPrivacy.PUBLIC,
36 commentsEnabled: true,
38 name: 'Default root channel',
42 fixture: 'video_short.webm',
51 const updateCheckAttributes = {
52 name: 'my super video updated',
57 description: 'my super description updated',
58 support: 'my super support text updated',
59 host: 'localhost:9001',
62 tags: [ 'tagup1', 'tagup2' ],
63 privacy: VideoPrivacy.PUBLIC,
65 commentsEnabled: false,
67 name: 'Default root channel',
71 fixture: 'video_short3.webm',
80 before(async function () {
85 server = await runServer(1)
87 await setAccessTokensToServers([ server ])
90 it('Should list video categories', async function () {
91 const res = await getVideoCategories(server.url)
93 const categories = res.body
94 expect(Object.keys(categories)).to.have.length.above(10)
96 expect(categories[11]).to.equal('News')
99 it('Should list video licences', async function () {
100 const res = await getVideoLicences(server.url)
102 const licences = res.body
103 expect(Object.keys(licences)).to.have.length.above(5)
105 expect(licences[3]).to.equal('Attribution - No Derivatives')
108 it('Should list video languages', async function () {
109 const res = await getVideoLanguages(server.url)
111 const languages = res.body
112 expect(Object.keys(languages)).to.have.length.above(5)
114 expect(languages[3]).to.equal('Mandarin')
117 it('Should list video privacies', async function () {
118 const res = await getVideoPrivacies(server.url)
120 const privacies = res.body
121 expect(Object.keys(privacies)).to.have.length.at.least(3)
123 expect(privacies[3]).to.equal('Private')
126 it('Should not have videos', async function () {
127 const res = await getVideosList(server.url)
129 expect(res.body.total).to.equal(0)
130 expect(res.body.data).to.be.an('array')
131 expect(res.body.data.length).to.equal(0)
134 it('Should upload the video', async function () {
135 const videoAttributes = {
136 name: 'my super name',
140 tags: [ 'tag1', 'tag2', 'tag3' ]
142 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
143 expect(res.body.video).to.not.be.undefined
144 expect(res.body.video.id).to.equal(1)
145 expect(res.body.video.uuid).to.have.length.above(5)
147 videoId = res.body.video.id
148 videoUUID = res.body.video.uuid
151 it('Should get and seed the uploaded video', async function () {
152 // Yes, this could be long
155 const res = await getVideosList(server.url)
157 expect(res.body.total).to.equal(1)
158 expect(res.body.data).to.be.an('array')
159 expect(res.body.data.length).to.equal(1)
161 const video = res.body.data[0]
162 await completeVideoCheck(server.url, video, getCheckAttributes)
165 it('Should get the video by UUID', async function () {
166 // Yes, this could be long
169 const res = await getVideo(server.url, videoUUID)
171 const video = res.body
172 await completeVideoCheck(server.url, video, getCheckAttributes)
175 it('Should have the views updated', async function () {
176 await viewVideo(server.url, videoId)
177 await viewVideo(server.url, videoId)
178 await viewVideo(server.url, videoId)
180 const res = await getVideo(server.url, videoId)
182 const video = res.body
183 expect(video.views).to.equal(3)
186 it('Should search the video by name', async function () {
187 const res = await searchVideo(server.url, 'my')
189 expect(res.body.total).to.equal(1)
190 expect(res.body.data).to.be.an('array')
191 expect(res.body.data.length).to.equal(1)
193 const video = res.body.data[0]
194 await completeVideoCheck(server.url, video, getCheckAttributes)
197 // Not implemented yet
198 // it('Should search the video by serverHost', async function () {
199 // const res = await videosUtils.searchVideo(server.url, '9001', 'host')
201 // expect(res.body.total).to.equal(1)
202 // expect(res.body.data).to.be.an('array')
203 // expect(res.body.data.length).to.equal(1)
205 // const video = res.body.data[0]
206 // expect(video.name).to.equal('my super name')
207 // expect(video.description).to.equal('my super description')
208 // expect(video.serverHost).to.equal('localhost:9001')
209 // expect(video.author).to.equal('root')
210 // expect(video.isLocal).to.be.true
211 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
212 // expect(dateIsValid(video.createdAt)).to.be.true
213 // expect(dateIsValid(video.updatedAt)).to.be.true
215 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
216 // expect(test).to.equal(true)
223 // Not implemented yet
224 // it('Should search the video by tag', async function () {
225 // const res = await searchVideo(server.url, 'tag1')
227 // expect(res.body.total).to.equal(1)
228 // expect(res.body.data).to.be.an('array')
229 // expect(res.body.data.length).to.equal(1)
231 // const video = res.body.data[0]
232 // expect(video.name).to.equal('my super name')
233 // expect(video.category).to.equal(2)
234 // expect(video.categoryLabel).to.equal('Films')
235 // expect(video.licence).to.equal(6)
236 // expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
237 // expect(video.language).to.equal(3)
238 // expect(video.languageLabel).to.equal('Mandarin')
239 // expect(video.nsfw).to.be.ok
240 // expect(video.description).to.equal('my super description')
241 // expect(video.serverHost).to.equal('localhost:9001')
242 // expect(video.accountName).to.equal('root')
243 // expect(video.isLocal).to.be.true
244 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
245 // expect(dateIsValid(video.createdAt)).to.be.true
246 // expect(dateIsValid(video.updatedAt)).to.be.true
248 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
249 // expect(test).to.equal(true)
252 it('Should not find a search by name', async function () {
253 const res = await searchVideo(server.url, 'hello')
255 expect(res.body.total).to.equal(0)
256 expect(res.body.data).to.be.an('array')
257 expect(res.body.data.length).to.equal(0)
260 // Not implemented yet
261 // it('Should not find a search by author', async function () {
262 // const res = await searchVideo(server.url, 'hello')
264 // expect(res.body.total).to.equal(0)
265 // expect(res.body.data).to.be.an('array')
266 // expect(res.body.data.length).to.equal(0)
269 // Not implemented yet
270 // it('Should not find a search by tag', async function () {
271 // const res = await searchVideo(server.url, 'hello')
273 // expect(res.body.total).to.equal(0)
274 // expect(res.body.data).to.be.an('array')
275 // expect(res.body.data.length).to.equal(0)
278 it('Should remove the video', async function () {
279 await removeVideo(server.url, server.accessToken, videoId)
281 await checkVideoFilesWereRemoved(videoUUID, 1)
284 it('Should not have videos', async function () {
285 const res = await getVideosList(server.url)
287 expect(res.body.total).to.equal(0)
288 expect(res.body.data).to.be.an('array')
289 expect(res.body.data).to.have.lengthOf(0)
292 it('Should upload 6 videos', async function () {
296 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
297 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
300 const tasks: Promise<any>[] = []
301 for (const video of videos) {
302 const videoAttributes = {
303 name: video + ' name',
304 description: video + ' description',
309 tags: [ 'tag1', 'tag2', 'tag3' ],
313 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
317 await Promise.all(tasks)
320 it('Should have the correct durations', async function () {
321 const res = await getVideosList(server.url)
323 expect(res.body.total).to.equal(6)
324 const videos = res.body.data
325 expect(videos).to.be.an('array')
326 expect(videos).to.have.lengthOf(6)
328 const videosByName = keyBy<{ duration: number }>(videos, 'name')
329 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
330 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
331 expect(videosByName['video_short.webm name'].duration).to.equal(5)
332 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
333 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
334 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
337 it('Should have the correct thumbnails', async function () {
338 const res = await getVideosList(server.url)
340 const videos = res.body.data
342 videosListBase = videos
344 for (const video of videos) {
345 const videoName = video.name.replace(' name', '')
346 await testImage(server.url, videoName, video.thumbnailPath)
350 it('Should list only the two first videos', async function () {
351 const res = await getVideosListPagination(server.url, 0, 2, 'name')
353 const videos = res.body.data
354 expect(res.body.total).to.equal(6)
355 expect(videos.length).to.equal(2)
356 expect(videos[0].name).to.equal(videosListBase[0].name)
357 expect(videos[1].name).to.equal(videosListBase[1].name)
360 it('Should list only the next three videos', async function () {
361 const res = await getVideosListPagination(server.url, 2, 3, 'name')
363 const videos = res.body.data
364 expect(res.body.total).to.equal(6)
365 expect(videos.length).to.equal(3)
366 expect(videos[0].name).to.equal(videosListBase[2].name)
367 expect(videos[1].name).to.equal(videosListBase[3].name)
368 expect(videos[2].name).to.equal(videosListBase[4].name)
371 it('Should list the last video', async function () {
372 const res = await getVideosListPagination(server.url, 5, 6, 'name')
374 const videos = res.body.data
375 expect(res.body.total).to.equal(6)
376 expect(videos.length).to.equal(1)
377 expect(videos[0].name).to.equal(videosListBase[5].name)
380 it('Should search the first video', async function () {
381 const res = await searchVideoWithPagination(server.url, 'webm', 0, 1, 'name')
383 const videos = res.body.data
384 expect(res.body.total).to.equal(4)
385 expect(videos.length).to.equal(1)
386 expect(videos[0].name).to.equal('video_short1.webm name')
389 it('Should search the last two videos', async function () {
390 const res = await searchVideoWithPagination(server.url, 'webm', 2, 2, 'name')
392 const videos = res.body.data
393 expect(res.body.total).to.equal(4)
394 expect(videos.length).to.equal(2)
395 expect(videos[0].name).to.equal('video_short3.webm name')
396 expect(videos[1].name).to.equal('video_short.webm name')
399 it('Should search all the webm videos', async function () {
400 const res = await searchVideoWithPagination(server.url, 'webm', 0, 15)
402 const videos = res.body.data
403 expect(res.body.total).to.equal(4)
404 expect(videos.length).to.equal(4)
407 // Not implemented yet
408 // it('Should search all the root author videos', async function () {
409 // const res = await searchVideoWithPagination(server.url, 'root', 0, 15)
411 // const videos = res.body.data
412 // expect(res.body.total).to.equal(6)
413 // expect(videos.length).to.equal(6)
416 // Not implemented yet
417 // it('Should search all the 9001 port videos', async function () {
418 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
420 // const videos = res.body.data
421 // expect(res.body.total).to.equal(6)
422 // expect(videos.length).to.equal(6)
428 // it('Should search all the localhost videos', async function () {
429 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
431 // const videos = res.body.data
432 // expect(res.body.total).to.equal(6)
433 // expect(videos.length).to.equal(6)
439 it('Should list and sort by name in descending order', async function () {
440 const res = await getVideosListSort(server.url, '-name')
442 const videos = res.body.data
443 expect(res.body.total).to.equal(6)
444 expect(videos.length).to.equal(6)
445 expect(videos[0].name).to.equal('video_short.webm name')
446 expect(videos[1].name).to.equal('video_short.ogv name')
447 expect(videos[2].name).to.equal('video_short.mp4 name')
448 expect(videos[3].name).to.equal('video_short3.webm name')
449 expect(videos[4].name).to.equal('video_short2.webm name')
450 expect(videos[5].name).to.equal('video_short1.webm name')
453 it('Should search and sort by name in ascending order', async function () {
454 const res = await searchVideoWithSort(server.url, 'webm', 'name')
456 const videos = res.body.data
457 expect(res.body.total).to.equal(4)
458 expect(videos.length).to.equal(4)
460 expect(videos[0].name).to.equal('video_short1.webm name')
461 expect(videos[1].name).to.equal('video_short2.webm name')
462 expect(videos[2].name).to.equal('video_short3.webm name')
463 expect(videos[3].name).to.equal('video_short.webm name')
465 videoId = videos[2].id
468 it('Should update a video', async function () {
470 name: 'my super video updated',
475 description: 'my super description updated',
476 commentsEnabled: false,
477 tags: [ 'tagup1', 'tagup2' ]
479 await updateVideo(server.url, server.accessToken, videoId, attributes)
482 it('Should have the video updated', async function () {
485 const res = await getVideo(server.url, videoId)
486 const video = res.body
488 await completeVideoCheck(server.url, video, updateCheckAttributes)
491 it('Should update only the tags of a video', async function () {
493 tags: [ 'supertag', 'tag1', 'tag2' ]
495 await updateVideo(server.url, server.accessToken, videoId, attributes)
497 const res = await getVideo(server.url, videoId)
498 const video = res.body
500 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
503 it('Should update only the description of a video', async function () {
505 description: 'hello everybody'
507 await updateVideo(server.url, server.accessToken, videoId, attributes)
509 const res = await getVideo(server.url, videoId)
510 const video = res.body
512 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
515 it('Should like a video', async function () {
516 await rateVideo(server.url, server.accessToken, videoId, 'like')
518 const res = await getVideo(server.url, videoId)
519 const video = res.body
521 expect(video.likes).to.equal(1)
522 expect(video.dislikes).to.equal(0)
525 it('Should dislike the same video', async function () {
526 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
528 const res = await getVideo(server.url, videoId)
529 const video = res.body
531 expect(video.likes).to.equal(0)
532 expect(video.dislikes).to.equal(1)
535 after(async function () {
536 killallServers([ server ])
538 // Keep the logs if the test failed