1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
5 import { VideoDetails } from '../../../shared/models/videos'
6 import { waitJobs } from '../utils/server/jobs'
7 import { addVideoCommentThread } from '../utils/videos/video-comments'
18 makeActivityPubGetRequest,
22 setAccessTokensToServers,
25 import { getAccountsList } from '../utils/users/accounts'
27 const expect = chai.expect
29 describe('Test update host scripts', function () {
30 let server: ServerInfo
32 before(async function () {
37 const overrideConfig = {
42 // Run server 2 to have transcoding enabled
43 server = await runServer(2, overrideConfig)
44 await setAccessTokensToServers([ server ])
46 // Upload two videos for our needs
47 const videoAttributes = {}
48 const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes)
49 const video1UUID = resVideo1.body.video.uuid
50 await uploadVideo(server.url, server.accessToken, videoAttributes)
53 await createUser(server.url, server.accessToken, 'toto', 'coucou')
56 const videoChannel = {
57 displayName: 'second video channel',
58 description: 'super video channel description'
60 await addVideoChannel(server.url, server.accessToken, videoChannel)
63 const text = 'my super first comment'
64 await addVideoCommentThread(server.url, server.accessToken, video1UUID, text)
66 await waitJobs(server)
69 it('Should run update host', async function () {
72 killallServers([ server ])
73 // Run server with standard configuration
74 server = await runServer(2)
76 const env = getEnvCli(server)
77 await execCLI(`${env} npm run update-host`)
80 it('Should have updated videos url', async function () {
81 const res = await getVideosList(server.url)
82 expect(res.body.total).to.equal(2)
84 for (const video of res.body.data) {
85 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
87 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
91 it('Should have updated video channels url', async function () {
92 const res = await getVideoChannelsList(server.url, 0, 5, '-name')
93 expect(res.body.total).to.equal(3)
95 for (const channel of res.body.data) {
96 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.uuid)
98 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.uuid)
102 it('Should have update accounts url', async function () {
103 const res = await getAccountsList(server.url)
104 expect(res.body.total).to.equal(3)
106 for (const account of res.body.data) {
107 const usernameWithDomain = account.name
108 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
110 expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain)
114 it('Should update torrent hosts', async function () {
117 const res = await getVideosList(server.url)
118 const videos = res.body.data
119 expect(videos).to.have.lengthOf(2)
121 for (const video of videos) {
122 const res2 = await getVideo(server.url, video.id)
123 const videoDetails: VideoDetails = res2.body
125 expect(videoDetails.files).to.have.lengthOf(4)
127 for (const file of videoDetails.files) {
128 expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')
129 expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')
131 const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id)
132 const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket')
133 expect(announceWS).to.not.be.undefined
135 const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce')
136 expect(announceHttp).to.not.be.undefined
138 expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')
143 after(async function () {
144 killallServers([ server ])