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