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