]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/update-host.ts
Add video channels
[github/Chocobozzz/PeerTube.git] / server / tests / cli / update-host.ts
CommitLineData
fdbda9e3
C
1import 'mocha'
2import * as chai from 'chai'
3const expect = chai.expect
4
5import {
6 execCLI,
7 flushTests,
8 getEnvCli,
9 getVideosList,
10 killallServers,
11 parseTorrentVideo,
12 runServer,
13 ServerInfo,
14 setAccessTokensToServers,
40298b02
C
15 uploadVideo,
16 wait
fdbda9e3
C
17} from '../utils'
18
19describe('Test update host scripts', function () {
20 let server: ServerInfo
21
22 before(async function () {
40298b02 23 this.timeout(60000)
fdbda9e3
C
24
25 await flushTests()
26
27 const overrideConfig = {
28 webserver: {
29 port: 9256
30 }
31 }
40298b02
C
32 // Run server 2 to have transcoding enabled
33 server = await runServer(2, overrideConfig)
fdbda9e3
C
34 await setAccessTokensToServers([ server ])
35
36 // Upload two videos for our needs
37 const videoAttributes = {}
38 await uploadVideo(server.url, server.accessToken, videoAttributes)
39 await uploadVideo(server.url, server.accessToken, videoAttributes)
40298b02 40 await wait(30000)
fdbda9e3
C
41 })
42
43 it('Should update torrent hosts', async function () {
e95561cd 44 this.timeout(30000)
fdbda9e3
C
45
46 killallServers([ server ])
40298b02
C
47 // Run server with standard configuration
48 server = await runServer(2)
fdbda9e3
C
49
50 const env = getEnvCli(server)
51 await execCLI(`${env} npm run update-host`)
52
53 const res = await getVideosList(server.url)
54 const videos = res.body.data
40298b02 55 expect(videos).to.have.lengthOf(2)
fdbda9e3 56
40298b02 57 for (const video of videos) {
14d3270f 58 expect(video.files).to.have.lengthOf(4)
fdbda9e3 59
40298b02
C
60 for (const file of video.files) {
61 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
62 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
fdbda9e3 63
14d3270f 64 const torrent = await parseTorrentVideo(server, video.uuid, file.resolution)
40298b02
C
65 expect(torrent.announce[0]).to.equal('ws://localhost:9002/tracker/socket')
66 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
67 }
68 }
fdbda9e3
C
69 })
70
71 after(async function () {
72 killallServers([ server ])
73
74 // Keep the logs if the test failed
75 if (this['ok']) {
76 await flushTests()
77 }
78 })
79})