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