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