1 /* tslint:disable:no-unused-expression */
3 import { keyBy } from 'lodash'
4 import { join } from 'path'
6 import * as chai from 'chai'
7 const expect = chai.expect
18 setAccessTokensToServers,
30 getVideosListPagination,
31 searchVideoWithPagination,
36 import { viewVideo } from '../utils/videos'
38 describe('Test a single server', function () {
39 let server: ServerInfo = null
42 let videosListBase: any[] = null
44 before(async function () {
49 server = await runServer(1)
51 await setAccessTokensToServers([ server ])
54 it('Should list video categories', async function () {
55 const res = await getVideoCategories(server.url)
57 const categories = res.body
58 expect(Object.keys(categories)).to.have.length.above(10)
60 expect(categories[11]).to.equal('News')
63 it('Should list video licences', async function () {
64 const res = await getVideoLicences(server.url)
66 const licences = res.body
67 expect(Object.keys(licences)).to.have.length.above(5)
69 expect(licences[3]).to.equal('Attribution - No Derivatives')
72 it('Should list video languages', async function () {
73 const res = await getVideoLanguages(server.url)
75 const languages = res.body
76 expect(Object.keys(languages)).to.have.length.above(5)
78 expect(languages[3]).to.equal('Mandarin')
81 it('Should list video privacies', async function () {
82 const res = await getVideoPrivacies(server.url)
84 const privacies = res.body
85 expect(Object.keys(privacies)).to.have.length.at.least(3)
87 expect(privacies[3]).to.equal('Private')
90 it('Should not have videos', async function () {
91 const res = await getVideosList(server.url)
93 expect(res.body.total).to.equal(0)
94 expect(res.body.data).to.be.an('array')
95 expect(res.body.data.length).to.equal(0)
98 it('Should upload the video', async function () {
99 const videoAttributes = {
100 name: 'my super name',
104 tags: [ 'tag1', 'tag2', 'tag3' ]
106 await uploadVideo(server.url, server.accessToken, videoAttributes)
109 it('Should seed the uploaded video', async function () {
110 // Yes, this could be long
113 const res = await getVideosList(server.url)
115 expect(res.body.total).to.equal(1)
116 expect(res.body.data).to.be.an('array')
117 expect(res.body.data.length).to.equal(1)
119 const video = res.body.data[0]
120 expect(video.name).to.equal('my super name')
121 expect(video.category).to.equal(2)
122 expect(video.categoryLabel).to.equal('Films')
123 expect(video.licence).to.equal(6)
124 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
125 expect(video.language).to.equal(3)
126 expect(video.languageLabel).to.equal('Mandarin')
127 expect(video.nsfw).to.be.ok
128 expect(video.description).to.equal('my super description')
129 expect(video.serverHost).to.equal('localhost:9001')
130 expect(video.account).to.equal('root')
131 expect(video.isLocal).to.be.true
132 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
133 expect(dateIsValid(video.createdAt)).to.be.true
134 expect(dateIsValid(video.updatedAt)).to.be.true
136 const res2 = await getVideo(server.url, res.body.data[0].id)
137 const videoDetails = res2.body
139 expect(videoDetails.files).to.have.lengthOf(1)
141 const file = videoDetails.files[0]
142 const magnetUri = file.magnetUri
143 expect(file.magnetUri).to.have.lengthOf.above(2)
144 expect(file.torrentUrl).to.equal(`${server.url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
145 expect(file.fileUrl).to.equal(`${server.url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
146 expect(file.resolution).to.equal(720)
147 expect(file.resolutionLabel).to.equal('720p')
148 expect(file.size).to.equal(218910)
150 const test = await testVideoImage(server.url, 'video_short.webm', videoDetails.thumbnailPath)
151 expect(test).to.equal(true)
153 videoId = videoDetails.id
154 videoUUID = videoDetails.uuid
156 const torrent = await webtorrentAdd(magnetUri)
157 expect(torrent.files).to.be.an('array')
158 expect(torrent.files.length).to.equal(1)
159 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
162 it('Should get the video', async function () {
163 // Yes, this could be long
166 const res = await getVideo(server.url, videoId)
168 const video = res.body
169 expect(video.name).to.equal('my super name')
170 expect(video.category).to.equal(2)
171 expect(video.categoryLabel).to.equal('Films')
172 expect(video.licence).to.equal(6)
173 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
174 expect(video.language).to.equal(3)
175 expect(video.languageLabel).to.equal('Mandarin')
176 expect(video.nsfw).to.be.ok
177 expect(video.description).to.equal('my super description')
178 expect(video.serverHost).to.equal('localhost:9001')
179 expect(video.account).to.equal('root')
180 expect(video.isLocal).to.be.true
181 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
182 expect(dateIsValid(video.createdAt)).to.be.true
183 expect(dateIsValid(video.updatedAt)).to.be.true
184 expect(video.channel.name).to.equal('Default root channel')
185 expect(video.channel.isLocal).to.be.true
186 expect(dateIsValid(video.channel.createdAt)).to.be.true
187 expect(dateIsValid(video.channel.updatedAt)).to.be.true
189 expect(video.files).to.have.lengthOf(1)
191 const file = video.files[0]
192 expect(file.magnetUri).to.have.lengthOf.above(2)
193 expect(file.resolution).to.equal(720)
194 expect(file.resolutionLabel).to.equal('720p')
195 expect(file.size).to.equal(218910)
197 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
198 expect(test).to.equal(true)
200 // Wait the async views increment
204 it('Should get the video by UUID', async function () {
205 // Yes, this could be long
208 const res = await getVideo(server.url, videoUUID)
210 const video = res.body
211 expect(video.name).to.equal('my super name')
213 // Wait the async views increment
217 it('Should have the views updated', async function () {
218 await viewVideo(server.url, videoId)
219 await viewVideo(server.url, videoId)
220 await viewVideo(server.url, videoId)
222 const res = await getVideo(server.url, videoId)
224 const video = res.body
225 expect(video.views).to.equal(3)
228 it('Should search the video by name by default', async function () {
229 const res = await searchVideo(server.url, 'my')
231 expect(res.body.total).to.equal(1)
232 expect(res.body.data).to.be.an('array')
233 expect(res.body.data.length).to.equal(1)
235 const video = res.body.data[0]
236 expect(video.name).to.equal('my super name')
237 expect(video.category).to.equal(2)
238 expect(video.categoryLabel).to.equal('Films')
239 expect(video.licence).to.equal(6)
240 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
241 expect(video.language).to.equal(3)
242 expect(video.languageLabel).to.equal('Mandarin')
243 expect(video.nsfw).to.be.ok
244 expect(video.description).to.equal('my super description')
245 expect(video.serverHost).to.equal('localhost:9001')
246 expect(video.account).to.equal('root')
247 expect(video.isLocal).to.be.true
248 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
249 expect(dateIsValid(video.createdAt)).to.be.true
250 expect(dateIsValid(video.updatedAt)).to.be.true
252 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
253 expect(test).to.equal(true)
256 // Not implemented yet
257 // it('Should search the video by serverHost', async function () {
258 // const res = await videosUtils.searchVideo(server.url, '9001', 'host')
260 // expect(res.body.total).to.equal(1)
261 // expect(res.body.data).to.be.an('array')
262 // expect(res.body.data.length).to.equal(1)
264 // const video = res.body.data[0]
265 // expect(video.name).to.equal('my super name')
266 // expect(video.description).to.equal('my super description')
267 // expect(video.serverHost).to.equal('localhost:9001')
268 // expect(video.author).to.equal('root')
269 // expect(video.isLocal).to.be.true
270 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
271 // expect(dateIsValid(video.createdAt)).to.be.true
272 // expect(dateIsValid(video.updatedAt)).to.be.true
274 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
275 // expect(test).to.equal(true)
282 it('Should search the video by tag', async function () {
283 const res = await searchVideo(server.url, 'tag1', 'tags')
285 expect(res.body.total).to.equal(1)
286 expect(res.body.data).to.be.an('array')
287 expect(res.body.data.length).to.equal(1)
289 const video = res.body.data[0]
290 expect(video.name).to.equal('my super name')
291 expect(video.category).to.equal(2)
292 expect(video.categoryLabel).to.equal('Films')
293 expect(video.licence).to.equal(6)
294 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
295 expect(video.language).to.equal(3)
296 expect(video.languageLabel).to.equal('Mandarin')
297 expect(video.nsfw).to.be.ok
298 expect(video.description).to.equal('my super description')
299 expect(video.serverHost).to.equal('localhost:9001')
300 expect(video.account).to.equal('root')
301 expect(video.isLocal).to.be.true
302 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
303 expect(dateIsValid(video.createdAt)).to.be.true
304 expect(dateIsValid(video.updatedAt)).to.be.true
306 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
307 expect(test).to.equal(true)
310 it('Should not find a search by name by default', async function () {
311 const res = await searchVideo(server.url, 'hello')
313 expect(res.body.total).to.equal(0)
314 expect(res.body.data).to.be.an('array')
315 expect(res.body.data.length).to.equal(0)
318 it('Should not find a search by author', async function () {
319 const res = await searchVideo(server.url, 'hello', 'account')
321 expect(res.body.total).to.equal(0)
322 expect(res.body.data).to.be.an('array')
323 expect(res.body.data.length).to.equal(0)
326 it('Should not find a search by tag', async function () {
327 const res = await searchVideo(server.url, 'hello', 'tags')
329 expect(res.body.total).to.equal(0)
330 expect(res.body.data).to.be.an('array')
331 expect(res.body.data.length).to.equal(0)
334 it('Should remove the video', async function () {
335 await removeVideo(server.url, server.accessToken, videoId)
337 const files1 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/videos/'))
338 expect(files1).to.have.lengthOf(0)
340 const files2 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/thumbnails/'))
341 expect(files2).to.have.lengthOf(0)
344 it('Should not have videos', async function () {
345 const res = await getVideosList(server.url)
347 expect(res.body.total).to.equal(0)
348 expect(res.body.data).to.be.an('array')
349 expect(res.body.data).to.have.lengthOf(0)
352 it('Should upload 6 videos', async function () {
356 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
357 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
360 // const tasks: Promise<any>[] = []
361 for (const video of videos) {
362 const videoAttributes = {
363 name: video + ' name',
364 description: video + ' description',
369 tags: [ 'tag1', 'tag2', 'tag3' ],
373 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
376 // FIXME: concurrent uploads does not work :(
380 // await Promise.all(tasks)
383 it('Should have the correct durations', async function () {
384 const res = await getVideosList(server.url)
386 expect(res.body.total).to.equal(6)
387 const videos = res.body.data
388 expect(videos).to.be.an('array')
389 expect(videos).to.have.lengthOf(6)
391 const videosByName = keyBy<{ duration: number }>(videos, 'name')
392 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
393 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
394 expect(videosByName['video_short.webm name'].duration).to.equal(5)
395 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
396 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
397 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
400 it('Should have the correct thumbnails', async function () {
401 const res = await getVideosList(server.url)
403 const videos = res.body.data
405 videosListBase = videos
407 for (const video of videos) {
408 const videoName = video.name.replace(' name', '')
409 const test = await testVideoImage(server.url, videoName, video.thumbnailPath)
411 expect(test).to.equal(true)
415 it('Should list only the two first videos', async function () {
416 const res = await getVideosListPagination(server.url, 0, 2, 'name')
418 const videos = res.body.data
419 expect(res.body.total).to.equal(6)
420 expect(videos.length).to.equal(2)
421 expect(videos[0].name).to.equal(videosListBase[0].name)
422 expect(videos[1].name).to.equal(videosListBase[1].name)
425 it('Should list only the next three videos', async function () {
426 const res = await getVideosListPagination(server.url, 2, 3, 'name')
428 const videos = res.body.data
429 expect(res.body.total).to.equal(6)
430 expect(videos.length).to.equal(3)
431 expect(videos[0].name).to.equal(videosListBase[2].name)
432 expect(videos[1].name).to.equal(videosListBase[3].name)
433 expect(videos[2].name).to.equal(videosListBase[4].name)
436 it('Should list the last video', async function () {
437 const res = await getVideosListPagination(server.url, 5, 6, 'name')
439 const videos = res.body.data
440 expect(res.body.total).to.equal(6)
441 expect(videos.length).to.equal(1)
442 expect(videos[0].name).to.equal(videosListBase[5].name)
445 it('Should search the first video', async function () {
446 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name')
448 const videos = res.body.data
449 expect(res.body.total).to.equal(4)
450 expect(videos.length).to.equal(1)
451 expect(videos[0].name).to.equal('video_short1.webm name')
454 it('Should search the last two videos', async function () {
455 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name')
457 const videos = res.body.data
458 expect(res.body.total).to.equal(4)
459 expect(videos.length).to.equal(2)
460 expect(videos[0].name).to.equal('video_short3.webm name')
461 expect(videos[1].name).to.equal('video_short.webm name')
464 it('Should search all the webm videos', async function () {
465 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 15)
467 const videos = res.body.data
468 expect(res.body.total).to.equal(4)
469 expect(videos.length).to.equal(4)
472 it('Should search all the root author videos', async function () {
473 const res = await searchVideoWithPagination(server.url, 'root', 'account', 0, 15)
475 const videos = res.body.data
476 expect(res.body.total).to.equal(6)
477 expect(videos.length).to.equal(6)
480 // Not implemented yet
481 // it('Should search all the 9001 port videos', async function () {
482 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
484 // const videos = res.body.data
485 // expect(res.body.total).to.equal(6)
486 // expect(videos.length).to.equal(6)
492 // it('Should search all the localhost videos', async function () {
493 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
495 // const videos = res.body.data
496 // expect(res.body.total).to.equal(6)
497 // expect(videos.length).to.equal(6)
503 it('Should list and sort by name in descending order', async function () {
504 const res = await getVideosListSort(server.url, '-name')
506 const videos = res.body.data
507 expect(res.body.total).to.equal(6)
508 expect(videos.length).to.equal(6)
509 expect(videos[0].name).to.equal('video_short.webm name')
510 expect(videos[1].name).to.equal('video_short.ogv name')
511 expect(videos[2].name).to.equal('video_short.mp4 name')
512 expect(videos[3].name).to.equal('video_short3.webm name')
513 expect(videos[4].name).to.equal('video_short2.webm name')
514 expect(videos[5].name).to.equal('video_short1.webm name')
517 it('Should search and sort by name in ascending order', async function () {
518 const res = await searchVideoWithSort(server.url, 'webm', 'name')
520 const videos = res.body.data
521 expect(res.body.total).to.equal(4)
522 expect(videos.length).to.equal(4)
524 expect(videos[0].name).to.equal('video_short1.webm name')
525 expect(videos[1].name).to.equal('video_short2.webm name')
526 expect(videos[2].name).to.equal('video_short3.webm name')
527 expect(videos[3].name).to.equal('video_short.webm name')
529 videoId = videos[2].id
532 it('Should update a video', async function () {
534 name: 'my super video updated',
539 description: 'my super description updated',
540 tags: [ 'tagup1', 'tagup2' ]
542 await updateVideo(server.url, server.accessToken, videoId, attributes)
545 it('Should have the video updated', async function () {
548 const res = await getVideo(server.url, videoId)
550 const video = res.body
552 expect(video.name).to.equal('my super video updated')
553 expect(video.category).to.equal(4)
554 expect(video.categoryLabel).to.equal('Art')
555 expect(video.licence).to.equal(2)
556 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
557 expect(video.language).to.equal(5)
558 expect(video.languageLabel).to.equal('Arabic')
559 expect(video.nsfw).to.be.ok
560 expect(video.description).to.equal('my super description updated')
561 expect(video.serverHost).to.equal('localhost:9001')
562 expect(video.account).to.equal('root')
563 expect(video.isLocal).to.be.true
564 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
565 expect(dateIsValid(video.createdAt)).to.be.true
566 expect(dateIsValid(video.updatedAt)).to.be.true
568 expect(video.channel.name).to.equal('Default root channel')
569 expect(video.channel.isLocal).to.be.true
570 expect(dateIsValid(video.channel.createdAt)).to.be.true
571 expect(dateIsValid(video.channel.updatedAt)).to.be.true
573 expect(video.files).to.have.lengthOf(1)
575 const file = video.files[0]
576 const magnetUri = file.magnetUri
577 expect(file.magnetUri).to.have.lengthOf.above(2)
578 expect(file.resolution).to.equal(720)
579 expect(file.resolutionLabel).to.equal('720p')
580 expect(file.size).to.equal(292677)
582 const test = await testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath)
583 expect(test).to.equal(true)
585 const torrent = await webtorrentAdd(magnetUri)
586 expect(torrent.files).to.be.an('array')
587 expect(torrent.files.length).to.equal(1)
588 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
591 it('Should update only the tags of a video', async function () {
593 tags: [ 'tag1', 'tag2', 'supertag' ]
596 await updateVideo(server.url, server.accessToken, videoId, attributes)
598 const res = await getVideo(server.url, videoId)
599 const video = res.body
601 expect(video.name).to.equal('my super video updated')
602 expect(video.category).to.equal(4)
603 expect(video.categoryLabel).to.equal('Art')
604 expect(video.licence).to.equal(2)
605 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
606 expect(video.language).to.equal(5)
607 expect(video.languageLabel).to.equal('Arabic')
608 expect(video.nsfw).to.be.ok
609 expect(video.description).to.equal('my super description updated')
610 expect(video.serverHost).to.equal('localhost:9001')
611 expect(video.account).to.equal('root')
612 expect(video.isLocal).to.be.true
613 expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ])
614 expect(dateIsValid(video.createdAt)).to.be.true
615 expect(dateIsValid(video.updatedAt)).to.be.true
617 expect(video.channel.name).to.equal('Default root channel')
618 expect(video.channel.isLocal).to.be.true
619 expect(dateIsValid(video.channel.createdAt)).to.be.true
620 expect(dateIsValid(video.channel.updatedAt)).to.be.true
622 expect(video.files).to.have.lengthOf(1)
624 const file = video.files[0]
625 expect(file.magnetUri).to.have.lengthOf.above(2)
626 expect(file.resolution).to.equal(720)
627 expect(file.resolutionLabel).to.equal('720p')
628 expect(file.size).to.equal(292677)
631 it('Should update only the description of a video', async function () {
633 description: 'hello everybody'
636 await updateVideo(server.url, server.accessToken, videoId, attributes)
638 const res = await getVideo(server.url, videoId)
639 const video = res.body
641 expect(video.name).to.equal('my super video updated')
642 expect(video.category).to.equal(4)
643 expect(video.categoryLabel).to.equal('Art')
644 expect(video.licence).to.equal(2)
645 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
646 expect(video.language).to.equal(5)
647 expect(video.languageLabel).to.equal('Arabic')
648 expect(video.nsfw).to.be.ok
649 expect(video.description).to.equal('hello everybody')
650 expect(video.serverHost).to.equal('localhost:9001')
651 expect(video.account).to.equal('root')
652 expect(video.isLocal).to.be.true
653 expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ])
654 expect(dateIsValid(video.createdAt)).to.be.true
655 expect(dateIsValid(video.updatedAt)).to.be.true
657 expect(video.channel.name).to.equal('Default root channel')
658 expect(video.channel.isLocal).to.be.true
659 expect(dateIsValid(video.channel.createdAt)).to.be.true
660 expect(dateIsValid(video.channel.updatedAt)).to.be.true
662 expect(video.files).to.have.lengthOf(1)
664 const file = video.files[0]
665 expect(file.magnetUri).to.have.lengthOf.above(2)
666 expect(file.resolution).to.equal(720)
667 expect(file.resolutionLabel).to.equal('720p')
668 expect(file.size).to.equal(292677)
671 it('Should like a video', async function () {
672 await rateVideo(server.url, server.accessToken, videoId, 'like')
674 const res = await getVideo(server.url, videoId)
675 const video = res.body
677 expect(video.likes).to.equal(1)
678 expect(video.dislikes).to.equal(0)
681 it('Should dislike the same video', async function () {
682 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
684 const res = await getVideo(server.url, videoId)
685 const video = res.body
687 expect(video.likes).to.equal(0)
688 expect(video.dislikes).to.equal(1)
691 after(async function () {
692 killallServers([ server ])
694 // Keep the logs if the test failed