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