]>
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 '../utils/server/jobs' | |
7 | import { addVideoCommentThread } from '../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 '../utils' | |
25 | import { getAccountsList } from '../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 | displayName: 'second video channel', | |
58 | description: 'super video channel description' | |
59 | } | |
60 | await addVideoChannel(server.url, server.accessToken, videoChannel) | |
61 | ||
62 | // Create comments | |
63 | const text = 'my super first comment' | |
64 | await addVideoCommentThread(server.url, server.accessToken, video1UUID, text) | |
65 | ||
66 | await waitJobs(server) | |
67 | }) | |
68 | ||
69 | it('Should run update host', async function () { | |
70 | this.timeout(30000) | |
71 | ||
72 | killallServers([ server ]) | |
73 | // Run server with standard configuration | |
74 | server = await runServer(2) | |
75 | ||
76 | const env = getEnvCli(server) | |
77 | await execCLI(`${env} npm run update-host`) | |
78 | }) | |
79 | ||
80 | it('Should have updated videos url', async function () { | |
81 | const res = await getVideosList(server.url) | |
82 | expect(res.body.total).to.equal(2) | |
83 | ||
84 | for (const video of res.body.data) { | |
85 | const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid) | |
86 | ||
87 | expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid) | |
88 | } | |
89 | }) | |
90 | ||
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) | |
94 | ||
95 | for (const channel of res.body.data) { | |
96 | const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.uuid) | |
97 | ||
98 | expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.uuid) | |
99 | } | |
100 | }) | |
101 | ||
102 | it('Should have update accounts url', async function () { | |
103 | const res = await getAccountsList(server.url) | |
104 | expect(res.body.total).to.equal(3) | |
105 | ||
106 | for (const account of res.body.data) { | |
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 | ||
114 | it('Should update torrent hosts', async function () { | |
115 | this.timeout(30000) | |
116 | ||
117 | const res = await getVideosList(server.url) | |
118 | const videos = res.body.data | |
119 | expect(videos).to.have.lengthOf(2) | |
120 | ||
121 | for (const video of videos) { | |
122 | const res2 = await getVideo(server.url, video.id) | |
123 | const videoDetails: VideoDetails = res2.body | |
124 | ||
125 | expect(videoDetails.files).to.have.lengthOf(4) | |
126 | ||
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') | |
130 | ||
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 | |
134 | ||
135 | const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce') | |
136 | expect(announceHttp).to.not.be.undefined | |
137 | ||
138 | expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed') | |
139 | } | |
140 | } | |
141 | }) | |
142 | ||
143 | after(async function () { | |
144 | killallServers([ server ]) | |
145 | }) | |
146 | }) |