1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
14 makeActivityPubGetRequest,
18 setAccessTokensToServers,
21 } from '@shared/extra-utils'
22 import { VideoDetails } from '@shared/models'
24 const expect = chai.expect
26 describe('Test update host scripts', function () {
27 let server: ServerInfo
29 before(async function () {
32 const overrideConfig = {
37 // Run server 2 to have transcoding enabled
38 server = await flushAndRunServer(2, overrideConfig)
39 await setAccessTokensToServers([ server ])
41 // Upload two videos for our needs
42 const videoAttributes = {}
43 const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes)
44 const video1UUID = resVideo1.body.video.uuid
45 await uploadVideo(server.url, server.accessToken, videoAttributes)
48 await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' })
51 const videoChannel = {
52 name: 'second_channel',
53 displayName: 'second video channel',
54 description: 'super video channel description'
56 await addVideoChannel(server.url, server.accessToken, videoChannel)
59 const text = 'my super first comment'
60 await addVideoCommentThread(server.url, server.accessToken, video1UUID, text)
62 await waitJobs(server)
65 it('Should run update host', async function () {
68 killallServers([ server ])
69 // Run server with standard configuration
70 await reRunServer(server)
72 await server.cliCommand.execWithEnv(`npm run update-host`)
75 it('Should have updated videos url', async function () {
76 const res = await getVideosList(server.url)
77 expect(res.body.total).to.equal(2)
79 for (const video of res.body.data) {
80 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
82 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
84 const res = await getVideo(server.url, video.uuid)
85 const videoDetails: VideoDetails = res.body
87 expect(videoDetails.trackerUrls[0]).to.include(server.host)
88 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
89 expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host)
93 it('Should have updated video channels url', async function () {
94 const res = await getVideoChannelsList(server.url, 0, 5, '-name')
95 expect(res.body.total).to.equal(3)
97 for (const channel of res.body.data) {
98 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
100 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
104 it('Should have updated accounts url', async function () {
105 const body = await server.accountsCommand.list()
106 expect(body.total).to.equal(3)
108 for (const account of body.data) {
109 const usernameWithDomain = account.name
110 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
112 expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain)
116 it('Should have updated torrent hosts', async function () {
119 const res = await getVideosList(server.url)
120 const videos = res.body.data
121 expect(videos).to.have.lengthOf(2)
123 for (const video of videos) {
124 const res2 = await getVideo(server.url, video.id)
125 const videoDetails: VideoDetails = res2.body
127 expect(videoDetails.files).to.have.lengthOf(4)
129 for (const file of videoDetails.files) {
130 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
131 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
133 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id)
134 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
135 expect(announceWS).to.not.be.undefined
137 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
138 expect(announceHttp).to.not.be.undefined
140 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
145 after(async function () {
146 await cleanupTests([ server ])