]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/create-import-video-file-job.ts
Move utils to /shared
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-import-video-file-job.ts
CommitLineData
0138af92
FF
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as chai from 'chai'
5import { VideoDetails, VideoFile } from '../../../shared/models/videos'
0138af92 6import {
28be8916 7 doubleFollow,
0138af92 8 execCLI,
28be8916 9 flushAndRunMultipleServers,
0138af92
FF
10 flushTests,
11 getEnvCli,
28be8916 12 getVideo,
0138af92
FF
13 getVideosList,
14 killallServers,
0138af92
FF
15 ServerInfo,
16 setAccessTokensToServers,
3cd0734f 17 uploadVideo
9639bd17 18} from '../../../shared/utils'
19import { waitJobs } from '../../../shared/utils/server/jobs'
0138af92 20
28be8916
C
21const expect = chai.expect
22
23function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) {
0138af92
FF
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)
28be8916
C
29
30 if (size) expect(video.size).to.equal(size)
0138af92
FF
31}
32
33describe('Test create import video jobs', function () {
34 this.timeout(60000)
35
36 let servers: ServerInfo[] = []
37 let video1UUID: string
38 let video2UUID: string
39
40 before(async function () {
41 this.timeout(90000)
42 await flushTests()
43
44 // Run server 2 to have transcoding enabled
45 servers = await flushAndRunMultipleServers(2)
46 await setAccessTokensToServers(servers)
47
48 await doubleFollow(servers[0], servers[1])
49
50 // Upload two videos for our needs
51 const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
52 video1UUID = res1.body.video.uuid
53 const res2 = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
54 video2UUID = res2.body.video.uuid
55
28be8916 56 // Transcoding
3cd0734f 57 await waitJobs(servers)
0138af92
FF
58 })
59
60 it('Should run a import job on video 1 with a lower resolution', async function () {
61 const env = getEnvCli(servers[0])
99d10301 62 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`)
0138af92 63
3cd0734f 64 await waitJobs(servers)
0138af92 65
28be8916 66 let magnetUri: string
0138af92
FF
67 for (const server of servers) {
68 const { data: videos } = (await getVideosList(server.url)).body
69 expect(videos).to.have.lengthOf(2)
70
0138af92
FF
71 const video = videos.find(({ uuid }) => uuid === video1UUID)
72 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
73
74 expect(videoDetail.files).to.have.lengthOf(2)
75 const [originalVideo, transcodedVideo] = videoDetail.files
6ccdf3a2
C
76 assertVideoProperties(originalVideo, 720, 'webm', 218910)
77 assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
28be8916
C
78
79 if (!magnetUri) magnetUri = transcodedVideo.magnetUri
80 else expect(transcodedVideo.magnetUri).to.equal(magnetUri)
0138af92
FF
81 }
82 })
83
6ccdf3a2 84 it('Should run a import job on video 2 with the same resolution and a different extension', async function () {
0138af92 85 const env = getEnvCli(servers[1])
99d10301 86 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`)
0138af92 87
3cd0734f 88 await waitJobs(servers)
0138af92 89
28be8916 90 let magnetUri: string
6ccdf3a2 91 for (const server of servers) {
0138af92
FF
92 const { data: videos } = (await getVideosList(server.url)).body
93 expect(videos).to.have.lengthOf(2)
94
0138af92
FF
95 const video = videos.find(({ uuid }) => uuid === video2UUID)
96 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
97
98 expect(videoDetail.files).to.have.lengthOf(4)
99 const [originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240] = videoDetail.files
28be8916 100 assertVideoProperties(originalVideo, 720, 'ogv', 140849)
0138af92
FF
101 assertVideoProperties(transcodedVideo420, 480, 'mp4')
102 assertVideoProperties(transcodedVideo320, 360, 'mp4')
103 assertVideoProperties(transcodedVideo240, 240, 'mp4')
28be8916
C
104
105 if (!magnetUri) magnetUri = originalVideo.magnetUri
106 else expect(originalVideo.magnetUri).to.equal(magnetUri)
0138af92
FF
107 }
108 })
109
6ccdf3a2
C
110 it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
111 const env = getEnvCli(servers[0])
112 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`)
113
3cd0734f 114 await waitJobs(servers)
6ccdf3a2
C
115
116 let magnetUri: string
117 for (const server of servers) {
118 const { data: videos } = (await getVideosList(server.url)).body
119 expect(videos).to.have.lengthOf(2)
120
121 const video = videos.find(({ uuid }) => uuid === video1UUID)
122 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
123
124 expect(videoDetail.files).to.have.lengthOf(2)
125 const [ video720, video480 ] = videoDetail.files
126 assertVideoProperties(video720, 720, 'webm', 942961)
127 assertVideoProperties(video480, 480, 'webm', 69217)
128
129 if (!magnetUri) magnetUri = video720.magnetUri
130 else expect(video720.magnetUri).to.equal(magnetUri)
131 }
132 })
133
0138af92
FF
134 after(async function () {
135 killallServers(servers)
0138af92
FF
136 })
137})