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