1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { getAllFiles } from '@shared/core-utils'
9 makeActivityPubGetRequest,
11 setAccessTokensToServers,
13 } from '@shared/server-commands'
14 import { parseTorrentVideo } from '../shared'
16 describe('Test update host scripts', function () {
17 let server: PeerTubeServer
19 before(async function () {
22 const overrideConfig = {
27 // Run server 2 to have transcoding enabled
28 server = await createSingleServer(2, overrideConfig)
29 await setAccessTokensToServers([ server ])
31 // Upload two videos for our needs
32 const { uuid: video1UUID } = await server.videos.upload()
33 await server.videos.upload()
36 await server.users.create({ username: 'toto', password: 'coucou' })
39 const videoChannel = {
40 name: 'second_channel',
41 displayName: 'second video channel',
42 description: 'super video channel description'
44 await server.channels.create({ attributes: videoChannel })
47 const text = 'my super first comment'
48 await server.comments.createThread({ videoId: video1UUID, text })
50 await waitJobs(server)
53 it('Should run update host', async function () {
56 await killallServers([ server ])
57 // Run server with standard configuration
60 await server.cli.execWithEnv(`npm run update-host`)
63 it('Should have updated videos url', async function () {
64 const { total, data } = await server.videos.list()
65 expect(total).to.equal(2)
67 for (const video of data) {
68 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
70 expect(body.id).to.equal('http://127.0.0.1:9002/videos/watch/' + video.uuid)
72 const videoDetails = await server.videos.get({ id: video.uuid })
74 expect(videoDetails.trackerUrls[0]).to.include(server.host)
75 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
76 expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host)
80 it('Should have updated video channels url', async function () {
81 const { data, total } = await server.channels.list({ sort: '-name' })
82 expect(total).to.equal(3)
84 for (const channel of data) {
85 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
87 expect(body.id).to.equal('http://127.0.0.1:9002/video-channels/' + channel.name)
91 it('Should have updated accounts url', async function () {
92 const body = await server.accounts.list()
93 expect(body.total).to.equal(3)
95 for (const account of body.data) {
96 const usernameWithDomain = account.name
97 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
99 expect(body.id).to.equal('http://127.0.0.1:9002/accounts/' + usernameWithDomain)
103 it('Should have updated torrent hosts', async function () {
106 const { data } = await server.videos.list()
107 expect(data).to.have.lengthOf(2)
109 for (const video of data) {
110 const videoDetails = await server.videos.get({ id: video.id })
111 const files = getAllFiles(videoDetails)
113 expect(files).to.have.lengthOf(8)
115 for (const file of files) {
116 expect(file.magnetUri).to.contain('127.0.0.1%3A9002%2Ftracker%2Fsocket')
117 expect(file.magnetUri).to.contain('127.0.0.1%3A9002%2Fstatic%2F')
119 const torrent = await parseTorrentVideo(server, file)
120 const announceWS = torrent.announce.find(a => a === 'ws://127.0.0.1:9002/tracker/socket')
121 expect(announceWS).to.not.be.undefined
123 const announceHttp = torrent.announce.find(a => a === 'http://127.0.0.1:9002/tracker/announce')
124 expect(announceHttp).to.not.be.undefined
126 expect(torrent.urlList[0]).to.contain('http://127.0.0.1:9002/static/')
131 after(async function () {
132 await cleanupTests([ server ])