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