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