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