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