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.torrentUrl).to.equal(`${server.url}/static/torrents/${video.uuid}-${file.resolution}.torrent`)
131 expect(file.fileUrl).to.equal(`${server.url}/static/webseed/${video.uuid}-${file.resolution}.webm`)
132 expect(file.resolution).to.equal(720)
133 expect(file.resolutionLabel).to.equal('720p')
134 expect(file.size).to.equal(218910)
136 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
137 expect(test).to.equal(true)
140 videoUUID = video.uuid
142 const torrent = await webtorrentAdd(magnetUri)
143 expect(torrent.files).to.be.an('array')
144 expect(torrent.files.length).to.equal(1)
145 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
148 it('Should get the video', async function () {
149 // Yes, this could be long
152 const res = await getVideo(server.url, videoId)
154 const video = res.body
155 expect(video.name).to.equal('my super name')
156 expect(video.category).to.equal(2)
157 expect(video.categoryLabel).to.equal('Films')
158 expect(video.licence).to.equal(6)
159 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
160 expect(video.language).to.equal(3)
161 expect(video.languageLabel).to.equal('Mandarin')
162 expect(video.nsfw).to.be.ok
163 expect(video.description).to.equal('my super description')
164 expect(video.podHost).to.equal('localhost:9001')
165 expect(video.author).to.equal('root')
166 expect(video.isLocal).to.be.true
167 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
168 expect(dateIsValid(video.createdAt)).to.be.true
169 expect(dateIsValid(video.updatedAt)).to.be.true
171 expect(video.files).to.have.lengthOf(1)
173 const file = video.files[0]
174 expect(file.magnetUri).to.have.lengthOf.above(2)
175 expect(file.resolution).to.equal(720)
176 expect(file.resolutionLabel).to.equal('720p')
177 expect(file.size).to.equal(218910)
179 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
180 expect(test).to.equal(true)
182 // Wait the async views increment
186 it('Should get the video by UUID', async function () {
187 // Yes, this could be long
190 const res = await getVideo(server.url, videoUUID)
192 const video = res.body
193 expect(video.name).to.equal('my super name')
195 // Wait the async views increment
199 it('Should have the views updated', async function () {
200 const res = await getVideo(server.url, videoId)
202 const video = res.body
203 expect(video.views).to.equal(2)
206 it('Should search the video by name by default', async function () {
207 const res = await searchVideo(server.url, 'my')
209 expect(res.body.total).to.equal(1)
210 expect(res.body.data).to.be.an('array')
211 expect(res.body.data.length).to.equal(1)
213 const video = res.body.data[0]
214 expect(video.name).to.equal('my super name')
215 expect(video.category).to.equal(2)
216 expect(video.categoryLabel).to.equal('Films')
217 expect(video.licence).to.equal(6)
218 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
219 expect(video.language).to.equal(3)
220 expect(video.languageLabel).to.equal('Mandarin')
221 expect(video.nsfw).to.be.ok
222 expect(video.description).to.equal('my super description')
223 expect(video.podHost).to.equal('localhost:9001')
224 expect(video.author).to.equal('root')
225 expect(video.isLocal).to.be.true
226 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
227 expect(dateIsValid(video.createdAt)).to.be.true
228 expect(dateIsValid(video.updatedAt)).to.be.true
230 expect(video.files).to.have.lengthOf(1)
232 const file = video.files[0]
233 expect(file.magnetUri).to.have.lengthOf.above(2)
234 expect(file.resolution).to.equal(720)
235 expect(file.resolutionLabel).to.equal('720p')
236 expect(file.size).to.equal(218910)
238 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
239 expect(test).to.equal(true)
242 // Not implemented yet
243 // it('Should search the video by podHost', async function () {
244 // const res = await videosUtils.searchVideo(server.url, '9001', 'host')
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.description).to.equal('my super description')
253 // expect(video.podHost).to.equal('localhost:9001')
254 // expect(video.author).to.equal('root')
255 // expect(video.isLocal).to.be.true
256 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
257 // expect(dateIsValid(video.createdAt)).to.be.true
258 // expect(dateIsValid(video.updatedAt)).to.be.true
260 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
261 // expect(test).to.equal(true)
268 it('Should search the video by tag', async function () {
269 const res = await searchVideo(server.url, 'tag1', 'tags')
271 expect(res.body.total).to.equal(1)
272 expect(res.body.data).to.be.an('array')
273 expect(res.body.data.length).to.equal(1)
275 const video = res.body.data[0]
276 expect(video.name).to.equal('my super name')
277 expect(video.category).to.equal(2)
278 expect(video.categoryLabel).to.equal('Films')
279 expect(video.licence).to.equal(6)
280 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
281 expect(video.language).to.equal(3)
282 expect(video.languageLabel).to.equal('Mandarin')
283 expect(video.nsfw).to.be.ok
284 expect(video.description).to.equal('my super description')
285 expect(video.podHost).to.equal('localhost:9001')
286 expect(video.author).to.equal('root')
287 expect(video.isLocal).to.be.true
288 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
289 expect(dateIsValid(video.createdAt)).to.be.true
290 expect(dateIsValid(video.updatedAt)).to.be.true
292 expect(video.files).to.have.lengthOf(1)
294 const file = video.files[0]
295 expect(file.magnetUri).to.have.lengthOf.above(2)
296 expect(file.resolution).to.equal(720)
297 expect(file.resolutionLabel).to.equal('720p')
298 expect(file.size).to.equal(218910)
300 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
301 expect(test).to.equal(true)
304 it('Should not find a search by name by default', async function () {
305 const res = await searchVideo(server.url, 'hello')
307 expect(res.body.total).to.equal(0)
308 expect(res.body.data).to.be.an('array')
309 expect(res.body.data.length).to.equal(0)
312 it('Should not find a search by author', async function () {
313 const res = await searchVideo(server.url, 'hello', 'author')
315 expect(res.body.total).to.equal(0)
316 expect(res.body.data).to.be.an('array')
317 expect(res.body.data.length).to.equal(0)
320 it('Should not find a search by tag', async function () {
321 const res = await searchVideo(server.url, 'hello', 'tags')
323 expect(res.body.total).to.equal(0)
324 expect(res.body.data).to.be.an('array')
325 expect(res.body.data.length).to.equal(0)
328 it('Should remove the video', async function () {
329 await removeVideo(server.url, server.accessToken, videoId)
331 const files1 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/videos/'))
332 expect(files1).to.have.lengthOf(0)
334 const files2 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/thumbnails/'))
335 expect(files2).to.have.lengthOf(0)
338 it('Should not have videos', async function () {
339 const res = await getVideosList(server.url)
341 expect(res.body.total).to.equal(0)
342 expect(res.body.data).to.be.an('array')
343 expect(res.body.data).to.have.lengthOf(0)
346 it('Should upload 6 videos', async function () {
350 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
351 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
354 const tasks: Promise<any>[] = []
355 for (const video of videos) {
356 const videoAttributes = {
357 name: video + ' name',
358 description: video + ' description',
363 tags: [ 'tag1', 'tag2', 'tag3' ],
367 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
371 await Promise.all(tasks)
374 it('Should have the correct durations', async function () {
375 const res = await getVideosList(server.url)
377 expect(res.body.total).to.equal(6)
378 const videos = res.body.data
379 expect(videos).to.be.an('array')
380 expect(videos).to.have.lengthOf(6)
382 const videosByName = keyBy<{ duration: number }>(videos, 'name')
383 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
384 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
385 expect(videosByName['video_short.webm name'].duration).to.equal(5)
386 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
387 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
388 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
391 it('Should have the correct thumbnails', async function () {
392 const res = await getVideosList(server.url)
394 const videos = res.body.data
396 videosListBase = videos
398 for (const video of videos) {
399 const videoName = video.name.replace(' name', '')
400 const test = await testVideoImage(server.url, videoName, video.thumbnailPath)
402 expect(test).to.equal(true)
406 it('Should list only the two first videos', async function () {
407 const res = await getVideosListPagination(server.url, 0, 2, 'name')
409 const videos = res.body.data
410 expect(res.body.total).to.equal(6)
411 expect(videos.length).to.equal(2)
412 expect(videos[0].name).to.equal(videosListBase[0].name)
413 expect(videos[1].name).to.equal(videosListBase[1].name)
416 it('Should list only the next three videos', async function () {
417 const res = await getVideosListPagination(server.url, 2, 3, 'name')
419 const videos = res.body.data
420 expect(res.body.total).to.equal(6)
421 expect(videos.length).to.equal(3)
422 expect(videos[0].name).to.equal(videosListBase[2].name)
423 expect(videos[1].name).to.equal(videosListBase[3].name)
424 expect(videos[2].name).to.equal(videosListBase[4].name)
427 it('Should list the last video', async function () {
428 const res = await getVideosListPagination(server.url, 5, 6, 'name')
430 const videos = res.body.data
431 expect(res.body.total).to.equal(6)
432 expect(videos.length).to.equal(1)
433 expect(videos[0].name).to.equal(videosListBase[5].name)
436 it('Should search the first video', async function () {
437 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name')
439 const videos = res.body.data
440 expect(res.body.total).to.equal(4)
441 expect(videos.length).to.equal(1)
442 expect(videos[0].name).to.equal('video_short1.webm name')
445 it('Should search the last two videos', async function () {
446 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name')
448 const videos = res.body.data
449 expect(res.body.total).to.equal(4)
450 expect(videos.length).to.equal(2)
451 expect(videos[0].name).to.equal('video_short3.webm name')
452 expect(videos[1].name).to.equal('video_short.webm name')
455 it('Should search all the webm videos', async function () {
456 const res = await searchVideoWithPagination(server.url, 'webm', 'name', 0, 15)
458 const videos = res.body.data
459 expect(res.body.total).to.equal(4)
460 expect(videos.length).to.equal(4)
463 it('Should search all the root author videos', async function () {
464 const res = await searchVideoWithPagination(server.url, 'root', 'author', 0, 15)
466 const videos = res.body.data
467 expect(res.body.total).to.equal(6)
468 expect(videos.length).to.equal(6)
471 // Not implemented yet
472 // it('Should search all the 9001 port videos', async function () {
473 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
475 // const videos = res.body.data
476 // expect(res.body.total).to.equal(6)
477 // expect(videos.length).to.equal(6)
483 // it('Should search all the localhost videos', async function () {
484 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
486 // const videos = res.body.data
487 // expect(res.body.total).to.equal(6)
488 // expect(videos.length).to.equal(6)
494 it('Should search the right magnetUri video', async function () {
495 const video = videosListBase[0]
496 const res = await searchVideoWithPagination(server.url, encodeURIComponent(video.files[0].magnetUri), 'magnetUri', 0, 15)
498 const videos = res.body.data
499 expect(res.body.total).to.equal(1)
500 expect(videos.length).to.equal(1)
501 expect(videos[0].name).to.equal(video.name)
504 it('Should list and sort by name in descending order', async function () {
505 const res = await getVideosListSort(server.url, '-name')
507 const videos = res.body.data
508 expect(res.body.total).to.equal(6)
509 expect(videos.length).to.equal(6)
510 expect(videos[0].name).to.equal('video_short.webm name')
511 expect(videos[1].name).to.equal('video_short.ogv name')
512 expect(videos[2].name).to.equal('video_short.mp4 name')
513 expect(videos[3].name).to.equal('video_short3.webm name')
514 expect(videos[4].name).to.equal('video_short2.webm name')
515 expect(videos[5].name).to.equal('video_short1.webm name')
518 it('Should search and sort by name in ascending order', async function () {
519 const res = await searchVideoWithSort(server.url, 'webm', 'name')
521 const videos = res.body.data
522 expect(res.body.total).to.equal(4)
523 expect(videos.length).to.equal(4)
525 expect(videos[0].name).to.equal('video_short1.webm name')
526 expect(videos[1].name).to.equal('video_short2.webm name')
527 expect(videos[2].name).to.equal('video_short3.webm name')
528 expect(videos[3].name).to.equal('video_short.webm name')
530 videoId = videos[2].id
533 it('Should update a video', async function () {
535 name: 'my super video updated',
540 description: 'my super description updated',
541 tags: [ 'tagup1', 'tagup2' ]
543 await updateVideo(server.url, server.accessToken, videoId, attributes)
546 it('Should have the video updated', async function () {
549 const res = await getVideo(server.url, videoId)
551 const video = res.body
553 expect(video.name).to.equal('my super video updated')
554 expect(video.category).to.equal(4)
555 expect(video.categoryLabel).to.equal('Art')
556 expect(video.licence).to.equal(2)
557 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
558 expect(video.language).to.equal(5)
559 expect(video.languageLabel).to.equal('Arabic')
560 expect(video.nsfw).to.be.ok
561 expect(video.description).to.equal('my super description updated')
562 expect(video.podHost).to.equal('localhost:9001')
563 expect(video.author).to.equal('root')
564 expect(video.isLocal).to.be.true
565 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
566 expect(dateIsValid(video.createdAt)).to.be.true
567 expect(dateIsValid(video.updatedAt)).to.be.true
569 expect(video.files).to.have.lengthOf(1)
571 const file = video.files[0]
572 const magnetUri = file.magnetUri
573 expect(file.magnetUri).to.have.lengthOf.above(2)
574 expect(file.resolution).to.equal(720)
575 expect(file.resolutionLabel).to.equal('720p')
576 expect(file.size).to.equal(292677)
578 const test = await testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath)
579 expect(test).to.equal(true)
581 const torrent = await webtorrentAdd(magnetUri)
582 expect(torrent.files).to.be.an('array')
583 expect(torrent.files.length).to.equal(1)
584 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
587 it('Should update only the tags of a video', async function () {
589 tags: [ 'tag1', 'tag2', 'supertag' ]
592 await updateVideo(server.url, server.accessToken, videoId, attributes)
594 const res = await getVideo(server.url, videoId)
595 const video = res.body
597 expect(video.name).to.equal('my super video updated')
598 expect(video.category).to.equal(4)
599 expect(video.categoryLabel).to.equal('Art')
600 expect(video.licence).to.equal(2)
601 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
602 expect(video.language).to.equal(5)
603 expect(video.languageLabel).to.equal('Arabic')
604 expect(video.nsfw).to.be.ok
605 expect(video.description).to.equal('my super description updated')
606 expect(video.podHost).to.equal('localhost:9001')
607 expect(video.author).to.equal('root')
608 expect(video.isLocal).to.be.true
609 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
610 expect(dateIsValid(video.createdAt)).to.be.true
611 expect(dateIsValid(video.updatedAt)).to.be.true
613 expect(video.files).to.have.lengthOf(1)
615 const file = video.files[0]
616 expect(file.magnetUri).to.have.lengthOf.above(2)
617 expect(file.resolution).to.equal(720)
618 expect(file.resolutionLabel).to.equal('720p')
619 expect(file.size).to.equal(292677)
622 it('Should update only the description of a video', async function () {
624 description: 'hello everybody'
627 await updateVideo(server.url, server.accessToken, videoId, attributes)
629 const res = await getVideo(server.url, videoId)
630 const video = res.body
632 expect(video.name).to.equal('my super video updated')
633 expect(video.category).to.equal(4)
634 expect(video.categoryLabel).to.equal('Art')
635 expect(video.licence).to.equal(2)
636 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
637 expect(video.language).to.equal(5)
638 expect(video.languageLabel).to.equal('Arabic')
639 expect(video.nsfw).to.be.ok
640 expect(video.description).to.equal('hello everybody')
641 expect(video.podHost).to.equal('localhost:9001')
642 expect(video.author).to.equal('root')
643 expect(video.isLocal).to.be.true
644 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
645 expect(dateIsValid(video.createdAt)).to.be.true
646 expect(dateIsValid(video.updatedAt)).to.be.true
648 expect(video.files).to.have.lengthOf(1)
650 const file = video.files[0]
651 expect(file.magnetUri).to.have.lengthOf.above(2)
652 expect(file.resolution).to.equal(720)
653 expect(file.resolutionLabel).to.equal('720p')
654 expect(file.size).to.equal(292677)
657 it('Should like a video', async function () {
658 await rateVideo(server.url, server.accessToken, videoId, 'like')
660 const res = await getVideo(server.url, videoId)
661 const video = res.body
663 expect(video.likes).to.equal(1)
664 expect(video.dislikes).to.equal(0)
667 it('Should dislike the same video', async function () {
668 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
670 const res = await getVideo(server.url, videoId)
671 const video = res.body
673 expect(video.likes).to.equal(0)
674 expect(video.dislikes).to.equal(1)
677 after(async function () {
678 killallServers([ server ])
680 // Keep the logs if the test failed