1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { keyBy } from 'lodash'
6 import { join } from 'path'
7 import { VideoPrivacy } from '../../../../shared/models/videos'
9 completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, getVideoPrivacies,
10 getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, readdirPromise, removeVideo, runServer, searchVideo,
11 searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testVideoImage, updateVideo, uploadVideo, viewVideo
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 host: 'localhost:9001',
33 tags: [ 'tag1', 'tag2', 'tag3' ],
34 privacy: VideoPrivacy.PUBLIC,
36 name: 'Default root channel',
40 fixture: 'video_short.webm',
49 const updateCheckAttributes = {
50 name: 'my super video updated',
55 description: 'my super description updated',
56 host: 'localhost:9001',
59 tags: [ 'tagup1', 'tagup2' ],
60 privacy: VideoPrivacy.PUBLIC,
63 name: 'Default root channel',
67 fixture: 'video_short3.webm',
76 before(async function () {
81 server = await runServer(1)
83 await setAccessTokensToServers([ server ])
86 it('Should list video categories', async function () {
87 const res = await getVideoCategories(server.url)
89 const categories = res.body
90 expect(Object.keys(categories)).to.have.length.above(10)
92 expect(categories[11]).to.equal('News')
95 it('Should list video licences', async function () {
96 const res = await getVideoLicences(server.url)
98 const licences = res.body
99 expect(Object.keys(licences)).to.have.length.above(5)
101 expect(licences[3]).to.equal('Attribution - No Derivatives')
104 it('Should list video languages', async function () {
105 const res = await getVideoLanguages(server.url)
107 const languages = res.body
108 expect(Object.keys(languages)).to.have.length.above(5)
110 expect(languages[3]).to.equal('Mandarin')
113 it('Should list video privacies', async function () {
114 const res = await getVideoPrivacies(server.url)
116 const privacies = res.body
117 expect(Object.keys(privacies)).to.have.length.at.least(3)
119 expect(privacies[3]).to.equal('Private')
122 it('Should not have videos', async function () {
123 const res = await getVideosList(server.url)
125 expect(res.body.total).to.equal(0)
126 expect(res.body.data).to.be.an('array')
127 expect(res.body.data.length).to.equal(0)
130 it('Should upload the video', async function () {
131 const videoAttributes = {
132 name: 'my super name',
136 tags: [ 'tag1', 'tag2', 'tag3' ]
138 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
139 expect(res.body.video).to.not.be.undefined
140 expect(res.body.video.id).to.equal(1)
141 expect(res.body.video.uuid).to.have.length.above(5)
143 videoId = res.body.video.id
144 videoUUID = res.body.video.uuid
147 it('Should get and seed the uploaded video', async function () {
148 // Yes, this could be long
151 const res = await getVideosList(server.url)
153 expect(res.body.total).to.equal(1)
154 expect(res.body.data).to.be.an('array')
155 expect(res.body.data.length).to.equal(1)
157 const video = res.body.data[0]
158 await completeVideoCheck(server.url, video, getCheckAttributes)
161 it('Should get the video by UUID', async function () {
162 // Yes, this could be long
165 const res = await getVideo(server.url, videoUUID)
167 const video = res.body
168 await completeVideoCheck(server.url, video, getCheckAttributes)
171 it('Should have the views updated', async function () {
172 await viewVideo(server.url, videoId)
173 await viewVideo(server.url, videoId)
174 await viewVideo(server.url, videoId)
176 const res = await getVideo(server.url, videoId)
178 const video = res.body
179 expect(video.views).to.equal(3)
182 it('Should search the video by name', async function () {
183 const res = await searchVideo(server.url, 'my')
185 expect(res.body.total).to.equal(1)
186 expect(res.body.data).to.be.an('array')
187 expect(res.body.data.length).to.equal(1)
189 const video = res.body.data[0]
190 await completeVideoCheck(server.url, video, getCheckAttributes)
193 // Not implemented yet
194 // it('Should search the video by serverHost', async function () {
195 // const res = await videosUtils.searchVideo(server.url, '9001', 'host')
197 // expect(res.body.total).to.equal(1)
198 // expect(res.body.data).to.be.an('array')
199 // expect(res.body.data.length).to.equal(1)
201 // const video = res.body.data[0]
202 // expect(video.name).to.equal('my super name')
203 // expect(video.description).to.equal('my super description')
204 // expect(video.serverHost).to.equal('localhost:9001')
205 // expect(video.author).to.equal('root')
206 // expect(video.isLocal).to.be.true
207 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
208 // expect(dateIsValid(video.createdAt)).to.be.true
209 // expect(dateIsValid(video.updatedAt)).to.be.true
211 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
212 // expect(test).to.equal(true)
219 // Not implemented yet
220 // it('Should search the video by tag', async function () {
221 // const res = await searchVideo(server.url, 'tag1')
223 // expect(res.body.total).to.equal(1)
224 // expect(res.body.data).to.be.an('array')
225 // expect(res.body.data.length).to.equal(1)
227 // const video = res.body.data[0]
228 // expect(video.name).to.equal('my super name')
229 // expect(video.category).to.equal(2)
230 // expect(video.categoryLabel).to.equal('Films')
231 // expect(video.licence).to.equal(6)
232 // expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
233 // expect(video.language).to.equal(3)
234 // expect(video.languageLabel).to.equal('Mandarin')
235 // expect(video.nsfw).to.be.ok
236 // expect(video.description).to.equal('my super description')
237 // expect(video.serverHost).to.equal('localhost:9001')
238 // expect(video.accountName).to.equal('root')
239 // expect(video.isLocal).to.be.true
240 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
241 // expect(dateIsValid(video.createdAt)).to.be.true
242 // expect(dateIsValid(video.updatedAt)).to.be.true
244 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
245 // expect(test).to.equal(true)
248 it('Should not find a search by name', async function () {
249 const res = await searchVideo(server.url, 'hello')
251 expect(res.body.total).to.equal(0)
252 expect(res.body.data).to.be.an('array')
253 expect(res.body.data.length).to.equal(0)
256 // Not implemented yet
257 // it('Should not find a search by author', async function () {
258 // const res = await searchVideo(server.url, 'hello')
260 // expect(res.body.total).to.equal(0)
261 // expect(res.body.data).to.be.an('array')
262 // expect(res.body.data.length).to.equal(0)
265 // Not implemented yet
266 // it('Should not find a search by tag', async function () {
267 // const res = await searchVideo(server.url, 'hello')
269 // expect(res.body.total).to.equal(0)
270 // expect(res.body.data).to.be.an('array')
271 // expect(res.body.data.length).to.equal(0)
274 it('Should remove the video', async function () {
275 await removeVideo(server.url, server.accessToken, videoId)
277 const files1 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'videos'))
278 expect(files1).to.have.lengthOf(0)
280 const files2 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'thumbnails'))
281 expect(files2).to.have.lengthOf(0)
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 const test = await testVideoImage(server.url, videoName, video.thumbnailPath)
348 expect(test).to.equal(true)
352 it('Should list only the two first videos', async function () {
353 const res = await getVideosListPagination(server.url, 0, 2, 'name')
355 const videos = res.body.data
356 expect(res.body.total).to.equal(6)
357 expect(videos.length).to.equal(2)
358 expect(videos[0].name).to.equal(videosListBase[0].name)
359 expect(videos[1].name).to.equal(videosListBase[1].name)
362 it('Should list only the next three videos', async function () {
363 const res = await getVideosListPagination(server.url, 2, 3, 'name')
365 const videos = res.body.data
366 expect(res.body.total).to.equal(6)
367 expect(videos.length).to.equal(3)
368 expect(videos[0].name).to.equal(videosListBase[2].name)
369 expect(videos[1].name).to.equal(videosListBase[3].name)
370 expect(videos[2].name).to.equal(videosListBase[4].name)
373 it('Should list the last video', async function () {
374 const res = await getVideosListPagination(server.url, 5, 6, 'name')
376 const videos = res.body.data
377 expect(res.body.total).to.equal(6)
378 expect(videos.length).to.equal(1)
379 expect(videos[0].name).to.equal(videosListBase[5].name)
382 it('Should search the first video', async function () {
383 const res = await searchVideoWithPagination(server.url, 'webm', 0, 1, 'name')
385 const videos = res.body.data
386 expect(res.body.total).to.equal(4)
387 expect(videos.length).to.equal(1)
388 expect(videos[0].name).to.equal('video_short1.webm name')
391 it('Should search the last two videos', async function () {
392 const res = await searchVideoWithPagination(server.url, 'webm', 2, 2, 'name')
394 const videos = res.body.data
395 expect(res.body.total).to.equal(4)
396 expect(videos.length).to.equal(2)
397 expect(videos[0].name).to.equal('video_short3.webm name')
398 expect(videos[1].name).to.equal('video_short.webm name')
401 it('Should search all the webm videos', async function () {
402 const res = await searchVideoWithPagination(server.url, 'webm', 0, 15)
404 const videos = res.body.data
405 expect(res.body.total).to.equal(4)
406 expect(videos.length).to.equal(4)
409 // Not implemented yet
410 // it('Should search all the root author videos', async function () {
411 // const res = await searchVideoWithPagination(server.url, 'root', 0, 15)
413 // const videos = res.body.data
414 // expect(res.body.total).to.equal(6)
415 // expect(videos.length).to.equal(6)
418 // Not implemented yet
419 // it('Should search all the 9001 port videos', async function () {
420 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
422 // const videos = res.body.data
423 // expect(res.body.total).to.equal(6)
424 // expect(videos.length).to.equal(6)
430 // it('Should search all the localhost videos', async function () {
431 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
433 // const videos = res.body.data
434 // expect(res.body.total).to.equal(6)
435 // expect(videos.length).to.equal(6)
441 it('Should list and sort by name in descending order', async function () {
442 const res = await getVideosListSort(server.url, '-name')
444 const videos = res.body.data
445 expect(res.body.total).to.equal(6)
446 expect(videos.length).to.equal(6)
447 expect(videos[0].name).to.equal('video_short.webm name')
448 expect(videos[1].name).to.equal('video_short.ogv name')
449 expect(videos[2].name).to.equal('video_short.mp4 name')
450 expect(videos[3].name).to.equal('video_short3.webm name')
451 expect(videos[4].name).to.equal('video_short2.webm name')
452 expect(videos[5].name).to.equal('video_short1.webm name')
455 it('Should search and sort by name in ascending order', async function () {
456 const res = await searchVideoWithSort(server.url, 'webm', 'name')
458 const videos = res.body.data
459 expect(res.body.total).to.equal(4)
460 expect(videos.length).to.equal(4)
462 expect(videos[0].name).to.equal('video_short1.webm name')
463 expect(videos[1].name).to.equal('video_short2.webm name')
464 expect(videos[2].name).to.equal('video_short3.webm name')
465 expect(videos[3].name).to.equal('video_short.webm name')
467 videoId = videos[2].id
470 it('Should update a video', async function () {
472 name: 'my super video updated',
477 description: 'my super description updated',
478 tags: [ 'tagup1', 'tagup2' ]
480 await updateVideo(server.url, server.accessToken, videoId, attributes)
483 it('Should have the video updated', async function () {
486 const res = await getVideo(server.url, videoId)
487 const video = res.body
489 await completeVideoCheck(server.url, video, updateCheckAttributes)
492 it('Should update only the tags of a video', async function () {
494 tags: [ 'supertag', 'tag1', 'tag2' ]
496 await updateVideo(server.url, server.accessToken, videoId, attributes)
498 const res = await getVideo(server.url, videoId)
499 const video = res.body
501 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
504 it('Should update only the description of a video', async function () {
506 description: 'hello everybody'
508 await updateVideo(server.url, server.accessToken, videoId, attributes)
510 const res = await getVideo(server.url, videoId)
511 const video = res.body
513 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
516 it('Should like a video', async function () {
517 await rateVideo(server.url, server.accessToken, videoId, 'like')
519 const res = await getVideo(server.url, videoId)
520 const video = res.body
522 expect(video.likes).to.equal(1)
523 expect(video.dislikes).to.equal(0)
526 it('Should dislike the same video', async function () {
527 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
529 const res = await getVideo(server.url, videoId)
530 const video = res.body
532 expect(video.likes).to.equal(0)
533 expect(video.dislikes).to.equal(1)
536 after(async function () {
537 killallServers([ server ])
539 // Keep the logs if the test failed