]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/update-host.ts
Use an object to represent a server
[github/Chocobozzz/PeerTube.git] / server / tests / cli / update-host.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import { expect } from 'chai'
5 import {
6 cleanupTests,
7 createSingleServer,
8 killallServers,
9 makeActivityPubGetRequest,
10 parseTorrentVideo,
11 PeerTubeServer,
12 setAccessTokensToServers,
13 waitJobs
14 } from '@shared/extra-utils'
15
16 describe('Test update host scripts', function () {
17 let server: PeerTubeServer
18
19 before(async function () {
20 this.timeout(60000)
21
22 const overrideConfig = {
23 webserver: {
24 port: 9256
25 }
26 }
27 // Run server 2 to have transcoding enabled
28 server = await createSingleServer(2, overrideConfig)
29 await setAccessTokensToServers([ server ])
30
31 // Upload two videos for our needs
32 const { uuid: video1UUID } = await server.videos.upload()
33 await server.videos.upload()
34
35 // Create a user
36 await server.users.create({ username: 'toto', password: 'coucou' })
37
38 // Create channel
39 const videoChannel = {
40 name: 'second_channel',
41 displayName: 'second video channel',
42 description: 'super video channel description'
43 }
44 await server.channels.create({ attributes: videoChannel })
45
46 // Create comments
47 const text = 'my super first comment'
48 await server.comments.createThread({ videoId: video1UUID, text })
49
50 await waitJobs(server)
51 })
52
53 it('Should run update host', async function () {
54 this.timeout(30000)
55
56 await killallServers([ server ])
57 // Run server with standard configuration
58 await server.run()
59
60 await server.cli.execWithEnv(`npm run update-host`)
61 })
62
63 it('Should have updated videos url', async function () {
64 const { total, data } = await server.videos.list()
65 expect(total).to.equal(2)
66
67 for (const video of data) {
68 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
69
70 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
71
72 const videoDetails = await server.videos.get({ id: video.uuid })
73
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)
77 }
78 })
79
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)
83
84 for (const channel of data) {
85 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
86
87 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
88 }
89 })
90
91 it('Should have updated accounts url', async function () {
92 const body = await server.accounts.list()
93 expect(body.total).to.equal(3)
94
95 for (const account of body.data) {
96 const usernameWithDomain = account.name
97 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
98
99 expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain)
100 }
101 })
102
103 it('Should have updated torrent hosts', async function () {
104 this.timeout(30000)
105
106 const { data } = await server.videos.list()
107 expect(data).to.have.lengthOf(2)
108
109 for (const video of data) {
110 const videoDetails = await server.videos.get({ id: video.id })
111
112 expect(videoDetails.files).to.have.lengthOf(4)
113
114 for (const file of videoDetails.files) {
115 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
116 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
117
118 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id)
119 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
120 expect(announceWS).to.not.be.undefined
121
122 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
123 expect(announceHttp).to.not.be.undefined
124
125 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
126 }
127 }
128 })
129
130 after(async function () {
131 await cleanupTests([ server ])
132 })
133 })