1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
5 import { VideoDetails, VideoFile } from '../../../shared/models/videos'
6 const expect = chai.expect
17 setAccessTokensToServers,
20 getVideo, flushAndRunMultipleServers, doubleFollow
23 function assertVideoProperties (video: VideoFile, resolution: number, extname: string) {
24 expect(video).to.have.nested.property('resolution.id', resolution)
25 expect(video).to.have.property('magnetUri').that.includes(`.${extname}`)
26 expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`)
27 expect(video).to.have.property('fileUrl').that.includes(`.${extname}`)
28 expect(video).to.have.property('size').that.is.above(0)
31 describe('Test create import video jobs', function () {
34 let servers: ServerInfo[] = []
35 let video1UUID: string
36 let video2UUID: string
38 before(async function () {
42 // Run server 2 to have transcoding enabled
43 servers = await flushAndRunMultipleServers(2)
44 await setAccessTokensToServers(servers)
46 await doubleFollow(servers[0], servers[1])
48 // Upload two videos for our needs
49 const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
50 video1UUID = res1.body.video.uuid
51 const res2 = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
52 video2UUID = res2.body.video.uuid
57 it('Should run a import job on video 1 with a lower resolution', async function () {
58 const env = getEnvCli(servers[0])
59 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/api/fixtures/video_short-480.webm`)
63 for (const server of servers) {
64 const { data: videos } = (await getVideosList(server.url)).body
65 expect(videos).to.have.lengthOf(2)
67 let infoHashes: { [ id: number ]: string } = {}
69 const video = videos.find(({ uuid }) => uuid === video1UUID)
70 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
72 expect(videoDetail.files).to.have.lengthOf(2)
73 const [originalVideo, transcodedVideo] = videoDetail.files
74 assertVideoProperties(originalVideo, 720, 'webm')
75 assertVideoProperties(transcodedVideo, 480, 'webm')
79 it('Should run a import job on video 2 with the same resolution', async function () {
80 const env = getEnvCli(servers[1])
81 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/api/fixtures/video_short.ogv`)
85 for (const server of servers.reverse()) {
86 const { data: videos } = (await getVideosList(server.url)).body
87 expect(videos).to.have.lengthOf(2)
89 let infoHashes: { [ id: number ]: string }
91 const video = videos.find(({ uuid }) => uuid === video2UUID)
92 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
94 expect(videoDetail.files).to.have.lengthOf(4)
95 const [originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240] = videoDetail.files
96 assertVideoProperties(originalVideo, 720, 'ogv')
97 assertVideoProperties(transcodedVideo420, 480, 'mp4')
98 assertVideoProperties(transcodedVideo320, 360, 'mp4')
99 assertVideoProperties(transcodedVideo240, 240, 'mp4')
103 after(async function () {
104 killallServers(servers)
106 // Keep the logs if the test failed