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