1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
12 makeActivityPubGetRequest,
16 setAccessTokensToServers,
19 } from '@shared/extra-utils'
20 import { VideoDetails } from '@shared/models'
22 describe('Test update host scripts', function () {
23 let server: ServerInfo
25 before(async function () {
28 const overrideConfig = {
33 // Run server 2 to have transcoding enabled
34 server = await flushAndRunServer(2, overrideConfig)
35 await setAccessTokensToServers([ server ])
37 // Upload two videos for our needs
38 const videoAttributes = {}
39 const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes)
40 const video1UUID = resVideo1.body.video.uuid
41 await uploadVideo(server.url, server.accessToken, videoAttributes)
44 await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' })
47 const videoChannel = {
48 name: 'second_channel',
49 displayName: 'second video channel',
50 description: 'super video channel description'
52 await server.channelsCommand.create({ attributes: videoChannel })
55 const text = 'my super first comment'
56 await server.commentsCommand.createThread({ videoId: video1UUID, text })
58 await waitJobs(server)
61 it('Should run update host', async function () {
64 await killallServers([ server ])
65 // Run server with standard configuration
66 await reRunServer(server)
68 await server.cliCommand.execWithEnv(`npm run update-host`)
71 it('Should have updated videos url', async function () {
72 const res = await getVideosList(server.url)
73 expect(res.body.total).to.equal(2)
75 for (const video of res.body.data) {
76 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
78 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
80 const res = await getVideo(server.url, video.uuid)
81 const videoDetails: VideoDetails = res.body
83 expect(videoDetails.trackerUrls[0]).to.include(server.host)
84 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
85 expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host)
89 it('Should have updated video channels url', async function () {
90 const { data, total } = await server.channelsCommand.list({ sort: '-name' })
91 expect(total).to.equal(3)
93 for (const channel of data) {
94 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
96 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
100 it('Should have updated accounts url', async function () {
101 const body = await server.accountsCommand.list()
102 expect(body.total).to.equal(3)
104 for (const account of body.data) {
105 const usernameWithDomain = account.name
106 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
108 expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain)
112 it('Should have updated torrent hosts', async function () {
115 const res = await getVideosList(server.url)
116 const videos = res.body.data
117 expect(videos).to.have.lengthOf(2)
119 for (const video of videos) {
120 const res2 = await getVideo(server.url, video.id)
121 const videoDetails: VideoDetails = res2.body
123 expect(videoDetails.files).to.have.lengthOf(4)
125 for (const file of videoDetails.files) {
126 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
127 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
129 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id)
130 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
131 expect(announceWS).to.not.be.undefined
133 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
134 expect(announceHttp).to.not.be.undefined
136 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
141 after(async function () {
142 await cleanupTests([ server ])