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