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'
17 getVideosListPagination,
25 searchVideoWithPagination,
28 setAccessTokensToServers,
34 viewVideo, completeVideoCheck, immutableAssign
37 const expect = chai.expect
39 describe('Test a single server', function () {
40 let server: ServerInfo = null
43 let videosListBase: any[] = null
45 const getCheckAttributes = {
46 name: 'my super name',
51 description: 'my super description',
52 host: 'localhost:9001',
56 tags: [ 'tag1', 'tag2', 'tag3' ],
57 privacy: VideoPrivacy.PUBLIC,
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 host: 'localhost:9001',
82 tags: [ 'tagup1', 'tagup2' ],
83 privacy: VideoPrivacy.PUBLIC,
86 name: 'Default root channel',
90 fixture: 'video_short3.webm',
99 before(async function () {
104 server = await runServer(1)
106 await setAccessTokensToServers([ server ])
109 it('Should list video categories', async function () {
110 const res = await getVideoCategories(server.url)
112 const categories = res.body
113 expect(Object.keys(categories)).to.have.length.above(10)
115 expect(categories[11]).to.equal('News')
118 it('Should list video licences', async function () {
119 const res = await getVideoLicences(server.url)
121 const licences = res.body
122 expect(Object.keys(licences)).to.have.length.above(5)
124 expect(licences[3]).to.equal('Attribution - No Derivatives')
127 it('Should list video languages', async function () {
128 const res = await getVideoLanguages(server.url)
130 const languages = res.body
131 expect(Object.keys(languages)).to.have.length.above(5)
133 expect(languages[3]).to.equal('Mandarin')
136 it('Should list video privacies', async function () {
137 const res = await getVideoPrivacies(server.url)
139 const privacies = res.body
140 expect(Object.keys(privacies)).to.have.length.at.least(3)
142 expect(privacies[3]).to.equal('Private')
145 it('Should not have videos', async function () {
146 const res = await getVideosList(server.url)
148 expect(res.body.total).to.equal(0)
149 expect(res.body.data).to.be.an('array')
150 expect(res.body.data.length).to.equal(0)
153 it('Should upload the video', async function () {
154 const videoAttributes = {
155 name: 'my super name',
159 tags: [ 'tag1', 'tag2', 'tag3' ]
161 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
162 expect(res.body.video).to.not.be.undefined
163 expect(res.body.video.id).to.equal(1)
164 expect(res.body.video.uuid).to.have.length.above(5)
166 videoId = res.body.video.id
167 videoUUID = res.body.video.uuid
170 it('Should get and seed the uploaded video', async function () {
171 // Yes, this could be long
174 const res = await getVideosList(server.url)
176 expect(res.body.total).to.equal(1)
177 expect(res.body.data).to.be.an('array')
178 expect(res.body.data.length).to.equal(1)
180 const video = res.body.data[0]
181 await completeVideoCheck(server.url, video, getCheckAttributes)
184 it('Should get the video by UUID', async function () {
185 // Yes, this could be long
188 const res = await getVideo(server.url, videoUUID)
190 const video = res.body
191 await completeVideoCheck(server.url, video, getCheckAttributes)
194 it('Should have the views updated', async function () {
195 await viewVideo(server.url, videoId)
196 await viewVideo(server.url, videoId)
197 await viewVideo(server.url, videoId)
199 const res = await getVideo(server.url, videoId)
201 const video = res.body
202 expect(video.views).to.equal(3)
205 it('Should search the video by name', async function () {
206 const res = await searchVideo(server.url, 'my')
208 expect(res.body.total).to.equal(1)
209 expect(res.body.data).to.be.an('array')
210 expect(res.body.data.length).to.equal(1)
212 const video = res.body.data[0]
213 await completeVideoCheck(server.url, video, getCheckAttributes)
216 // Not implemented yet
217 // it('Should search the video by serverHost', async function () {
218 // const res = await videosUtils.searchVideo(server.url, '9001', 'host')
220 // expect(res.body.total).to.equal(1)
221 // expect(res.body.data).to.be.an('array')
222 // expect(res.body.data.length).to.equal(1)
224 // const video = res.body.data[0]
225 // expect(video.name).to.equal('my super name')
226 // expect(video.description).to.equal('my super description')
227 // expect(video.serverHost).to.equal('localhost:9001')
228 // expect(video.author).to.equal('root')
229 // expect(video.isLocal).to.be.true
230 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
231 // expect(dateIsValid(video.createdAt)).to.be.true
232 // expect(dateIsValid(video.updatedAt)).to.be.true
234 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
235 // expect(test).to.equal(true)
242 // Not implemented yet
243 // it('Should search the video by tag', async function () {
244 // const res = await searchVideo(server.url, 'tag1')
246 // expect(res.body.total).to.equal(1)
247 // expect(res.body.data).to.be.an('array')
248 // expect(res.body.data.length).to.equal(1)
250 // const video = res.body.data[0]
251 // expect(video.name).to.equal('my super name')
252 // expect(video.category).to.equal(2)
253 // expect(video.categoryLabel).to.equal('Films')
254 // expect(video.licence).to.equal(6)
255 // expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
256 // expect(video.language).to.equal(3)
257 // expect(video.languageLabel).to.equal('Mandarin')
258 // expect(video.nsfw).to.be.ok
259 // expect(video.description).to.equal('my super description')
260 // expect(video.serverHost).to.equal('localhost:9001')
261 // expect(video.accountName).to.equal('root')
262 // expect(video.isLocal).to.be.true
263 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
264 // expect(dateIsValid(video.createdAt)).to.be.true
265 // expect(dateIsValid(video.updatedAt)).to.be.true
267 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
268 // expect(test).to.equal(true)
271 it('Should not find a search by name', async function () {
272 const res = await searchVideo(server.url, 'hello')
274 expect(res.body.total).to.equal(0)
275 expect(res.body.data).to.be.an('array')
276 expect(res.body.data.length).to.equal(0)
279 // Not implemented yet
280 // it('Should not find a search by author', async function () {
281 // const res = await searchVideo(server.url, 'hello')
283 // expect(res.body.total).to.equal(0)
284 // expect(res.body.data).to.be.an('array')
285 // expect(res.body.data.length).to.equal(0)
288 // Not implemented yet
289 // it('Should not find a search by tag', async function () {
290 // const res = await searchVideo(server.url, 'hello')
292 // expect(res.body.total).to.equal(0)
293 // expect(res.body.data).to.be.an('array')
294 // expect(res.body.data.length).to.equal(0)
297 it('Should remove the video', async function () {
298 await removeVideo(server.url, server.accessToken, videoId)
300 const files1 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'videos'))
301 expect(files1).to.have.lengthOf(0)
303 const files2 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'thumbnails'))
304 expect(files2).to.have.lengthOf(0)
307 it('Should not have videos', async function () {
308 const res = await getVideosList(server.url)
310 expect(res.body.total).to.equal(0)
311 expect(res.body.data).to.be.an('array')
312 expect(res.body.data).to.have.lengthOf(0)
315 it('Should upload 6 videos', async function () {
319 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
320 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
323 const tasks: Promise<any>[] = []
324 for (const video of videos) {
325 const videoAttributes = {
326 name: video + ' name',
327 description: video + ' description',
332 tags: [ 'tag1', 'tag2', 'tag3' ],
336 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
340 await Promise.all(tasks)
343 it('Should have the correct durations', async function () {
344 const res = await getVideosList(server.url)
346 expect(res.body.total).to.equal(6)
347 const videos = res.body.data
348 expect(videos).to.be.an('array')
349 expect(videos).to.have.lengthOf(6)
351 const videosByName = keyBy<{ duration: number }>(videos, 'name')
352 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
353 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
354 expect(videosByName['video_short.webm name'].duration).to.equal(5)
355 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
356 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
357 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
360 it('Should have the correct thumbnails', async function () {
361 const res = await getVideosList(server.url)
363 const videos = res.body.data
365 videosListBase = videos
367 for (const video of videos) {
368 const videoName = video.name.replace(' name', '')
369 const test = await testVideoImage(server.url, videoName, video.thumbnailPath)
371 expect(test).to.equal(true)
375 it('Should list only the two first videos', async function () {
376 const res = await getVideosListPagination(server.url, 0, 2, 'name')
378 const videos = res.body.data
379 expect(res.body.total).to.equal(6)
380 expect(videos.length).to.equal(2)
381 expect(videos[0].name).to.equal(videosListBase[0].name)
382 expect(videos[1].name).to.equal(videosListBase[1].name)
385 it('Should list only the next three videos', async function () {
386 const res = await getVideosListPagination(server.url, 2, 3, 'name')
388 const videos = res.body.data
389 expect(res.body.total).to.equal(6)
390 expect(videos.length).to.equal(3)
391 expect(videos[0].name).to.equal(videosListBase[2].name)
392 expect(videos[1].name).to.equal(videosListBase[3].name)
393 expect(videos[2].name).to.equal(videosListBase[4].name)
396 it('Should list the last video', async function () {
397 const res = await getVideosListPagination(server.url, 5, 6, 'name')
399 const videos = res.body.data
400 expect(res.body.total).to.equal(6)
401 expect(videos.length).to.equal(1)
402 expect(videos[0].name).to.equal(videosListBase[5].name)
405 it('Should search the first video', async function () {
406 const res = await searchVideoWithPagination(server.url, 'webm', 0, 1, 'name')
408 const videos = res.body.data
409 expect(res.body.total).to.equal(4)
410 expect(videos.length).to.equal(1)
411 expect(videos[0].name).to.equal('video_short1.webm name')
414 it('Should search the last two videos', async function () {
415 const res = await searchVideoWithPagination(server.url, 'webm', 2, 2, 'name')
417 const videos = res.body.data
418 expect(res.body.total).to.equal(4)
419 expect(videos.length).to.equal(2)
420 expect(videos[0].name).to.equal('video_short3.webm name')
421 expect(videos[1].name).to.equal('video_short.webm name')
424 it('Should search all the webm videos', async function () {
425 const res = await searchVideoWithPagination(server.url, 'webm', 0, 15)
427 const videos = res.body.data
428 expect(res.body.total).to.equal(4)
429 expect(videos.length).to.equal(4)
432 // Not implemented yet
433 // it('Should search all the root author videos', async function () {
434 // const res = await searchVideoWithPagination(server.url, 'root', 0, 15)
436 // const videos = res.body.data
437 // expect(res.body.total).to.equal(6)
438 // expect(videos.length).to.equal(6)
441 // Not implemented yet
442 // it('Should search all the 9001 port videos', async function () {
443 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
445 // const videos = res.body.data
446 // expect(res.body.total).to.equal(6)
447 // expect(videos.length).to.equal(6)
453 // it('Should search all the localhost videos', async function () {
454 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
456 // const videos = res.body.data
457 // expect(res.body.total).to.equal(6)
458 // expect(videos.length).to.equal(6)
464 it('Should list and sort by name in descending order', async function () {
465 const res = await getVideosListSort(server.url, '-name')
467 const videos = res.body.data
468 expect(res.body.total).to.equal(6)
469 expect(videos.length).to.equal(6)
470 expect(videos[0].name).to.equal('video_short.webm name')
471 expect(videos[1].name).to.equal('video_short.ogv name')
472 expect(videos[2].name).to.equal('video_short.mp4 name')
473 expect(videos[3].name).to.equal('video_short3.webm name')
474 expect(videos[4].name).to.equal('video_short2.webm name')
475 expect(videos[5].name).to.equal('video_short1.webm name')
478 it('Should search and sort by name in ascending order', async function () {
479 const res = await searchVideoWithSort(server.url, 'webm', 'name')
481 const videos = res.body.data
482 expect(res.body.total).to.equal(4)
483 expect(videos.length).to.equal(4)
485 expect(videos[0].name).to.equal('video_short1.webm name')
486 expect(videos[1].name).to.equal('video_short2.webm name')
487 expect(videos[2].name).to.equal('video_short3.webm name')
488 expect(videos[3].name).to.equal('video_short.webm name')
490 videoId = videos[2].id
493 it('Should update a video', async function () {
495 name: 'my super video updated',
500 description: 'my super description updated',
501 tags: [ 'tagup1', 'tagup2' ]
503 await updateVideo(server.url, server.accessToken, videoId, attributes)
506 it('Should have the video updated', async function () {
509 const res = await getVideo(server.url, videoId)
510 const video = res.body
512 await completeVideoCheck(server.url, video, updateCheckAttributes)
515 it('Should update only the tags of a video', async function () {
517 tags: [ 'supertag', 'tag1', 'tag2' ]
519 await updateVideo(server.url, server.accessToken, videoId, attributes)
521 const res = await getVideo(server.url, videoId)
522 const video = res.body
524 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
527 it('Should update only the description of a video', async function () {
529 description: 'hello everybody'
531 await updateVideo(server.url, server.accessToken, videoId, attributes)
533 const res = await getVideo(server.url, videoId)
534 const video = res.body
536 await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes, attributes))
539 it('Should like a video', async function () {
540 await rateVideo(server.url, server.accessToken, videoId, 'like')
542 const res = await getVideo(server.url, videoId)
543 const video = res.body
545 expect(video.likes).to.equal(1)
546 expect(video.dislikes).to.equal(0)
549 it('Should dislike the same video', async function () {
550 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
552 const res = await getVideo(server.url, videoId)
553 const video = res.body
555 expect(video.likes).to.equal(0)
556 expect(video.dislikes).to.equal(1)
559 after(async function () {
560 killallServers([ server ])
562 // Keep the logs if the test failed