1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
12 makeActivityPubGetRequest,
16 setAccessTokensToServers,
19 } from '@shared/extra-utils'
20 import { VideoDetails } from '@shared/models'
22 const expect = chai.expect
24 describe('Test update host scripts', function () {
25 let server: ServerInfo
27 before(async function () {
30 const overrideConfig = {
35 // Run server 2 to have transcoding enabled
36 server = await flushAndRunServer(2, overrideConfig)
37 await setAccessTokensToServers([ server ])
39 // Upload two videos for our needs
40 const videoAttributes = {}
41 const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes)
42 const video1UUID = resVideo1.body.video.uuid
43 await uploadVideo(server.url, server.accessToken, videoAttributes)
46 await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' })
49 const videoChannel = {
50 name: 'second_channel',
51 displayName: 'second video channel',
52 description: 'super video channel description'
54 await server.channelsCommand.create({ attributes: videoChannel })
57 const text = 'my super first comment'
58 await addVideoCommentThread(server.url, server.accessToken, video1UUID, text)
60 await waitJobs(server)
63 it('Should run update host', async function () {
66 killallServers([ server ])
67 // Run server with standard configuration
68 await reRunServer(server)
70 await server.cliCommand.execWithEnv(`npm run update-host`)
73 it('Should have updated videos url', async function () {
74 const res = await getVideosList(server.url)
75 expect(res.body.total).to.equal(2)
77 for (const video of res.body.data) {
78 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
80 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
82 const res = await getVideo(server.url, video.uuid)
83 const videoDetails: VideoDetails = res.body
85 expect(videoDetails.trackerUrls[0]).to.include(server.host)
86 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
87 expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host)
91 it('Should have updated video channels url', async function () {
92 const { data, total } = await server.channelsCommand.list({ sort: '-name' })
93 expect(total).to.equal(3)
95 for (const channel of data) {
96 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
98 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
102 it('Should have updated accounts url', async function () {
103 const body = await server.accountsCommand.list()
104 expect(body.total).to.equal(3)
106 for (const account of body.data) {
107 const usernameWithDomain = account.name
108 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
110 expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain)
114 it('Should have updated torrent hosts', async function () {
117 const res = await getVideosList(server.url)
118 const videos = res.body.data
119 expect(videos).to.have.lengthOf(2)
121 for (const video of videos) {
122 const res2 = await getVideo(server.url, video.id)
123 const videoDetails: VideoDetails = res2.body
125 expect(videoDetails.files).to.have.lengthOf(4)
127 for (const file of videoDetails.files) {
128 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
129 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
131 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id)
132 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
133 expect(announceWS).to.not.be.undefined
135 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
136 expect(announceHttp).to.not.be.undefined
138 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
143 after(async function () {
144 await cleanupTests([ server ])