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