]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/update-host.ts
Move plugin blocklist mock
[github/Chocobozzz/PeerTube.git] / server / tests / cli / update-host.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
adcaf1a8 2
fdbda9e3
C
3import 'mocha'
4import * as chai from 'chai'
fdbda9e3 5import {
23687332 6 addVideoChannel,
7c3b7976 7 cleanupTests,
23687332 8 createUser,
7c3b7976 9 flushAndRunServer,
3cd0734f 10 getVideo,
23687332 11 getVideoChannelsList,
fdbda9e3
C
12 getVideosList,
13 killallServers,
23687332 14 makeActivityPubGetRequest,
329619b3
C
15 parseTorrentVideo,
16 reRunServer,
fdbda9e3
C
17 ServerInfo,
18 setAccessTokensToServers,
3cd0734f 19 uploadVideo
94565d52 20} from '../../../shared/extra-utils'
329619b3 21import { waitJobs } from '../../../shared/extra-utils/server/jobs'
94565d52 22import { getAccountsList } from '../../../shared/extra-utils/users/accounts'
329619b3
C
23import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
24import { VideoDetails } from '../../../shared/models/videos'
3cd0734f
C
25
26const expect = chai.expect
fdbda9e3
C
27
28describe('Test update host scripts', function () {
29 let server: ServerInfo
30
31 before(async function () {
40298b02 32 this.timeout(60000)
fdbda9e3 33
fdbda9e3
C
34 const overrideConfig = {
35 webserver: {
36 port: 9256
37 }
38 }
40298b02 39 // Run server 2 to have transcoding enabled
210feb6c 40 server = await flushAndRunServer(2, overrideConfig)
fdbda9e3
C
41 await setAccessTokensToServers([ server ])
42
43 // Upload two videos for our needs
44 const videoAttributes = {}
23687332
C
45 const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes)
46 const video1UUID = resVideo1.body.video.uuid
fdbda9e3 47 await uploadVideo(server.url, server.accessToken, videoAttributes)
23687332
C
48
49 // Create a user
1eddc9a7 50 await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' })
23687332
C
51
52 // Create channel
53 const videoChannel = {
8a19bee1 54 name: 'second_channel',
23687332
C
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)
3cd0734f
C
63
64 await waitJobs(server)
fdbda9e3
C
65 })
66
23687332 67 it('Should run update host', async function () {
e95561cd 68 this.timeout(30000)
fdbda9e3
C
69
70 killallServers([ server ])
40298b02 71 // Run server with standard configuration
7c3b7976 72 await reRunServer(server)
fdbda9e3 73
329619b3 74 await server.cliCommand.execWithEnv(`npm run update-host`)
23687332
C
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)
09209296
C
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)
23687332
C
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) {
240085d0 100 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
23687332 101
240085d0 102 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
23687332
C
103 }
104 })
105
09209296 106 it('Should have updated accounts url', async function () {
23687332
C
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
09209296 118 it('Should have updated torrent hosts', async function () {
23687332 119 this.timeout(30000)
fdbda9e3
C
120
121 const res = await getVideosList(server.url)
122 const videos = res.body.data
40298b02 123 expect(videos).to.have.lengthOf(2)
fdbda9e3 124
40298b02 125 for (const video of videos) {
5f04dd2f 126 const res2 = await getVideo(server.url, video.id)
5d00a3d7 127 const videoDetails: VideoDetails = res2.body
fdbda9e3 128
5f04dd2f
C
129 expect(videoDetails.files).to.have.lengthOf(4)
130
131 for (const file of videoDetails.files) {
40298b02
C
132 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
133 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
fdbda9e3 134
5d00a3d7 135 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id)
adcaf1a8
C
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
40298b02
C
142 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
143 }
144 }
fdbda9e3
C
145 })
146
7c3b7976
C
147 after(async function () {
148 await cleanupTests([ server ])
fdbda9e3
C
149 })
150})