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 expect(video.files).to.have.lengthOf(1)
127 const file = video.files[0]
128 const magnetUri = file.magnetUri
129 expect(file.magnetUri).to.have.lengthOf.above(2)
130 expect(file.resolution).to.equal(720)
131 expect(file.resolutionLabel).to.equal('720p')
132 expect(file.size).to.equal(218910)
134 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
135 expect(test).to.equal(true)
138 videoUUID = video.uuid
140 const torrent = await webtorrentAdd(magnetUri)
141 expect(torrent.files).to.be.an('array')
142 expect(torrent.files.length).to.equal(1)
143 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
146 it('Should get the video', async function () {
147 // Yes, this could be long
150 const res = await getVideo(server.url, videoId)
152 const video = res.body
153 expect(video.name).to.equal('my super name')
154 expect(video.category).to.equal(2)
155 expect(video.categoryLabel).to.equal('Films')
156 expect(video.licence).to.equal(6)
157 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
158 expect(video.language).to.equal(3)
159 expect(video.languageLabel).to.equal('Mandarin')
160 expect(video.nsfw).to.be.ok
161 expect(video.description).to.equal('my super description')
162 expect(video.podHost).to.equal('localhost:9001')
163 expect(video.author).to.equal('root')
164 expect(video.isLocal).to.be.true
165 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
166 expect(dateIsValid(video.createdAt)).to.be.true
167 expect(dateIsValid(video.updatedAt)).to.be.true
169 expect(video.files).to.have.lengthOf(1)
171 const file = video.files[0]
172 expect(file.magnetUri).to.have.lengthOf.above(2)
173 expect(file.resolution).to.equal(720)
174 expect(file.resolutionLabel).to.equal('720p')
175 expect(file.size).to.equal(218910)
177 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
178 expect(test).to.equal(true)
180 // Wait the async views increment
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 expect(video.name).to.equal('my super name')
193 // Wait the async views increment
197 it('Should have the views updated', async function () {
198 const res = await getVideo(server.url, videoId)
200 const video = res.body
201 expect(video.views).to.equal(2)
204 it('Should search the video by name by default', async function () {
205 const res = await searchVideo(server.url, 'my')
207 expect(res.body.total).to.equal(1)
208 expect(res.body.data).to.be.an('array')
209 expect(res.body.data.length).to.equal(1)
211 const video = res.body.data[0]
212 expect(video.name).to.equal('my super name')
213 expect(video.category).to.equal(2)
214 expect(video.categoryLabel).to.equal('Films')
215 expect(video.licence).to.equal(6)
216 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
217 expect(video.language).to.equal(3)
218 expect(video.languageLabel).to.equal('Mandarin')
219 expect(video.nsfw).to.be.ok
220 expect(video.description).to.equal('my super description')
221 expect(video.podHost).to.equal('localhost:9001')
222 expect(video.author).to.equal('root')
223 expect(video.isLocal).to.be.true
224 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
225 expect(dateIsValid(video.createdAt)).to.be.true
226 expect(dateIsValid(video.updatedAt)).to.be.true
228 expect(video.files).to.have.lengthOf(1)
230 const file = video.files[0]
231 expect(file.magnetUri).to.have.lengthOf.above(2)
232 expect(file.resolution).to.equal(720)
233 expect(file.resolutionLabel).to.equal('720p')
234 expect(file.size).to.equal(218910)
236 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
237 expect(test).to.equal(true)
240 // Not implemented yet
241 // it('Should search the video by podHost', async function () {
242 // const res = await videosUtils.searchVideo(server.url, '9001', 'host')
244 // expect(res.body.total).to.equal(1)
245 // expect(res.body.data).to.be.an('array')
246 // expect(res.body.data.length).to.equal(1)
248 // const video = res.body.data[0]
249 // expect(video.name).to.equal('my super name')
250 // expect(video.description).to.equal('my super description')
251 // expect(video.podHost).to.equal('localhost:9001')
252 // expect(video.author).to.equal('root')
253 // expect(video.isLocal).to.be.true
254 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
255 // expect(dateIsValid(video.createdAt)).to.be.true
256 // expect(dateIsValid(video.updatedAt)).to.be.true
258 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
259 // expect(test).to.equal(true)
266 it('Should search the video by tag', async function () {
267 const res = await searchVideo(server.url, 'tag1', 'tags')
269 expect(res.body.total).to.equal(1)
270 expect(res.body.data).to.be.an('array')
271 expect(res.body.data.length).to.equal(1)
273 const video = res.body.data[0]
274 expect(video.name).to.equal('my super name')
275 expect(video.category).to.equal(2)
276 expect(video.categoryLabel).to.equal('Films')
277 expect(video.licence).to.equal(6)
278 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
279 expect(video.language).to.equal(3)
280 expect(video.languageLabel).to.equal('Mandarin')
281 expect(video.nsfw).to.be.ok
282 expect(video.description).to.equal('my super description')
283 expect(video.podHost).to.equal('localhost:9001')
284 expect(video.author).to.equal('root')
285 expect(video.isLocal).to.be.true
286 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
287 expect(dateIsValid(video.createdAt)).to.be.true
288 expect(dateIsValid(video.updatedAt)).to.be.true
290 expect(video.files).to.have.lengthOf(1)
292 const file = video.files[0]
293 expect(file.magnetUri).to.have.lengthOf.above(2)
294 expect(file.resolution).to.equal(720)
295 expect(file.resolutionLabel).to.equal('720p')
296 expect(file.size).to.equal(218910)
298 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
299 expect(test).to.equal(true)
302 it('Should not find a search by name by default', async function () {
303 const res = await searchVideo(server.url, 'hello')
305 expect(res.body.total).to.equal(0)
306 expect(res.body.data).to.be.an('array')
307 expect(res.body.data.length).to.equal(0)
310 it('Should not find a search by author', async function () {
311 const res = await searchVideo(server.url, 'hello', 'author')
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 tag', async function () {
319 const res = await searchVideo(server.url, 'hello', 'tags')
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 remove the video', async function () {
327 await removeVideo(server.url, server.accessToken, videoId)
329 const files1 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/videos/'))
330 expect(files1).to.have.lengthOf(0)
332 const files2 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/thumbnails/'))
333 expect(files2).to.have.lengthOf(0)
336 it('Should not have videos', async function () {
337 const res = await getVideosList(server.url)
339 expect(res.body.total).to.equal(0)
340 expect(res.body.data).to.be.an('array')
341 expect(res.body.data).to.have.lengthOf(0)
344 it('Should upload 6 videos', async function () {
348 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
349 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
352 const tasks: Promise<any>[] = []
353 for (const video of videos) {
354 const videoAttributes = {
355 name: video + ' name',
356 description: video + ' description',
361 tags: [ 'tag1', 'tag2', 'tag3' ],
365 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
369 await Promise.all(tasks)
372 it('Should have the correct durations', async function () {
373 const res = await getVideosList(server.url)
375 expect(res.body.total).to.equal(6)
376 const videos = res.body.data
377 expect(videos).to.be.an('array')
378 expect(videos).to.have.lengthOf(6)
380 const videosByName = keyBy<{ duration: number }>(videos, 'name')
381 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
382 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
383 expect(videosByName['video_short.webm name'].duration).to.equal(5)
384 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
385 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
386 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
389 it('Should have the correct thumbnails', async function () {
390 const res = await getVideosList(server.url)
392 const videos = res.body.data
394 videosListBase = videos
396 for (const video of videos) {
397 const videoName = video.name.replace(' name', '')
398 const test = await testVideoImage(server.url, videoName, video.thumbnailPath)
400 expect(test).to.equal(true)
404 it('Should list only the two first videos', async function () {
405 const res = await getVideosListPagination(server.url, 0, 2, 'name')
407 const videos = res.body.data
408 expect(res.body.total).to.equal(6)
409 expect(videos.length).to.equal(2)
410 expect(videos[0].name).to.equal(videosListBase[0].name)
411 expect(videos[1].name).to.equal(videosListBase[1].name)
414 it('Should list only the next three videos', async function () {
415 const res = await getVideosListPagination(server.url, 2, 3, 'name')
417 const videos = res.body.data
418 expect(res.body.total).to.equal(6)
419 expect(videos.length).to.equal(3)
420 expect(videos[0].name).to.equal(videosListBase[2].name)
421 expect(videos[1].name).to.equal(videosListBase[3].name)
422 expect(videos[2].name).to.equal(videosListBase[4].name)
425 it('Should list the last video', async function () {
426 const res = await getVideosListPagination(server.url, 5, 6, 'name')
428 const videos = res.body.data
429 expect(res.body.total).to.equal(6)
430 expect(videos.length).to.equal(1)
431 expect(videos[0].name).to.equal(videosListBase[5].name)
434 it('Should search the first video', async function () {
435 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name')
437 const videos = res.body.data
438 expect(res.body.total).to.equal(4)
439 expect(videos.length).to.equal(1)
440 expect(videos[0].name).to.equal('video_short1.webm name')
443 it('Should search the last two videos', async function () {
444 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name')
446 const videos = res.body.data
447 expect(res.body.total).to.equal(4)
448 expect(videos.length).to.equal(2)
449 expect(videos[0].name).to.equal('video_short3.webm name')
450 expect(videos[1].name).to.equal('video_short.webm name')
453 it('Should search all the webm videos', async function () {
454 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 15)
456 const videos = res.body.data
457 expect(res.body.total).to.equal(4)
458 expect(videos.length).to.equal(4)
461 it('Should search all the root author videos', async function () {
462 const res = await searchVideoWithPagination(server.url, 'root', 'author', 0, 15)
464 const videos = res.body.data
465 expect(res.body.total).to.equal(6)
466 expect(videos.length).to.equal(6)
469 // Not implemented yet
470 // it('Should search all the 9001 port videos', async function () {
471 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
473 // const videos = res.body.data
474 // expect(res.body.total).to.equal(6)
475 // expect(videos.length).to.equal(6)
481 // it('Should search all the localhost videos', async function () {
482 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', '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 the right magnetUri video', async function () {
493 const video = videosListBase[0]
494 const res = await searchVideoWithPagination(server.url, encodeURIComponent(video.files[0].magnetUri), 'magnetUri', 0, 15)
496 const videos = res.body.data
497 expect(res.body.total).to.equal(1)
498 expect(videos.length).to.equal(1)
499 expect(videos[0].name).to.equal(video.name)
502 it('Should list and sort by name in descending order', async function () {
503 const res = await getVideosListSort(server.url, '-name')
505 const videos = res.body.data
506 expect(res.body.total).to.equal(6)
507 expect(videos.length).to.equal(6)
508 expect(videos[0].name).to.equal('video_short.webm name')
509 expect(videos[1].name).to.equal('video_short.ogv name')
510 expect(videos[2].name).to.equal('video_short.mp4 name')
511 expect(videos[3].name).to.equal('video_short3.webm name')
512 expect(videos[4].name).to.equal('video_short2.webm name')
513 expect(videos[5].name).to.equal('video_short1.webm name')
516 it('Should search and sort by name in ascending order', async function () {
517 const res = await searchVideoWithSort(server.url, 'webm', 'name')
519 const videos = res.body.data
520 expect(res.body.total).to.equal(4)
521 expect(videos.length).to.equal(4)
523 expect(videos[0].name).to.equal('video_short1.webm name')
524 expect(videos[1].name).to.equal('video_short2.webm name')
525 expect(videos[2].name).to.equal('video_short3.webm name')
526 expect(videos[3].name).to.equal('video_short.webm name')
528 videoId = videos[2].id
531 it('Should update a video', async function () {
533 name: 'my super video updated',
538 description: 'my super description updated',
539 tags: [ 'tagup1', 'tagup2' ]
541 await updateVideo(server.url, server.accessToken, videoId, attributes)
544 it('Should have the video updated', async function () {
547 const res = await getVideo(server.url, videoId)
549 const video = res.body
551 expect(video.name).to.equal('my super video updated')
552 expect(video.category).to.equal(4)
553 expect(video.categoryLabel).to.equal('Art')
554 expect(video.licence).to.equal(2)
555 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
556 expect(video.language).to.equal(5)
557 expect(video.languageLabel).to.equal('Arabic')
558 expect(video.nsfw).to.be.ok
559 expect(video.description).to.equal('my super description updated')
560 expect(video.podHost).to.equal('localhost:9001')
561 expect(video.author).to.equal('root')
562 expect(video.isLocal).to.be.true
563 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
564 expect(dateIsValid(video.createdAt)).to.be.true
565 expect(dateIsValid(video.updatedAt)).to.be.true
567 expect(video.files).to.have.lengthOf(1)
569 const file = video.files[0]
570 const magnetUri = file.magnetUri
571 expect(file.magnetUri).to.have.lengthOf.above(2)
572 expect(file.resolution).to.equal(720)
573 expect(file.resolutionLabel).to.equal('720p')
574 expect(file.size).to.equal(292677)
576 const test = await testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath)
577 expect(test).to.equal(true)
579 const torrent = await webtorrentAdd(magnetUri)
580 expect(torrent.files).to.be.an('array')
581 expect(torrent.files.length).to.equal(1)
582 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
585 it('Should update only the tags of a video', async function () {
587 tags: [ 'tag1', 'tag2', 'supertag' ]
590 await updateVideo(server.url, server.accessToken, videoId, attributes)
592 const res = await getVideo(server.url, videoId)
593 const video = res.body
595 expect(video.name).to.equal('my super video updated')
596 expect(video.category).to.equal(4)
597 expect(video.categoryLabel).to.equal('Art')
598 expect(video.licence).to.equal(2)
599 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
600 expect(video.language).to.equal(5)
601 expect(video.languageLabel).to.equal('Arabic')
602 expect(video.nsfw).to.be.ok
603 expect(video.description).to.equal('my super description updated')
604 expect(video.podHost).to.equal('localhost:9001')
605 expect(video.author).to.equal('root')
606 expect(video.isLocal).to.be.true
607 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
608 expect(dateIsValid(video.createdAt)).to.be.true
609 expect(dateIsValid(video.updatedAt)).to.be.true
611 expect(video.files).to.have.lengthOf(1)
613 const file = video.files[0]
614 expect(file.magnetUri).to.have.lengthOf.above(2)
615 expect(file.resolution).to.equal(720)
616 expect(file.resolutionLabel).to.equal('720p')
617 expect(file.size).to.equal(292677)
620 it('Should update only the description of a video', async function () {
622 description: 'hello everybody'
625 await updateVideo(server.url, server.accessToken, videoId, attributes)
627 const res = await getVideo(server.url, videoId)
628 const video = res.body
630 expect(video.name).to.equal('my super video updated')
631 expect(video.category).to.equal(4)
632 expect(video.categoryLabel).to.equal('Art')
633 expect(video.licence).to.equal(2)
634 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
635 expect(video.language).to.equal(5)
636 expect(video.languageLabel).to.equal('Arabic')
637 expect(video.nsfw).to.be.ok
638 expect(video.description).to.equal('hello everybody')
639 expect(video.podHost).to.equal('localhost:9001')
640 expect(video.author).to.equal('root')
641 expect(video.isLocal).to.be.true
642 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
643 expect(dateIsValid(video.createdAt)).to.be.true
644 expect(dateIsValid(video.updatedAt)).to.be.true
646 expect(video.files).to.have.lengthOf(1)
648 const file = video.files[0]
649 expect(file.magnetUri).to.have.lengthOf.above(2)
650 expect(file.resolution).to.equal(720)
651 expect(file.resolutionLabel).to.equal('720p')
652 expect(file.size).to.equal(292677)
655 it('Should like a video', async function () {
656 await rateVideo(server.url, server.accessToken, videoId, 'like')
658 const res = await getVideo(server.url, videoId)
659 const video = res.body
661 expect(video.likes).to.equal(1)
662 expect(video.dislikes).to.equal(0)
665 it('Should dislike the same video', async function () {
666 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
668 const res = await getVideo(server.url, videoId)
669 const video = res.body
671 expect(video.likes).to.equal(0)
672 expect(video.dislikes).to.equal(1)
675 after(async function () {
676 killallServers([ server ])
678 // Keep the logs if the test failed