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