1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
14 makeActivityPubGetRequest,
18 setAccessTokensToServers,
20 } from '../../../shared/extra-utils'
21 import { waitJobs } from '../../../shared/extra-utils/server/jobs'
22 import { getAccountsList } from '../../../shared/extra-utils/users/accounts'
23 import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
24 import { VideoDetails } from '../../../shared/models/videos'
26 const expect = chai.expect
28 describe('Test update host scripts', function () {
29 let server: ServerInfo
31 before(async function () {
34 const overrideConfig = {
39 // Run server 2 to have transcoding enabled
40 server = await flushAndRunServer(2, overrideConfig)
41 await setAccessTokensToServers([ server ])
43 // Upload two videos for our needs
44 const videoAttributes = {}
45 const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes)
46 const video1UUID = resVideo1.body.video.uuid
47 await uploadVideo(server.url, server.accessToken, videoAttributes)
50 await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' })
53 const videoChannel = {
54 name: 'second_channel',
55 displayName: 'second video channel',
56 description: 'super video channel description'
58 await addVideoChannel(server.url, server.accessToken, videoChannel)
61 const text = 'my super first comment'
62 await addVideoCommentThread(server.url, server.accessToken, video1UUID, text)
64 await waitJobs(server)
67 it('Should run update host', async function () {
70 killallServers([ server ])
71 // Run server with standard configuration
72 await reRunServer(server)
74 await server.cliCommand.execWithEnv(`npm run update-host`)
77 it('Should have updated videos url', async function () {
78 const res = await getVideosList(server.url)
79 expect(res.body.total).to.equal(2)
81 for (const video of res.body.data) {
82 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
84 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
86 const res = await getVideo(server.url, video.uuid)
87 const videoDetails: VideoDetails = res.body
89 expect(videoDetails.trackerUrls[0]).to.include(server.host)
90 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
91 expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host)
95 it('Should have updated video channels url', async function () {
96 const res = await getVideoChannelsList(server.url, 0, 5, '-name')
97 expect(res.body.total).to.equal(3)
99 for (const channel of res.body.data) {
100 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
102 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
106 it('Should have updated accounts url', async function () {
107 const res = await getAccountsList(server.url)
108 expect(res.body.total).to.equal(3)
110 for (const account of res.body.data) {
111 const usernameWithDomain = account.name
112 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
114 expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain)
118 it('Should have updated torrent hosts', async function () {
121 const res = await getVideosList(server.url)
122 const videos = res.body.data
123 expect(videos).to.have.lengthOf(2)
125 for (const video of videos) {
126 const res2 = await getVideo(server.url, video.id)
127 const videoDetails: VideoDetails = res2.body
129 expect(videoDetails.files).to.have.lengthOf(4)
131 for (const file of videoDetails.files) {
132 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
133 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
135 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id)
136 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
137 expect(announceWS).to.not.be.undefined
139 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
140 expect(announceHttp).to.not.be.undefined
142 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
147 after(async function () {
148 await cleanupTests([ server ])