]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/update-host.ts
import-youtube: add try/catch to manage token expiration when importing lot of youtub...
[github/Chocobozzz/PeerTube.git] / server / tests / cli / update-host.ts
CommitLineData
adcaf1a8
C
1/* tslint:disable:no-unused-expression */
2
fdbda9e3
C
3import 'mocha'
4import * as chai from 'chai'
5const expect = chai.expect
6
7import {
8 execCLI,
9 flushTests,
10 getEnvCli,
11 getVideosList,
12 killallServers,
13 parseTorrentVideo,
14 runServer,
15 ServerInfo,
16 setAccessTokensToServers,
40298b02 17 uploadVideo,
5f04dd2f
C
18 wait,
19 getVideo
fdbda9e3
C
20} from '../utils'
21
22describe('Test update host scripts', function () {
23 let server: ServerInfo
24
25 before(async function () {
40298b02 26 this.timeout(60000)
fdbda9e3
C
27
28 await flushTests()
29
30 const overrideConfig = {
31 webserver: {
32 port: 9256
33 }
34 }
40298b02
C
35 // Run server 2 to have transcoding enabled
36 server = await runServer(2, overrideConfig)
fdbda9e3
C
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)
40298b02 43 await wait(30000)
fdbda9e3
C
44 })
45
46 it('Should update torrent hosts', async function () {
e95561cd 47 this.timeout(30000)
fdbda9e3
C
48
49 killallServers([ server ])
40298b02
C
50 // Run server with standard configuration
51 server = await runServer(2)
fdbda9e3
C
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
40298b02 58 expect(videos).to.have.lengthOf(2)
fdbda9e3 59
40298b02 60 for (const video of videos) {
5f04dd2f
C
61 const res2 = await getVideo(server.url, video.id)
62 const videoDetails = res2.body
fdbda9e3 63
5f04dd2f
C
64 expect(videoDetails.files).to.have.lengthOf(4)
65
66 for (const file of videoDetails.files) {
40298b02
C
67 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
68 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
fdbda9e3 69
5f04dd2f 70 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution)
adcaf1a8
C
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
40298b02
C
77 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
78 }
79 }
fdbda9e3
C
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})