1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
9 makeActivityPubGetRequest,
12 setAccessTokensToServers,
14 } from '@shared/server-commands'
15 import { getAllFiles } from '../shared'
17 describe('Test update host scripts', function () {
18 let server: PeerTubeServer
20 before(async function () {
23 const overrideConfig = {
28 // Run server 2 to have transcoding enabled
29 server = await createSingleServer(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
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 })
112 const files = getAllFiles(videoDetails)
114 expect(files).to.have.lengthOf(8)
116 for (const file of files) {
117 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
118 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2F')
120 const torrent = await parseTorrentVideo(server, file)
121 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
122 expect(announceWS).to.not.be.undefined
124 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
125 expect(announceHttp).to.not.be.undefined
127 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/')
132 after(async function () {
133 await cleanupTests([ server ])