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