1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
9 makeActivityPubGetRequest,
13 setAccessTokensToServers,
15 } from '@shared/extra-utils'
17 describe('Test update host scripts', function () {
18 let server: ServerInfo
20 before(async function () {
23 const overrideConfig = {
28 // Run server 2 to have transcoding enabled
29 server = await flushAndRunServer(2, overrideConfig)
30 await setAccessTokensToServers([ server ])
32 // Upload two videos for our needs
33 const { uuid: video1UUID } = await server.videos.upload()
34 await server.videos.upload()
37 await server.users.create({ username: 'toto', password: 'coucou' })
40 const videoChannel = {
41 name: 'second_channel',
42 displayName: 'second video channel',
43 description: 'super video channel description'
45 await server.channels.create({ attributes: videoChannel })
48 const text = 'my super first comment'
49 await server.comments.createThread({ videoId: video1UUID, text })
51 await waitJobs(server)
54 it('Should run update host', async function () {
57 await killallServers([ server ])
58 // Run server with standard configuration
59 await reRunServer(server)
61 await server.cli.execWithEnv(`npm run update-host`)
64 it('Should have updated videos url', async function () {
65 const { total, data } = await server.videos.list()
66 expect(total).to.equal(2)
68 for (const video of data) {
69 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
71 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
73 const videoDetails = await server.videos.get({ id: video.uuid })
75 expect(videoDetails.trackerUrls[0]).to.include(server.host)
76 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
77 expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host)
81 it('Should have updated video channels url', async function () {
82 const { data, total } = await server.channels.list({ sort: '-name' })
83 expect(total).to.equal(3)
85 for (const channel of data) {
86 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
88 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
92 it('Should have updated accounts url', async function () {
93 const body = await server.accounts.list()
94 expect(body.total).to.equal(3)
96 for (const account of body.data) {
97 const usernameWithDomain = account.name
98 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
100 expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain)
104 it('Should have updated torrent hosts', async function () {
107 const { data } = await server.videos.list()
108 expect(data).to.have.lengthOf(2)
110 for (const video of data) {
111 const videoDetails = await server.videos.get({ id: video.id })
113 expect(videoDetails.files).to.have.lengthOf(4)
115 for (const file of videoDetails.files) {
116 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
117 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
119 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id)
120 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
121 expect(announceWS).to.not.be.undefined
123 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
124 expect(announceHttp).to.not.be.undefined
126 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
131 after(async function () {
132 await cleanupTests([ server ])