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