]>
Commit | Line | Data |
---|---|---|
adcaf1a8 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
fdbda9e3 C |
3 | import 'mocha' |
4 | import * as chai from 'chai' | |
5d00a3d7 | 5 | import { VideoDetails } from '../../../shared/models/videos' |
23687332 C |
6 | import { waitJobs } from '../utils/server/jobs' |
7 | import { addVideoCommentThread } from '../utils/videos/video-comments' | |
fdbda9e3 | 8 | import { |
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 |
fdbda9e3 | 24 | } from '../utils' |
23687332 | 25 | import { getAccountsList } from '../utils/users/accounts' |
3cd0734f C |
26 | |
27 | const expect = chai.expect | |
fdbda9e3 C |
28 | |
29 | describe('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 = { | |
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) | |
3cd0734f C |
65 | |
66 | await waitJobs(server) | |
fdbda9e3 C |
67 | }) |
68 | ||
23687332 | 69 | it('Should run update host', async function () { |
e95561cd | 70 | this.timeout(30000) |
fdbda9e3 C |
71 | |
72 | killallServers([ server ]) | |
40298b02 C |
73 | // Run server with standard configuration |
74 | server = await runServer(2) | |
fdbda9e3 C |
75 | |
76 | const env = getEnvCli(server) | |
77 | await execCLI(`${env} npm run update-host`) | |
23687332 C |
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) | |
fdbda9e3 C |
116 | |
117 | const res = await getVideosList(server.url) | |
118 | const videos = res.body.data | |
40298b02 | 119 | expect(videos).to.have.lengthOf(2) |
fdbda9e3 | 120 | |
40298b02 | 121 | for (const video of videos) { |
5f04dd2f | 122 | const res2 = await getVideo(server.url, video.id) |
5d00a3d7 | 123 | const videoDetails: VideoDetails = res2.body |
fdbda9e3 | 124 | |
5f04dd2f C |
125 | expect(videoDetails.files).to.have.lengthOf(4) |
126 | ||
127 | for (const file of videoDetails.files) { | |
40298b02 C |
128 | expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket') |
129 | expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F') | |
fdbda9e3 | 130 | |
5d00a3d7 | 131 | const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id) |
adcaf1a8 C |
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 | ||
40298b02 C |
138 | expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed') |
139 | } | |
140 | } | |
fdbda9e3 C |
141 | }) |
142 | ||
143 | after(async function () { | |
144 | killallServers([ server ]) | |
fdbda9e3 C |
145 | }) |
146 | }) |