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