]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
adcaf1a8 | 2 | |
fdbda9e3 | 3 | import 'mocha' |
078f17e6 | 4 | import { expect } from 'chai' |
fdbda9e3 | 5 | import { |
7c3b7976 | 6 | cleanupTests, |
7c3b7976 | 7 | flushAndRunServer, |
3cd0734f | 8 | getVideo, |
fdbda9e3 C |
9 | getVideosList, |
10 | killallServers, | |
23687332 | 11 | makeActivityPubGetRequest, |
329619b3 C |
12 | parseTorrentVideo, |
13 | reRunServer, | |
fdbda9e3 C |
14 | ServerInfo, |
15 | setAccessTokensToServers, | |
9fff08cf C |
16 | uploadVideo, |
17 | waitJobs | |
18 | } from '@shared/extra-utils' | |
19 | import { VideoDetails } from '@shared/models' | |
3cd0734f | 20 | |
fdbda9e3 C |
21 | describe('Test update host scripts', function () { |
22 | let server: ServerInfo | |
23 | ||
24 | before(async function () { | |
40298b02 | 25 | this.timeout(60000) |
fdbda9e3 | 26 | |
fdbda9e3 C |
27 | const overrideConfig = { |
28 | webserver: { | |
29 | port: 9256 | |
30 | } | |
31 | } | |
40298b02 | 32 | // Run server 2 to have transcoding enabled |
210feb6c | 33 | server = await flushAndRunServer(2, overrideConfig) |
fdbda9e3 C |
34 | await setAccessTokensToServers([ server ]) |
35 | ||
36 | // Upload two videos for our needs | |
37 | const videoAttributes = {} | |
23687332 C |
38 | const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes) |
39 | const video1UUID = resVideo1.body.video.uuid | |
fdbda9e3 | 40 | await uploadVideo(server.url, server.accessToken, videoAttributes) |
23687332 C |
41 | |
42 | // Create a user | |
7926c5f9 | 43 | await server.usersCommand.create({ username: 'toto', password: 'coucou' }) |
23687332 C |
44 | |
45 | // Create channel | |
46 | const videoChannel = { | |
8a19bee1 | 47 | name: 'second_channel', |
23687332 C |
48 | displayName: 'second video channel', |
49 | description: 'super video channel description' | |
50 | } | |
a5461888 | 51 | await server.channelsCommand.create({ attributes: videoChannel }) |
23687332 C |
52 | |
53 | // Create comments | |
54 | const text = 'my super first comment' | |
12edc149 | 55 | await server.commentsCommand.createThread({ videoId: video1UUID, text }) |
3cd0734f C |
56 | |
57 | await waitJobs(server) | |
fdbda9e3 C |
58 | }) |
59 | ||
23687332 | 60 | it('Should run update host', async function () { |
e95561cd | 61 | this.timeout(30000) |
fdbda9e3 | 62 | |
9293139f | 63 | await killallServers([ server ]) |
40298b02 | 64 | // Run server with standard configuration |
7c3b7976 | 65 | await reRunServer(server) |
fdbda9e3 | 66 | |
329619b3 | 67 | await server.cliCommand.execWithEnv(`npm run update-host`) |
23687332 C |
68 | }) |
69 | ||
70 | it('Should have updated videos url', async function () { | |
71 | const res = await getVideosList(server.url) | |
72 | expect(res.body.total).to.equal(2) | |
73 | ||
74 | for (const video of res.body.data) { | |
75 | const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid) | |
76 | ||
77 | expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid) | |
09209296 C |
78 | |
79 | const res = await getVideo(server.url, video.uuid) | |
80 | const videoDetails: VideoDetails = res.body | |
81 | ||
82 | expect(videoDetails.trackerUrls[0]).to.include(server.host) | |
83 | expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host) | |
84 | expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host) | |
23687332 C |
85 | } |
86 | }) | |
87 | ||
88 | it('Should have updated video channels url', async function () { | |
a5461888 C |
89 | const { data, total } = await server.channelsCommand.list({ sort: '-name' }) |
90 | expect(total).to.equal(3) | |
23687332 | 91 | |
a5461888 | 92 | for (const channel of data) { |
240085d0 | 93 | const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name) |
23687332 | 94 | |
240085d0 | 95 | expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name) |
23687332 C |
96 | } |
97 | }) | |
98 | ||
09209296 | 99 | it('Should have updated accounts url', async function () { |
9fff08cf C |
100 | const body = await server.accountsCommand.list() |
101 | expect(body.total).to.equal(3) | |
23687332 | 102 | |
9fff08cf | 103 | for (const account of body.data) { |
23687332 C |
104 | const usernameWithDomain = account.name |
105 | const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain) | |
106 | ||
107 | expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain) | |
108 | } | |
109 | }) | |
110 | ||
09209296 | 111 | it('Should have updated torrent hosts', async function () { |
23687332 | 112 | this.timeout(30000) |
fdbda9e3 C |
113 | |
114 | const res = await getVideosList(server.url) | |
115 | const videos = res.body.data | |
40298b02 | 116 | expect(videos).to.have.lengthOf(2) |
fdbda9e3 | 117 | |
40298b02 | 118 | for (const video of videos) { |
5f04dd2f | 119 | const res2 = await getVideo(server.url, video.id) |
5d00a3d7 | 120 | const videoDetails: VideoDetails = res2.body |
fdbda9e3 | 121 | |
5f04dd2f C |
122 | expect(videoDetails.files).to.have.lengthOf(4) |
123 | ||
124 | for (const file of videoDetails.files) { | |
40298b02 C |
125 | expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket') |
126 | expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F') | |
fdbda9e3 | 127 | |
5d00a3d7 | 128 | const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution.id) |
adcaf1a8 C |
129 | const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket') |
130 | expect(announceWS).to.not.be.undefined | |
131 | ||
132 | const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce') | |
133 | expect(announceHttp).to.not.be.undefined | |
134 | ||
40298b02 C |
135 | expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed') |
136 | } | |
137 | } | |
fdbda9e3 C |
138 | }) |
139 | ||
7c3b7976 C |
140 | after(async function () { |
141 | await cleanupTests([ server ]) | |
fdbda9e3 C |
142 | }) |
143 | }) |