1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
11 makeActivityPubGetRequest,
15 setAccessTokensToServers,
18 } from '@shared/extra-utils'
19 import { VideoDetails } from '@shared/models'
21 describe('Test update host scripts', function () {
22 let server: ServerInfo
24 before(async function () {
27 const overrideConfig = {
32 // Run server 2 to have transcoding enabled
33 server = await flushAndRunServer(2, overrideConfig)
34 await setAccessTokensToServers([ server ])
36 // Upload two videos for our needs
37 const videoAttributes = {}
38 const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes)
39 const video1UUID = resVideo1.body.video.uuid
40 await uploadVideo(server.url, server.accessToken, videoAttributes)
43 await server.usersCommand.create({ username: 'toto', password: 'coucou' })
46 const videoChannel = {
47 name: 'second_channel',
48 displayName: 'second video channel',
49 description: 'super video channel description'
51 await server.channelsCommand.create({ attributes: videoChannel })
54 const text = 'my super first comment'
55 await server.commentsCommand.createThread({ videoId: video1UUID, text })
57 await waitJobs(server)
60 it('Should run update host', async function () {
63 await killallServers([ server ])
64 // Run server with standard configuration
65 await reRunServer(server)
67 await server.cliCommand.execWithEnv(`npm run update-host`)
70 it('Should have updated videos url', async function () {
71 const res = await getVideosList(server.url)
72 expect(res.body.total).to.equal(2)
74 for (const video of res.body.data) {
75 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
77 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
79 const res = await getVideo(server.url, video.uuid)
80 const videoDetails: VideoDetails = res.body
82 expect(videoDetails.trackerUrls[0]).to.include(server.host)
83 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
84 expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host)
88 it('Should have updated video channels url', async function () {
89 const { data, total } = await server.channelsCommand.list({ sort: '-name' })
90 expect(total).to.equal(3)
92 for (const channel of data) {
93 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
95 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
99 it('Should have updated accounts url', async function () {
100 const body = await server.accountsCommand.list()
101 expect(body.total).to.equal(3)
103 for (const account of body.data) {
104 const usernameWithDomain = account.name
105 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
107 expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain)
111 it('Should have updated torrent hosts', async function () {
114 const res = await getVideosList(server.url)
115 const videos = res.body.data
116 expect(videos).to.have.lengthOf(2)
118 for (const video of videos) {
119 const res2 = await getVideo(server.url, video.id)
120 const videoDetails: VideoDetails = res2.body
122 expect(videoDetails.files).to.have.lengthOf(4)
124 for (const file of videoDetails.files) {
125 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
126 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
128 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id)
129 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
130 expect(announceWS).to.not.be.undefined
132 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
133 expect(announceHttp).to.not.be.undefined
135 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
140 after(async function () {
141 await cleanupTests([ server ])