Change how we handle resolution
[oweals/peertube.git] / server / tests / api / video-transcoder.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 const expect = chai.expect
6
7 import {
8   ServerInfo,
9   flushTests,
10   uploadVideo,
11   getVideosList,
12   wait,
13   setAccessTokensToServers,
14   flushAndRunMultipleServers,
15   killallServers,
16   webtorrentAdd
17 } from '../utils'
18
19 describe('Test video transcoding', function () {
20   let servers: ServerInfo[] = []
21
22   before(async function () {
23     this.timeout(60000)
24
25     // Run servers
26     servers = await flushAndRunMultipleServers(2)
27
28     await setAccessTokensToServers(servers)
29   })
30
31   it('Should not transcode video on server 1', async function () {
32     this.timeout(60000)
33
34     const videoAttributes = {
35       name: 'my super name for pod 1',
36       description: 'my super description for pod 1',
37       fixture: 'video_short.webm'
38     }
39     await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
40
41     await wait(30000)
42
43     const res = await getVideosList(servers[0].url)
44     const video = res.body.data[0]
45     expect(video.files).to.have.lengthOf(1)
46
47     const magnetUri = video.files[0].magnetUri
48     expect(magnetUri).to.match(/\.webm/)
49
50     const torrent = await webtorrentAdd(magnetUri)
51     expect(torrent.files).to.be.an('array')
52     expect(torrent.files.length).to.equal(1)
53     expect(torrent.files[0].path).match(/\.webm$/)
54   })
55
56   it('Should transcode video on server 2', async function () {
57     this.timeout(60000)
58
59     const videoAttributes = {
60       name: 'my super name for pod 2',
61       description: 'my super description for pod 2',
62       fixture: 'video_short.webm'
63     }
64     await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
65
66     await wait(30000)
67
68     const res = await getVideosList(servers[1].url)
69
70     const video = res.body.data[0]
71     expect(video.files).to.have.lengthOf(4)
72
73     const magnetUri = video.files[0].magnetUri
74     expect(magnetUri).to.match(/\.mp4/)
75
76     const torrent = await webtorrentAdd(magnetUri)
77     expect(torrent.files).to.be.an('array')
78     expect(torrent.files.length).to.equal(1)
79     expect(torrent.files[0].path).match(/\.mp4$/)
80   })
81
82   after(async function () {
83     killallServers(servers)
84
85     // Keep the logs if the test failed
86     if (this['ok']) {
87       await flushTests()
88     }
89   })
90 })