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