1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
11 makeActivityPubGetRequest,
15 setAccessTokensToServers,
18 } from '@shared/extra-utils'
19 import { VideoDetails } from '@shared/models'
21 const expect = chai.expect
23 describe('Test update host scripts', function () {
24 let server: ServerInfo
26 before(async function () {
29 const overrideConfig = {
34 // Run server 2 to have transcoding enabled
35 server = await flushAndRunServer(2, overrideConfig)
36 await setAccessTokensToServers([ server ])
38 // Upload two videos for our needs
39 const videoAttributes = {}
40 const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes)
41 const video1UUID = resVideo1.body.video.uuid
42 await uploadVideo(server.url, server.accessToken, videoAttributes)
45 await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' })
48 const videoChannel = {
49 name: 'second_channel',
50 displayName: 'second video channel',
51 description: 'super video channel description'
53 await server.channelsCommand.create({ attributes: videoChannel })
56 const text = 'my super first comment'
57 await server.commentsCommand.createThread({ videoId: video1UUID, text })
59 await waitJobs(server)
62 it('Should run update host', async function () {
65 killallServers([ server ])
66 // Run server with standard configuration
67 await reRunServer(server)
69 await server.cliCommand.execWithEnv(`npm run update-host`)
72 it('Should have updated videos url', async function () {
73 const res = await getVideosList(server.url)
74 expect(res.body.total).to.equal(2)
76 for (const video of res.body.data) {
77 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
79 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
81 const res = await getVideo(server.url, video.uuid)
82 const videoDetails: VideoDetails = res.body
84 expect(videoDetails.trackerUrls[0]).to.include(server.host)
85 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
86 expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host)
90 it('Should have updated video channels url', async function () {
91 const { data, total } = await server.channelsCommand.list({ sort: '-name' })
92 expect(total).to.equal(3)
94 for (const channel of data) {
95 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
97 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
101 it('Should have updated accounts url', async function () {
102 const body = await server.accountsCommand.list()
103 expect(body.total).to.equal(3)
105 for (const account of body.data) {
106 const usernameWithDomain = account.name
107 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
109 expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain)
113 it('Should have updated torrent hosts', async function () {
116 const res = await getVideosList(server.url)
117 const videos = res.body.data
118 expect(videos).to.have.lengthOf(2)
120 for (const video of videos) {
121 const res2 = await getVideo(server.url, video.id)
122 const videoDetails: VideoDetails = res2.body
124 expect(videoDetails.files).to.have.lengthOf(4)
126 for (const file of videoDetails.files) {
127 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
128 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
130 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id)
131 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
132 expect(announceWS).to.not.be.undefined
134 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
135 expect(announceHttp).to.not.be.undefined
137 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
142 after(async function () {
143 await cleanupTests([ server ])