1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
5 import { VideoDetails } from '../../../shared/models/videos'
6 import { waitJobs } from '../../../shared/utils/server/jobs'
7 import { addVideoCommentThread } from '../../../shared/utils/videos/video-comments'
18 makeActivityPubGetRequest,
22 setAccessTokensToServers,
24 } from '../../../shared/utils'
25 import { getAccountsList } from '../../../shared/utils/users/accounts'
27 const expect = chai.expect
29 describe('Test update host scripts', function () {
30 let server: ServerInfo
32 before(async function () {
37 const overrideConfig = {
42 // Run server 2 to have transcoding enabled
43 server = await runServer(2, overrideConfig)
44 await setAccessTokensToServers([ server ])
46 // Upload two videos for our needs
47 const videoAttributes = {}
48 const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes)
49 const video1UUID = resVideo1.body.video.uuid
50 await uploadVideo(server.url, server.accessToken, videoAttributes)
53 await createUser(server.url, server.accessToken, 'toto', 'coucou')
56 const videoChannel = {
57 name: 'second_channel',
58 displayName: 'second video channel',
59 description: 'super video channel description'
61 await addVideoChannel(server.url, server.accessToken, videoChannel)
64 const text = 'my super first comment'
65 await addVideoCommentThread(server.url, server.accessToken, video1UUID, text)
67 await waitJobs(server)
70 it('Should run update host', async function () {
73 killallServers([ server ])
74 // Run server with standard configuration
75 server = await runServer(2)
77 const env = getEnvCli(server)
78 await execCLI(`${env} npm run update-host`)
81 it('Should have updated videos url', async function () {
82 const res = await getVideosList(server.url)
83 expect(res.body.total).to.equal(2)
85 for (const video of res.body.data) {
86 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
88 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
90 const res = await getVideo(server.url, video.uuid)
91 const videoDetails: VideoDetails = res.body
93 expect(videoDetails.trackerUrls[0]).to.include(server.host)
94 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
95 expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host)
99 it('Should have updated video channels url', async function () {
100 const res = await getVideoChannelsList(server.url, 0, 5, '-name')
101 expect(res.body.total).to.equal(3)
103 for (const channel of res.body.data) {
104 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
106 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
110 it('Should have updated accounts url', async function () {
111 const res = await getAccountsList(server.url)
112 expect(res.body.total).to.equal(3)
114 for (const account of res.body.data) {
115 const usernameWithDomain = account.name
116 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
118 expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain)
122 it('Should have updated torrent hosts', async function () {
125 const res = await getVideosList(server.url)
126 const videos = res.body.data
127 expect(videos).to.have.lengthOf(2)
129 for (const video of videos) {
130 const res2 = await getVideo(server.url, video.id)
131 const videoDetails: VideoDetails = res2.body
133 expect(videoDetails.files).to.have.lengthOf(4)
135 for (const file of videoDetails.files) {
136 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
137 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
139 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id)
140 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
141 expect(announceWS).to.not.be.undefined
143 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
144 expect(announceHttp).to.not.be.undefined
146 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
151 after(async function () {
152 killallServers([ server ])