1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
5 import { VideoDetails } from '../../../shared/models/videos'
16 setAccessTokensToServers,
19 import { waitJobs } from '../utils/server/jobs'
21 const expect = chai.expect
23 describe('Test update host scripts', function () {
24 let server: ServerInfo
26 before(async function () {
31 const overrideConfig = {
36 // Run server 2 to have transcoding enabled
37 server = await runServer(2, overrideConfig)
38 await setAccessTokensToServers([ server ])
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)
45 await waitJobs(server)
48 it('Should update torrent hosts', async function () {
51 killallServers([ server ])
52 // Run server with standard configuration
53 server = await runServer(2)
55 const env = getEnvCli(server)
56 await execCLI(`${env} npm run update-host`)
58 const res = await getVideosList(server.url)
59 const videos = res.body.data
60 expect(videos).to.have.lengthOf(2)
62 for (const video of videos) {
63 const res2 = await getVideo(server.url, video.id)
64 const videoDetails: VideoDetails = res2.body
66 expect(videoDetails.files).to.have.lengthOf(4)
68 for (const file of videoDetails.files) {
69 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
70 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
72 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id)
73 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
74 expect(announceWS).to.not.be.undefined
76 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
77 expect(announceHttp).to.not.be.undefined
79 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
84 after(async function () {
85 killallServers([ server ])