]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/update-host.ts
Add runner server tests
[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
078f17e6 3import { expect } from 'chai'
367a9dc6 4import { getAllFiles } from '@shared/core-utils'
fdbda9e3 5import {
7c3b7976 6 cleanupTests,
254d3579 7 createSingleServer,
fdbda9e3 8 killallServers,
23687332 9 makeActivityPubGetRequest,
254d3579 10 PeerTubeServer,
fdbda9e3 11 setAccessTokensToServers,
9fff08cf 12 waitJobs
bf54587a 13} from '@shared/server-commands'
d102de1b 14import { parseTorrentVideo } from '../shared'
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
2732eeff 70 expect(body.id).to.equal('http://127.0.0.1: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
2732eeff 87 expect(body.id).to.equal('http://127.0.0.1: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
2732eeff 99 expect(body.id).to.equal('http://127.0.0.1:9002/accounts/' + usernameWithDomain)
23687332
C
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 })
c729caf6 111 const files = getAllFiles(videoDetails)
fdbda9e3 112
764b1a14 113 expect(files).to.have.lengthOf(8)
5f04dd2f 114
764b1a14 115 for (const file of files) {
2732eeff
C
116 expect(file.magnetUri).to.contain('127.0.0.1%3A9002%2Ftracker%2Fsocket')
117 expect(file.magnetUri).to.contain('127.0.0.1%3A9002%2Fstatic%2F')
fdbda9e3 118
764b1a14 119 const torrent = await parseTorrentVideo(server, file)
2732eeff 120 const announceWS = torrent.announce.find(a => a === 'ws://127.0.0.1:9002/tracker/socket')
adcaf1a8
C
121 expect(announceWS).to.not.be.undefined
122
2732eeff 123 const announceHttp = torrent.announce.find(a => a === 'http://127.0.0.1:9002/tracker/announce')
adcaf1a8
C
124 expect(announceHttp).to.not.be.undefined
125
2732eeff 126 expect(torrent.urlList[0]).to.contain('http://127.0.0.1:9002/static/')
40298b02
C
127 }
128 }
fdbda9e3
C
129 })
130
7c3b7976
C
131 after(async function () {
132 await cleanupTests([ server ])
fdbda9e3
C
133 })
134})