aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/tests/src/cli/update-host.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/tests/src/cli/update-host.ts')
-rw-r--r--packages/tests/src/cli/update-host.ts134
1 files changed, 134 insertions, 0 deletions
diff --git a/packages/tests/src/cli/update-host.ts b/packages/tests/src/cli/update-host.ts
new file mode 100644
index 000000000..e5f165e5e
--- /dev/null
+++ b/packages/tests/src/cli/update-host.ts
@@ -0,0 +1,134 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { getAllFiles } from '@peertube/peertube-core-utils'
5import {
6 cleanupTests,
7 createSingleServer,
8 killallServers,
9 makeActivityPubGetRequest,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 waitJobs
13} from '@peertube/peertube-server-commands'
14import { parseTorrentVideo } from '@tests/shared/webtorrent.js'
15
16describe('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://127.0.0.1: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://127.0.0.1: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://127.0.0.1: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 const files = getAllFiles(videoDetails)
112
113 expect(files).to.have.lengthOf(8)
114
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')
118
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
122
123 const announceHttp = torrent.announce.find(a => a === 'http://127.0.0.1:9002/tracker/announce')
124 expect(announceHttp).to.not.be.undefined
125
126 expect(torrent.urlList[0]).to.contain('http://127.0.0.1:9002/static/')
127 }
128 }
129 })
130
131 after(async function () {
132 await cleanupTests([ server ])
133 })
134})