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,
37 describe('Test a single pod', function () {
38 let server: ServerInfo = null
41 let videosListBase: any[] = null
43 before(async function () {
48 server = await runServer(1)
50 await setAccessTokensToServers([ server ])
53 it('Should list video categories', async function () {
54 const res = await getVideoCategories(server.url)
56 const categories = res.body
57 expect(Object.keys(categories)).to.have.length.above(10)
59 expect(categories[11]).to.equal('News')
62 it('Should list video licences', async function () {
63 const res = await getVideoLicences(server.url)
65 const licences = res.body
66 expect(Object.keys(licences)).to.have.length.above(5)
68 expect(licences[3]).to.equal('Attribution - No Derivatives')
71 it('Should list video languages', async function () {
72 const res = await getVideoLanguages(server.url)
74 const languages = res.body
75 expect(Object.keys(languages)).to.have.length.above(5)
77 expect(languages[3]).to.equal('Mandarin')
80 it('Should list video privacies', async function () {
81 const res = await getVideoPrivacies(server.url)
83 const privacies = res.body
84 expect(Object.keys(privacies)).to.have.length.at.least(3)
86 expect(privacies[3]).to.equal('Private')
89 it('Should not have videos', async function () {
90 const res = await getVideosList(server.url)
92 expect(res.body.total).to.equal(0)
93 expect(res.body.data).to.be.an('array')
94 expect(res.body.data.length).to.equal(0)
97 it('Should upload the video', async function () {
98 const videoAttributes = {
99 name: 'my super name',
103 tags: [ 'tag1', 'tag2', 'tag3' ]
105 await uploadVideo(server.url, server.accessToken, videoAttributes)
108 it('Should seed the uploaded video', async function () {
109 // Yes, this could be long
112 const res = await getVideosList(server.url)
114 expect(res.body.total).to.equal(1)
115 expect(res.body.data).to.be.an('array')
116 expect(res.body.data.length).to.equal(1)
118 const video = res.body.data[0]
119 expect(video.name).to.equal('my super name')
120 expect(video.category).to.equal(2)
121 expect(video.categoryLabel).to.equal('Films')
122 expect(video.licence).to.equal(6)
123 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
124 expect(video.language).to.equal(3)
125 expect(video.languageLabel).to.equal('Mandarin')
126 expect(video.nsfw).to.be.ok
127 expect(video.description).to.equal('my super description')
128 expect(video.podHost).to.equal('localhost:9001')
129 expect(video.author).to.equal('root')
130 expect(video.isLocal).to.be.true
131 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
132 expect(dateIsValid(video.createdAt)).to.be.true
133 expect(dateIsValid(video.updatedAt)).to.be.true
135 const res2 = await getVideo(server.url, res.body.data[0].id)
136 const videoDetails = res2.body
138 expect(videoDetails.files).to.have.lengthOf(1)
140 const file = videoDetails.files[0]
141 const magnetUri = file.magnetUri
142 expect(file.magnetUri).to.have.lengthOf.above(2)
143 expect(file.torrentUrl).to.equal(`${server.url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
144 expect(file.fileUrl).to.equal(`${server.url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
145 expect(file.resolution).to.equal(720)
146 expect(file.resolutionLabel).to.equal('720p')
147 expect(file.size).to.equal(218910)
149 const test = await testVideoImage(server.url, 'video_short.webm', videoDetails.thumbnailPath)
150 expect(test).to.equal(true)
152 videoId = videoDetails.id
153 videoUUID = videoDetails.uuid
155 const torrent = await webtorrentAdd(magnetUri)
156 expect(torrent.files).to.be.an('array')
157 expect(torrent.files.length).to.equal(1)
158 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
161 it('Should get the video', async function () {
162 // Yes, this could be long
165 const res = await getVideo(server.url, videoId)
167 const video = res.body
168 expect(video.name).to.equal('my super name')
169 expect(video.category).to.equal(2)
170 expect(video.categoryLabel).to.equal('Films')
171 expect(video.licence).to.equal(6)
172 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
173 expect(video.language).to.equal(3)
174 expect(video.languageLabel).to.equal('Mandarin')
175 expect(video.nsfw).to.be.ok
176 expect(video.description).to.equal('my super description')
177 expect(video.podHost).to.equal('localhost:9001')
178 expect(video.author).to.equal('root')
179 expect(video.isLocal).to.be.true
180 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
181 expect(dateIsValid(video.createdAt)).to.be.true
182 expect(dateIsValid(video.updatedAt)).to.be.true
183 expect(video.channel.name).to.equal('Default root channel')
184 expect(video.channel.isLocal).to.be.true
185 expect(dateIsValid(video.channel.createdAt)).to.be.true
186 expect(dateIsValid(video.channel.updatedAt)).to.be.true
188 expect(video.files).to.have.lengthOf(1)
190 const file = video.files[0]
191 expect(file.magnetUri).to.have.lengthOf.above(2)
192 expect(file.resolution).to.equal(720)
193 expect(file.resolutionLabel).to.equal('720p')
194 expect(file.size).to.equal(218910)
196 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
197 expect(test).to.equal(true)
199 // Wait the async views increment
203 it('Should get the video by UUID', async function () {
204 // Yes, this could be long
207 const res = await getVideo(server.url, videoUUID)
209 const video = res.body
210 expect(video.name).to.equal('my super name')
212 // Wait the async views increment
216 it('Should have the views updated', async function () {
217 const res = await getVideo(server.url, videoId)
219 const video = res.body
220 expect(video.views).to.equal(3)
223 it('Should search the video by name by default', async function () {
224 const res = await searchVideo(server.url, 'my')
226 expect(res.body.total).to.equal(1)
227 expect(res.body.data).to.be.an('array')
228 expect(res.body.data.length).to.equal(1)
230 const video = res.body.data[0]
231 expect(video.name).to.equal('my super name')
232 expect(video.category).to.equal(2)
233 expect(video.categoryLabel).to.equal('Films')
234 expect(video.licence).to.equal(6)
235 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
236 expect(video.language).to.equal(3)
237 expect(video.languageLabel).to.equal('Mandarin')
238 expect(video.nsfw).to.be.ok
239 expect(video.description).to.equal('my super description')
240 expect(video.podHost).to.equal('localhost:9001')
241 expect(video.author).to.equal('root')
242 expect(video.isLocal).to.be.true
243 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
244 expect(dateIsValid(video.createdAt)).to.be.true
245 expect(dateIsValid(video.updatedAt)).to.be.true
247 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
248 expect(test).to.equal(true)
251 // Not implemented yet
252 // it('Should search the video by podHost', async function () {
253 // const res = await videosUtils.searchVideo(server.url, '9001', 'host')
255 // expect(res.body.total).to.equal(1)
256 // expect(res.body.data).to.be.an('array')
257 // expect(res.body.data.length).to.equal(1)
259 // const video = res.body.data[0]
260 // expect(video.name).to.equal('my super name')
261 // expect(video.description).to.equal('my super description')
262 // expect(video.podHost).to.equal('localhost:9001')
263 // expect(video.author).to.equal('root')
264 // expect(video.isLocal).to.be.true
265 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
266 // expect(dateIsValid(video.createdAt)).to.be.true
267 // expect(dateIsValid(video.updatedAt)).to.be.true
269 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
270 // expect(test).to.equal(true)
277 it('Should search the video by tag', async function () {
278 const res = await searchVideo(server.url, 'tag1', 'tags')
280 expect(res.body.total).to.equal(1)
281 expect(res.body.data).to.be.an('array')
282 expect(res.body.data.length).to.equal(1)
284 const video = res.body.data[0]
285 expect(video.name).to.equal('my super name')
286 expect(video.category).to.equal(2)
287 expect(video.categoryLabel).to.equal('Films')
288 expect(video.licence).to.equal(6)
289 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
290 expect(video.language).to.equal(3)
291 expect(video.languageLabel).to.equal('Mandarin')
292 expect(video.nsfw).to.be.ok
293 expect(video.description).to.equal('my super description')
294 expect(video.podHost).to.equal('localhost:9001')
295 expect(video.author).to.equal('root')
296 expect(video.isLocal).to.be.true
297 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
298 expect(dateIsValid(video.createdAt)).to.be.true
299 expect(dateIsValid(video.updatedAt)).to.be.true
301 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
302 expect(test).to.equal(true)
305 it('Should not find a search by name by default', async function () {
306 const res = await searchVideo(server.url, 'hello')
308 expect(res.body.total).to.equal(0)
309 expect(res.body.data).to.be.an('array')
310 expect(res.body.data.length).to.equal(0)
313 it('Should not find a search by author', async function () {
314 const res = await searchVideo(server.url, 'hello', 'author')
316 expect(res.body.total).to.equal(0)
317 expect(res.body.data).to.be.an('array')
318 expect(res.body.data.length).to.equal(0)
321 it('Should not find a search by tag', async function () {
322 const res = await searchVideo(server.url, 'hello', 'tags')
324 expect(res.body.total).to.equal(0)
325 expect(res.body.data).to.be.an('array')
326 expect(res.body.data.length).to.equal(0)
329 it('Should remove the video', async function () {
330 await removeVideo(server.url, server.accessToken, videoId)
332 const files1 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/videos/'))
333 expect(files1).to.have.lengthOf(0)
335 const files2 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/thumbnails/'))
336 expect(files2).to.have.lengthOf(0)
339 it('Should not have videos', async function () {
340 const res = await getVideosList(server.url)
342 expect(res.body.total).to.equal(0)
343 expect(res.body.data).to.be.an('array')
344 expect(res.body.data).to.have.lengthOf(0)
347 it('Should upload 6 videos', async function () {
351 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
352 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
355 const tasks: Promise<any>[] = []
356 for (const video of videos) {
357 const videoAttributes = {
358 name: video + ' name',
359 description: video + ' description',
364 tags: [ 'tag1', 'tag2', 'tag3' ],
368 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
372 await Promise.all(tasks)
375 it('Should have the correct durations', async function () {
376 const res = await getVideosList(server.url)
378 expect(res.body.total).to.equal(6)
379 const videos = res.body.data
380 expect(videos).to.be.an('array')
381 expect(videos).to.have.lengthOf(6)
383 const videosByName = keyBy<{ duration: number }>(videos, 'name')
384 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
385 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
386 expect(videosByName['video_short.webm name'].duration).to.equal(5)
387 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
388 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
389 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
392 it('Should have the correct thumbnails', async function () {
393 const res = await getVideosList(server.url)
395 const videos = res.body.data
397 videosListBase = videos
399 for (const video of videos) {
400 const videoName = video.name.replace(' name', '')
401 const test = await testVideoImage(server.url, videoName, video.thumbnailPath)
403 expect(test).to.equal(true)
407 it('Should list only the two first videos', async function () {
408 const res = await getVideosListPagination(server.url, 0, 2, 'name')
410 const videos = res.body.data
411 expect(res.body.total).to.equal(6)
412 expect(videos.length).to.equal(2)
413 expect(videos[0].name).to.equal(videosListBase[0].name)
414 expect(videos[1].name).to.equal(videosListBase[1].name)
417 it('Should list only the next three videos', async function () {
418 const res = await getVideosListPagination(server.url, 2, 3, 'name')
420 const videos = res.body.data
421 expect(res.body.total).to.equal(6)
422 expect(videos.length).to.equal(3)
423 expect(videos[0].name).to.equal(videosListBase[2].name)
424 expect(videos[1].name).to.equal(videosListBase[3].name)
425 expect(videos[2].name).to.equal(videosListBase[4].name)
428 it('Should list the last video', async function () {
429 const res = await getVideosListPagination(server.url, 5, 6, 'name')
431 const videos = res.body.data
432 expect(res.body.total).to.equal(6)
433 expect(videos.length).to.equal(1)
434 expect(videos[0].name).to.equal(videosListBase[5].name)
437 it('Should search the first video', async function () {
438 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name')
440 const videos = res.body.data
441 expect(res.body.total).to.equal(4)
442 expect(videos.length).to.equal(1)
443 expect(videos[0].name).to.equal('video_short1.webm name')
446 it('Should search the last two videos', async function () {
447 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name')
449 const videos = res.body.data
450 expect(res.body.total).to.equal(4)
451 expect(videos.length).to.equal(2)
452 expect(videos[0].name).to.equal('video_short3.webm name')
453 expect(videos[1].name).to.equal('video_short.webm name')
456 it('Should search all the webm videos', async function () {
457 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 15)
459 const videos = res.body.data
460 expect(res.body.total).to.equal(4)
461 expect(videos.length).to.equal(4)
464 it('Should search all the root author videos', async function () {
465 const res = await searchVideoWithPagination(server.url, 'root', 'author', 0, 15)
467 const videos = res.body.data
468 expect(res.body.total).to.equal(6)
469 expect(videos.length).to.equal(6)
472 // Not implemented yet
473 // it('Should search all the 9001 port videos', async function () {
474 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
476 // const videos = res.body.data
477 // expect(res.body.total).to.equal(6)
478 // expect(videos.length).to.equal(6)
484 // it('Should search all the localhost videos', async function () {
485 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
487 // const videos = res.body.data
488 // expect(res.body.total).to.equal(6)
489 // expect(videos.length).to.equal(6)
495 it('Should list and sort by name in descending order', async function () {
496 const res = await getVideosListSort(server.url, '-name')
498 const videos = res.body.data
499 expect(res.body.total).to.equal(6)
500 expect(videos.length).to.equal(6)
501 expect(videos[0].name).to.equal('video_short.webm name')
502 expect(videos[1].name).to.equal('video_short.ogv name')
503 expect(videos[2].name).to.equal('video_short.mp4 name')
504 expect(videos[3].name).to.equal('video_short3.webm name')
505 expect(videos[4].name).to.equal('video_short2.webm name')
506 expect(videos[5].name).to.equal('video_short1.webm name')
509 it('Should search and sort by name in ascending order', async function () {
510 const res = await searchVideoWithSort(server.url, 'webm', 'name')
512 const videos = res.body.data
513 expect(res.body.total).to.equal(4)
514 expect(videos.length).to.equal(4)
516 expect(videos[0].name).to.equal('video_short1.webm name')
517 expect(videos[1].name).to.equal('video_short2.webm name')
518 expect(videos[2].name).to.equal('video_short3.webm name')
519 expect(videos[3].name).to.equal('video_short.webm name')
521 videoId = videos[2].id
524 it('Should update a video', async function () {
526 name: 'my super video updated',
531 description: 'my super description updated',
532 tags: [ 'tagup1', 'tagup2' ]
534 await updateVideo(server.url, server.accessToken, videoId, attributes)
537 it('Should have the video updated', async function () {
540 const res = await getVideo(server.url, videoId)
542 const video = res.body
544 expect(video.name).to.equal('my super video updated')
545 expect(video.category).to.equal(4)
546 expect(video.categoryLabel).to.equal('Art')
547 expect(video.licence).to.equal(2)
548 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
549 expect(video.language).to.equal(5)
550 expect(video.languageLabel).to.equal('Arabic')
551 expect(video.nsfw).to.be.ok
552 expect(video.description).to.equal('my super description updated')
553 expect(video.podHost).to.equal('localhost:9001')
554 expect(video.author).to.equal('root')
555 expect(video.isLocal).to.be.true
556 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
557 expect(dateIsValid(video.createdAt)).to.be.true
558 expect(dateIsValid(video.updatedAt)).to.be.true
560 expect(video.channel.name).to.equal('Default root channel')
561 expect(video.channel.isLocal).to.be.true
562 expect(dateIsValid(video.channel.createdAt)).to.be.true
563 expect(dateIsValid(video.channel.updatedAt)).to.be.true
565 expect(video.files).to.have.lengthOf(1)
567 const file = video.files[0]
568 const magnetUri = file.magnetUri
569 expect(file.magnetUri).to.have.lengthOf.above(2)
570 expect(file.resolution).to.equal(720)
571 expect(file.resolutionLabel).to.equal('720p')
572 expect(file.size).to.equal(292677)
574 const test = await testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath)
575 expect(test).to.equal(true)
577 const torrent = await webtorrentAdd(magnetUri)
578 expect(torrent.files).to.be.an('array')
579 expect(torrent.files.length).to.equal(1)
580 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
583 it('Should update only the tags of a video', async function () {
585 tags: [ 'tag1', 'tag2', 'supertag' ]
588 await updateVideo(server.url, server.accessToken, videoId, attributes)
590 const res = await getVideo(server.url, videoId)
591 const video = res.body
593 expect(video.name).to.equal('my super video updated')
594 expect(video.category).to.equal(4)
595 expect(video.categoryLabel).to.equal('Art')
596 expect(video.licence).to.equal(2)
597 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
598 expect(video.language).to.equal(5)
599 expect(video.languageLabel).to.equal('Arabic')
600 expect(video.nsfw).to.be.ok
601 expect(video.description).to.equal('my super description updated')
602 expect(video.podHost).to.equal('localhost:9001')
603 expect(video.author).to.equal('root')
604 expect(video.isLocal).to.be.true
605 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
606 expect(dateIsValid(video.createdAt)).to.be.true
607 expect(dateIsValid(video.updatedAt)).to.be.true
609 expect(video.channel.name).to.equal('Default root channel')
610 expect(video.channel.isLocal).to.be.true
611 expect(dateIsValid(video.channel.createdAt)).to.be.true
612 expect(dateIsValid(video.channel.updatedAt)).to.be.true
614 expect(video.files).to.have.lengthOf(1)
616 const file = video.files[0]
617 expect(file.magnetUri).to.have.lengthOf.above(2)
618 expect(file.resolution).to.equal(720)
619 expect(file.resolutionLabel).to.equal('720p')
620 expect(file.size).to.equal(292677)
623 it('Should update only the description of a video', async function () {
625 description: 'hello everybody'
628 await updateVideo(server.url, server.accessToken, videoId, attributes)
630 const res = await getVideo(server.url, videoId)
631 const video = res.body
633 expect(video.name).to.equal('my super video updated')
634 expect(video.category).to.equal(4)
635 expect(video.categoryLabel).to.equal('Art')
636 expect(video.licence).to.equal(2)
637 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
638 expect(video.language).to.equal(5)
639 expect(video.languageLabel).to.equal('Arabic')
640 expect(video.nsfw).to.be.ok
641 expect(video.description).to.equal('hello everybody')
642 expect(video.podHost).to.equal('localhost:9001')
643 expect(video.author).to.equal('root')
644 expect(video.isLocal).to.be.true
645 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
646 expect(dateIsValid(video.createdAt)).to.be.true
647 expect(dateIsValid(video.updatedAt)).to.be.true
649 expect(video.channel.name).to.equal('Default root channel')
650 expect(video.channel.isLocal).to.be.true
651 expect(dateIsValid(video.channel.createdAt)).to.be.true
652 expect(dateIsValid(video.channel.updatedAt)).to.be.true
654 expect(video.files).to.have.lengthOf(1)
656 const file = video.files[0]
657 expect(file.magnetUri).to.have.lengthOf.above(2)
658 expect(file.resolution).to.equal(720)
659 expect(file.resolutionLabel).to.equal('720p')
660 expect(file.size).to.equal(292677)
663 it('Should like a video', async function () {
664 await rateVideo(server.url, server.accessToken, videoId, 'like')
666 const res = await getVideo(server.url, videoId)
667 const video = res.body
669 expect(video.likes).to.equal(1)
670 expect(video.dislikes).to.equal(0)
673 it('Should dislike the same video', async function () {
674 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
676 const res = await getVideo(server.url, videoId)
677 const video = res.body
679 expect(video.likes).to.equal(0)
680 expect(video.dislikes).to.equal(1)
683 after(async function () {
684 killallServers([ server ])
686 // Keep the logs if the test failed