]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { VideoDetails } from '../../../shared/models/videos' | |
6 | import { waitJobs } from '../../../shared/utils/server/jobs' | |
7 | import { addVideoCommentThread } from '../../../shared/utils/videos/video-comments' | |
8 | import { | |
9 | addVideoChannel, | |
10 | createUser, | |
11 | execCLI, | |
12 | flushTests, | |
13 | getEnvCli, | |
14 | getVideo, | |
15 | getVideoChannelsList, | |
16 | getVideosList, | |
17 | killallServers, | |
18 | makeActivityPubGetRequest, | |
19 | parseTorrentVideo, | |
20 | runServer, | |
21 | ServerInfo, | |
22 | setAccessTokensToServers, | |
23 | uploadVideo | |
24 | } from '../../../shared/utils' | |
25 | import { getAccountsList } from '../../../shared/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 | await flushTests() | |
36 | ||
37 | const overrideConfig = { | |
38 | webserver: { | |
39 | port: 9256 | |
40 | } | |
41 | } | |
42 | // Run server 2 to have transcoding enabled | |
43 | server = await runServer(2, overrideConfig) | |
44 | await setAccessTokensToServers([ server ]) | |
45 | ||
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) | |
51 | ||
52 | // Create a user | |
53 | await createUser(server.url, server.accessToken, 'toto', 'coucou') | |
54 | ||
55 | // Create channel | |
56 | const videoChannel = { | |
57 | name: 'second_channel', | |
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) | |
66 | ||
67 | await waitJobs(server) | |
68 | }) | |
69 | ||
70 | it('Should run update host', async function () { | |
71 | this.timeout(30000) | |
72 | ||
73 | killallServers([ server ]) | |
74 | // Run server with standard configuration | |
75 | server = await runServer(2) | |
76 | ||
77 | const env = getEnvCli(server) | |
78 | await execCLI(`${env} npm run update-host`) | |
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) { | |
97 | const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name) | |
98 | ||
99 | expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name) | |
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) | |
117 | ||
118 | const res = await getVideosList(server.url) | |
119 | const videos = res.body.data | |
120 | expect(videos).to.have.lengthOf(2) | |
121 | ||
122 | for (const video of videos) { | |
123 | const res2 = await getVideo(server.url, video.id) | |
124 | const videoDetails: VideoDetails = res2.body | |
125 | ||
126 | expect(videoDetails.files).to.have.lengthOf(4) | |
127 | ||
128 | for (const file of videoDetails.files) { | |
129 | expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket') | |
130 | expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F') | |
131 | ||
132 | const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id) | |
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 | ||
139 | expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed') | |
140 | } | |
141 | } | |
142 | }) | |
143 | ||
144 | after(async function () { | |
145 | killallServers([ server ]) | |
146 | }) | |
147 | }) |