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,
29 getVideosListPagination,
30 searchVideoWithPagination,
36 describe('Test a single pod', function () {
37 let server: ServerInfo = null
40 let videosListBase: any[] = null
42 before(async function () {
47 server = await runServer(1)
49 await setAccessTokensToServers([ server ])
52 it('Should list video categories', async function () {
53 const res = await getVideoCategories(server.url)
55 const categories = res.body
56 expect(Object.keys(categories)).to.have.length.above(10)
58 expect(categories[11]).to.equal('News')
61 it('Should list video licences', async function () {
62 const res = await getVideoLicences(server.url)
64 const licences = res.body
65 expect(Object.keys(licences)).to.have.length.above(5)
67 expect(licences[3]).to.equal('Attribution - No Derivatives')
70 it('Should list video languages', async function () {
71 const res = await getVideoLanguages(server.url)
73 const languages = res.body
74 expect(Object.keys(languages)).to.have.length.above(5)
76 expect(languages[3]).to.equal('Mandarin')
79 it('Should not have videos', async function () {
80 const res = await getVideosList(server.url)
82 expect(res.body.total).to.equal(0)
83 expect(res.body.data).to.be.an('array')
84 expect(res.body.data.length).to.equal(0)
87 it('Should upload the video', async function () {
88 const videoAttributes = {
89 name: 'my super name',
93 tags: [ 'tag1', 'tag2', 'tag3' ]
95 await uploadVideo(server.url, server.accessToken, videoAttributes)
98 it('Should seed the uploaded video', async function () {
99 // Yes, this could be long
102 const res = await getVideosList(server.url)
104 expect(res.body.total).to.equal(1)
105 expect(res.body.data).to.be.an('array')
106 expect(res.body.data.length).to.equal(1)
108 const video = res.body.data[0]
109 expect(video.name).to.equal('my super name')
110 expect(video.category).to.equal(2)
111 expect(video.categoryLabel).to.equal('Films')
112 expect(video.licence).to.equal(6)
113 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
114 expect(video.language).to.equal(3)
115 expect(video.languageLabel).to.equal('Mandarin')
116 expect(video.nsfw).to.be.ok
117 expect(video.description).to.equal('my super description')
118 expect(video.podHost).to.equal('localhost:9001')
119 expect(video.author).to.equal('root')
120 expect(video.isLocal).to.be.true
121 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
122 expect(dateIsValid(video.createdAt)).to.be.true
123 expect(dateIsValid(video.updatedAt)).to.be.true
125 const res2 = await getVideo(server.url, res.body.data[0].id)
126 const videoDetails = res2.body
128 expect(videoDetails.files).to.have.lengthOf(1)
130 const file = videoDetails.files[0]
131 const magnetUri = file.magnetUri
132 expect(file.magnetUri).to.have.lengthOf.above(2)
133 expect(file.torrentUrl).to.equal(`${server.url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
134 expect(file.fileUrl).to.equal(`${server.url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
135 expect(file.resolution).to.equal(720)
136 expect(file.resolutionLabel).to.equal('720p')
137 expect(file.size).to.equal(218910)
139 const test = await testVideoImage(server.url, 'video_short.webm', videoDetails.thumbnailPath)
140 expect(test).to.equal(true)
142 videoId = videoDetails.id
143 videoUUID = videoDetails.uuid
145 const torrent = await webtorrentAdd(magnetUri)
146 expect(torrent.files).to.be.an('array')
147 expect(torrent.files.length).to.equal(1)
148 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
151 it('Should get the video', async function () {
152 // Yes, this could be long
155 const res = await getVideo(server.url, videoId)
157 const video = res.body
158 expect(video.name).to.equal('my super name')
159 expect(video.category).to.equal(2)
160 expect(video.categoryLabel).to.equal('Films')
161 expect(video.licence).to.equal(6)
162 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
163 expect(video.language).to.equal(3)
164 expect(video.languageLabel).to.equal('Mandarin')
165 expect(video.nsfw).to.be.ok
166 expect(video.description).to.equal('my super description')
167 expect(video.podHost).to.equal('localhost:9001')
168 expect(video.author).to.equal('root')
169 expect(video.isLocal).to.be.true
170 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
171 expect(dateIsValid(video.createdAt)).to.be.true
172 expect(dateIsValid(video.updatedAt)).to.be.true
173 expect(video.channel.name).to.equal('Default root channel')
174 expect(video.channel.isLocal).to.be.true
175 expect(dateIsValid(video.channel.createdAt)).to.be.true
176 expect(dateIsValid(video.channel.updatedAt)).to.be.true
178 expect(video.files).to.have.lengthOf(1)
180 const file = video.files[0]
181 expect(file.magnetUri).to.have.lengthOf.above(2)
182 expect(file.resolution).to.equal(720)
183 expect(file.resolutionLabel).to.equal('720p')
184 expect(file.size).to.equal(218910)
186 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
187 expect(test).to.equal(true)
189 // Wait the async views increment
193 it('Should get the video by UUID', async function () {
194 // Yes, this could be long
197 const res = await getVideo(server.url, videoUUID)
199 const video = res.body
200 expect(video.name).to.equal('my super name')
202 // Wait the async views increment
206 it('Should have the views updated', async function () {
207 const res = await getVideo(server.url, videoId)
209 const video = res.body
210 expect(video.views).to.equal(3)
213 it('Should search the video by name by default', async function () {
214 const res = await searchVideo(server.url, 'my')
216 expect(res.body.total).to.equal(1)
217 expect(res.body.data).to.be.an('array')
218 expect(res.body.data.length).to.equal(1)
220 const video = res.body.data[0]
221 expect(video.name).to.equal('my super name')
222 expect(video.category).to.equal(2)
223 expect(video.categoryLabel).to.equal('Films')
224 expect(video.licence).to.equal(6)
225 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
226 expect(video.language).to.equal(3)
227 expect(video.languageLabel).to.equal('Mandarin')
228 expect(video.nsfw).to.be.ok
229 expect(video.description).to.equal('my super description')
230 expect(video.podHost).to.equal('localhost:9001')
231 expect(video.author).to.equal('root')
232 expect(video.isLocal).to.be.true
233 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
234 expect(dateIsValid(video.createdAt)).to.be.true
235 expect(dateIsValid(video.updatedAt)).to.be.true
237 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
238 expect(test).to.equal(true)
241 // Not implemented yet
242 // it('Should search the video by podHost', async function () {
243 // const res = await videosUtils.searchVideo(server.url, '9001', 'host')
245 // expect(res.body.total).to.equal(1)
246 // expect(res.body.data).to.be.an('array')
247 // expect(res.body.data.length).to.equal(1)
249 // const video = res.body.data[0]
250 // expect(video.name).to.equal('my super name')
251 // expect(video.description).to.equal('my super description')
252 // expect(video.podHost).to.equal('localhost:9001')
253 // expect(video.author).to.equal('root')
254 // expect(video.isLocal).to.be.true
255 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
256 // expect(dateIsValid(video.createdAt)).to.be.true
257 // expect(dateIsValid(video.updatedAt)).to.be.true
259 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
260 // expect(test).to.equal(true)
267 it('Should search the video by tag', async function () {
268 const res = await searchVideo(server.url, 'tag1', 'tags')
270 expect(res.body.total).to.equal(1)
271 expect(res.body.data).to.be.an('array')
272 expect(res.body.data.length).to.equal(1)
274 const video = res.body.data[0]
275 expect(video.name).to.equal('my super name')
276 expect(video.category).to.equal(2)
277 expect(video.categoryLabel).to.equal('Films')
278 expect(video.licence).to.equal(6)
279 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
280 expect(video.language).to.equal(3)
281 expect(video.languageLabel).to.equal('Mandarin')
282 expect(video.nsfw).to.be.ok
283 expect(video.description).to.equal('my super description')
284 expect(video.podHost).to.equal('localhost:9001')
285 expect(video.author).to.equal('root')
286 expect(video.isLocal).to.be.true
287 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
288 expect(dateIsValid(video.createdAt)).to.be.true
289 expect(dateIsValid(video.updatedAt)).to.be.true
291 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
292 expect(test).to.equal(true)
295 it('Should not find a search by name by default', async function () {
296 const res = await searchVideo(server.url, 'hello')
298 expect(res.body.total).to.equal(0)
299 expect(res.body.data).to.be.an('array')
300 expect(res.body.data.length).to.equal(0)
303 it('Should not find a search by author', async function () {
304 const res = await searchVideo(server.url, 'hello', 'author')
306 expect(res.body.total).to.equal(0)
307 expect(res.body.data).to.be.an('array')
308 expect(res.body.data.length).to.equal(0)
311 it('Should not find a search by tag', async function () {
312 const res = await searchVideo(server.url, 'hello', 'tags')
314 expect(res.body.total).to.equal(0)
315 expect(res.body.data).to.be.an('array')
316 expect(res.body.data.length).to.equal(0)
319 it('Should remove the video', async function () {
320 await removeVideo(server.url, server.accessToken, videoId)
322 const files1 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/videos/'))
323 expect(files1).to.have.lengthOf(0)
325 const files2 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/thumbnails/'))
326 expect(files2).to.have.lengthOf(0)
329 it('Should not have videos', async function () {
330 const res = await getVideosList(server.url)
332 expect(res.body.total).to.equal(0)
333 expect(res.body.data).to.be.an('array')
334 expect(res.body.data).to.have.lengthOf(0)
337 it('Should upload 6 videos', async function () {
341 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
342 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
345 const tasks: Promise<any>[] = []
346 for (const video of videos) {
347 const videoAttributes = {
348 name: video + ' name',
349 description: video + ' description',
354 tags: [ 'tag1', 'tag2', 'tag3' ],
358 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
362 await Promise.all(tasks)
365 it('Should have the correct durations', async function () {
366 const res = await getVideosList(server.url)
368 expect(res.body.total).to.equal(6)
369 const videos = res.body.data
370 expect(videos).to.be.an('array')
371 expect(videos).to.have.lengthOf(6)
373 const videosByName = keyBy<{ duration: number }>(videos, 'name')
374 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
375 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
376 expect(videosByName['video_short.webm name'].duration).to.equal(5)
377 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
378 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
379 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
382 it('Should have the correct thumbnails', async function () {
383 const res = await getVideosList(server.url)
385 const videos = res.body.data
387 videosListBase = videos
389 for (const video of videos) {
390 const videoName = video.name.replace(' name', '')
391 const test = await testVideoImage(server.url, videoName, video.thumbnailPath)
393 expect(test).to.equal(true)
397 it('Should list only the two first videos', async function () {
398 const res = await getVideosListPagination(server.url, 0, 2, 'name')
400 const videos = res.body.data
401 expect(res.body.total).to.equal(6)
402 expect(videos.length).to.equal(2)
403 expect(videos[0].name).to.equal(videosListBase[0].name)
404 expect(videos[1].name).to.equal(videosListBase[1].name)
407 it('Should list only the next three videos', async function () {
408 const res = await getVideosListPagination(server.url, 2, 3, 'name')
410 const videos = res.body.data
411 expect(res.body.total).to.equal(6)
412 expect(videos.length).to.equal(3)
413 expect(videos[0].name).to.equal(videosListBase[2].name)
414 expect(videos[1].name).to.equal(videosListBase[3].name)
415 expect(videos[2].name).to.equal(videosListBase[4].name)
418 it('Should list the last video', async function () {
419 const res = await getVideosListPagination(server.url, 5, 6, 'name')
421 const videos = res.body.data
422 expect(res.body.total).to.equal(6)
423 expect(videos.length).to.equal(1)
424 expect(videos[0].name).to.equal(videosListBase[5].name)
427 it('Should search the first video', async function () {
428 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name')
430 const videos = res.body.data
431 expect(res.body.total).to.equal(4)
432 expect(videos.length).to.equal(1)
433 expect(videos[0].name).to.equal('video_short1.webm name')
436 it('Should search the last two videos', async function () {
437 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name')
439 const videos = res.body.data
440 expect(res.body.total).to.equal(4)
441 expect(videos.length).to.equal(2)
442 expect(videos[0].name).to.equal('video_short3.webm name')
443 expect(videos[1].name).to.equal('video_short.webm name')
446 it('Should search all the webm videos', async function () {
447 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 15)
449 const videos = res.body.data
450 expect(res.body.total).to.equal(4)
451 expect(videos.length).to.equal(4)
454 it('Should search all the root author videos', async function () {
455 const res = await searchVideoWithPagination(server.url, 'root', 'author', 0, 15)
457 const videos = res.body.data
458 expect(res.body.total).to.equal(6)
459 expect(videos.length).to.equal(6)
462 // Not implemented yet
463 // it('Should search all the 9001 port videos', async function () {
464 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
466 // const videos = res.body.data
467 // expect(res.body.total).to.equal(6)
468 // expect(videos.length).to.equal(6)
474 // it('Should search all the localhost videos', async function () {
475 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
477 // const videos = res.body.data
478 // expect(res.body.total).to.equal(6)
479 // expect(videos.length).to.equal(6)
485 it('Should search the right magnetUri video', async function () {
486 const video = videosListBase[0]
487 const res = await getVideo(server.url, video.id)
488 const videoDetails = res.body
490 const res2 = await searchVideoWithPagination(server.url, encodeURIComponent(videoDetails.files[0].magnetUri), 'magnetUri', 0, 15)
492 const videos = res2.body.data
493 expect(res2.body.total).to.equal(1)
494 expect(videos.length).to.equal(1)
495 expect(videos[0].name).to.equal(video.name)
498 it('Should list and sort by name in descending order', async function () {
499 const res = await getVideosListSort(server.url, '-name')
501 const videos = res.body.data
502 expect(res.body.total).to.equal(6)
503 expect(videos.length).to.equal(6)
504 expect(videos[0].name).to.equal('video_short.webm name')
505 expect(videos[1].name).to.equal('video_short.ogv name')
506 expect(videos[2].name).to.equal('video_short.mp4 name')
507 expect(videos[3].name).to.equal('video_short3.webm name')
508 expect(videos[4].name).to.equal('video_short2.webm name')
509 expect(videos[5].name).to.equal('video_short1.webm name')
512 it('Should search and sort by name in ascending order', async function () {
513 const res = await searchVideoWithSort(server.url, 'webm', 'name')
515 const videos = res.body.data
516 expect(res.body.total).to.equal(4)
517 expect(videos.length).to.equal(4)
519 expect(videos[0].name).to.equal('video_short1.webm name')
520 expect(videos[1].name).to.equal('video_short2.webm name')
521 expect(videos[2].name).to.equal('video_short3.webm name')
522 expect(videos[3].name).to.equal('video_short.webm name')
524 videoId = videos[2].id
527 it('Should update a video', async function () {
529 name: 'my super video updated',
534 description: 'my super description updated',
535 tags: [ 'tagup1', 'tagup2' ]
537 await updateVideo(server.url, server.accessToken, videoId, attributes)
540 it('Should have the video updated', async function () {
543 const res = await getVideo(server.url, videoId)
545 const video = res.body
547 expect(video.name).to.equal('my super video updated')
548 expect(video.category).to.equal(4)
549 expect(video.categoryLabel).to.equal('Art')
550 expect(video.licence).to.equal(2)
551 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
552 expect(video.language).to.equal(5)
553 expect(video.languageLabel).to.equal('Arabic')
554 expect(video.nsfw).to.be.ok
555 expect(video.description).to.equal('my super description updated')
556 expect(video.podHost).to.equal('localhost:9001')
557 expect(video.author).to.equal('root')
558 expect(video.isLocal).to.be.true
559 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
560 expect(dateIsValid(video.createdAt)).to.be.true
561 expect(dateIsValid(video.updatedAt)).to.be.true
563 expect(video.channel.name).to.equal('Default root channel')
564 expect(video.channel.isLocal).to.be.true
565 expect(dateIsValid(video.channel.createdAt)).to.be.true
566 expect(dateIsValid(video.channel.updatedAt)).to.be.true
568 expect(video.files).to.have.lengthOf(1)
570 const file = video.files[0]
571 const magnetUri = file.magnetUri
572 expect(file.magnetUri).to.have.lengthOf.above(2)
573 expect(file.resolution).to.equal(720)
574 expect(file.resolutionLabel).to.equal('720p')
575 expect(file.size).to.equal(292677)
577 const test = await testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath)
578 expect(test).to.equal(true)
580 const torrent = await webtorrentAdd(magnetUri)
581 expect(torrent.files).to.be.an('array')
582 expect(torrent.files.length).to.equal(1)
583 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
586 it('Should update only the tags of a video', async function () {
588 tags: [ 'tag1', 'tag2', 'supertag' ]
591 await updateVideo(server.url, server.accessToken, videoId, attributes)
593 const res = await getVideo(server.url, videoId)
594 const video = res.body
596 expect(video.name).to.equal('my super video updated')
597 expect(video.category).to.equal(4)
598 expect(video.categoryLabel).to.equal('Art')
599 expect(video.licence).to.equal(2)
600 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
601 expect(video.language).to.equal(5)
602 expect(video.languageLabel).to.equal('Arabic')
603 expect(video.nsfw).to.be.ok
604 expect(video.description).to.equal('my super description updated')
605 expect(video.podHost).to.equal('localhost:9001')
606 expect(video.author).to.equal('root')
607 expect(video.isLocal).to.be.true
608 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
609 expect(dateIsValid(video.createdAt)).to.be.true
610 expect(dateIsValid(video.updatedAt)).to.be.true
612 expect(video.channel.name).to.equal('Default root channel')
613 expect(video.channel.isLocal).to.be.true
614 expect(dateIsValid(video.channel.createdAt)).to.be.true
615 expect(dateIsValid(video.channel.updatedAt)).to.be.true
617 expect(video.files).to.have.lengthOf(1)
619 const file = video.files[0]
620 expect(file.magnetUri).to.have.lengthOf.above(2)
621 expect(file.resolution).to.equal(720)
622 expect(file.resolutionLabel).to.equal('720p')
623 expect(file.size).to.equal(292677)
626 it('Should update only the description of a video', async function () {
628 description: 'hello everybody'
631 await updateVideo(server.url, server.accessToken, videoId, attributes)
633 const res = await getVideo(server.url, videoId)
634 const video = res.body
636 expect(video.name).to.equal('my super video updated')
637 expect(video.category).to.equal(4)
638 expect(video.categoryLabel).to.equal('Art')
639 expect(video.licence).to.equal(2)
640 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
641 expect(video.language).to.equal(5)
642 expect(video.languageLabel).to.equal('Arabic')
643 expect(video.nsfw).to.be.ok
644 expect(video.description).to.equal('hello everybody')
645 expect(video.podHost).to.equal('localhost:9001')
646 expect(video.author).to.equal('root')
647 expect(video.isLocal).to.be.true
648 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
649 expect(dateIsValid(video.createdAt)).to.be.true
650 expect(dateIsValid(video.updatedAt)).to.be.true
652 expect(video.channel.name).to.equal('Default root channel')
653 expect(video.channel.isLocal).to.be.true
654 expect(dateIsValid(video.channel.createdAt)).to.be.true
655 expect(dateIsValid(video.channel.updatedAt)).to.be.true
657 expect(video.files).to.have.lengthOf(1)
659 const file = video.files[0]
660 expect(file.magnetUri).to.have.lengthOf.above(2)
661 expect(file.resolution).to.equal(720)
662 expect(file.resolutionLabel).to.equal('720p')
663 expect(file.size).to.equal(292677)
666 it('Should like a video', async function () {
667 await rateVideo(server.url, server.accessToken, videoId, 'like')
669 const res = await getVideo(server.url, videoId)
670 const video = res.body
672 expect(video.likes).to.equal(1)
673 expect(video.dislikes).to.equal(0)
676 it('Should dislike the same video', async function () {
677 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
679 const res = await getVideo(server.url, videoId)
680 const video = res.body
682 expect(video.likes).to.equal(0)
683 expect(video.dislikes).to.equal(1)
686 after(async function () {
687 killallServers([ server ])
689 // Keep the logs if the test failed