2
1

create-import-video-file-job.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* tslint:disable:no-unused-expression */
  2. import 'mocha'
  3. import * as chai from 'chai'
  4. import { VideoDetails, VideoFile } from '../../../shared/models/videos'
  5. import {
  6. cleanupTests,
  7. doubleFollow,
  8. execCLI,
  9. flushAndRunMultipleServers,
  10. flushTests,
  11. getEnvCli,
  12. getVideo,
  13. getVideosList,
  14. killallServers,
  15. ServerInfo,
  16. setAccessTokensToServers,
  17. uploadVideo
  18. } from '../../../shared/extra-utils'
  19. import { waitJobs } from '../../../shared/extra-utils/server/jobs'
  20. const expect = chai.expect
  21. function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) {
  22. expect(video).to.have.nested.property('resolution.id', resolution)
  23. expect(video).to.have.property('magnetUri').that.includes(`.${extname}`)
  24. expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`)
  25. expect(video).to.have.property('fileUrl').that.includes(`.${extname}`)
  26. expect(video).to.have.property('size').that.is.above(0)
  27. if (size) expect(video.size).to.equal(size)
  28. }
  29. describe('Test create import video jobs', function () {
  30. this.timeout(60000)
  31. let servers: ServerInfo[] = []
  32. let video1UUID: string
  33. let video2UUID: string
  34. before(async function () {
  35. this.timeout(90000)
  36. // Run server 2 to have transcoding enabled
  37. servers = await flushAndRunMultipleServers(2)
  38. await setAccessTokensToServers(servers)
  39. await doubleFollow(servers[0], servers[1])
  40. // Upload two videos for our needs
  41. const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
  42. video1UUID = res1.body.video.uuid
  43. const res2 = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
  44. video2UUID = res2.body.video.uuid
  45. // Transcoding
  46. await waitJobs(servers)
  47. })
  48. it('Should run a import job on video 1 with a lower resolution', async function () {
  49. const env = getEnvCli(servers[0])
  50. await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`)
  51. await waitJobs(servers)
  52. let magnetUri: string
  53. for (const server of servers) {
  54. const { data: videos } = (await getVideosList(server.url)).body
  55. expect(videos).to.have.lengthOf(2)
  56. const video = videos.find(({ uuid }) => uuid === video1UUID)
  57. const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
  58. expect(videoDetail.files).to.have.lengthOf(2)
  59. const [originalVideo, transcodedVideo] = videoDetail.files
  60. assertVideoProperties(originalVideo, 720, 'webm', 218910)
  61. assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
  62. if (!magnetUri) magnetUri = transcodedVideo.magnetUri
  63. else expect(transcodedVideo.magnetUri).to.equal(magnetUri)
  64. }
  65. })
  66. it('Should run a import job on video 2 with the same resolution and a different extension', async function () {
  67. const env = getEnvCli(servers[1])
  68. await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`)
  69. await waitJobs(servers)
  70. let magnetUri: string
  71. for (const server of servers) {
  72. const { data: videos } = (await getVideosList(server.url)).body
  73. expect(videos).to.have.lengthOf(2)
  74. const video = videos.find(({ uuid }) => uuid === video2UUID)
  75. const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
  76. expect(videoDetail.files).to.have.lengthOf(4)
  77. const [originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240] = videoDetail.files
  78. assertVideoProperties(originalVideo, 720, 'ogv', 140849)
  79. assertVideoProperties(transcodedVideo420, 480, 'mp4')
  80. assertVideoProperties(transcodedVideo320, 360, 'mp4')
  81. assertVideoProperties(transcodedVideo240, 240, 'mp4')
  82. if (!magnetUri) magnetUri = originalVideo.magnetUri
  83. else expect(originalVideo.magnetUri).to.equal(magnetUri)
  84. }
  85. })
  86. it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
  87. const env = getEnvCli(servers[0])
  88. await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`)
  89. await waitJobs(servers)
  90. let magnetUri: string
  91. for (const server of servers) {
  92. const { data: videos } = (await getVideosList(server.url)).body
  93. expect(videos).to.have.lengthOf(2)
  94. const video = videos.find(({ uuid }) => uuid === video1UUID)
  95. const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
  96. expect(videoDetail.files).to.have.lengthOf(2)
  97. const [ video720, video480 ] = videoDetail.files
  98. assertVideoProperties(video720, 720, 'webm', 942961)
  99. assertVideoProperties(video480, 480, 'webm', 69217)
  100. if (!magnetUri) magnetUri = video720.magnetUri
  101. else expect(video720.magnetUri).to.equal(magnetUri)
  102. }
  103. })
  104. after(async function () {
  105. await cleanupTests(servers)
  106. })
  107. })