]>
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, |
254d3579 | 7 | createSingleServer, |
fdbda9e3 | 8 | killallServers, |
23687332 | 9 | makeActivityPubGetRequest, |
329619b3 | 10 | parseTorrentVideo, |
254d3579 | 11 | PeerTubeServer, |
fdbda9e3 | 12 | setAccessTokensToServers, |
9fff08cf | 13 | waitJobs |
bf54587a | 14 | } from '@shared/server-commands' |
c729caf6 | 15 | import { getAllFiles } from '../shared' |
3cd0734f | 16 | |
fdbda9e3 | 17 | describe('Test update host scripts', function () { |
254d3579 | 18 | let server: PeerTubeServer |
fdbda9e3 C |
19 | |
20 | before(async function () { | |
40298b02 | 21 | this.timeout(60000) |
fdbda9e3 | 22 | |
fdbda9e3 C |
23 | const overrideConfig = { |
24 | webserver: { | |
25 | port: 9256 | |
26 | } | |
27 | } | |
40298b02 | 28 | // Run server 2 to have transcoding enabled |
254d3579 | 29 | server = await createSingleServer(2, overrideConfig) |
fdbda9e3 C |
30 | await setAccessTokensToServers([ server ]) |
31 | ||
32 | // Upload two videos for our needs | |
89d241a7 C |
33 | const { uuid: video1UUID } = await server.videos.upload() |
34 | await server.videos.upload() | |
23687332 C |
35 | |
36 | // Create a user | |
89d241a7 | 37 | await server.users.create({ username: 'toto', password: 'coucou' }) |
23687332 C |
38 | |
39 | // Create channel | |
40 | const videoChannel = { | |
8a19bee1 | 41 | name: 'second_channel', |
23687332 C |
42 | displayName: 'second video channel', |
43 | description: 'super video channel description' | |
44 | } | |
89d241a7 | 45 | await server.channels.create({ attributes: videoChannel }) |
23687332 C |
46 | |
47 | // Create comments | |
48 | const text = 'my super first comment' | |
89d241a7 | 49 | await server.comments.createThread({ videoId: video1UUID, text }) |
3cd0734f C |
50 | |
51 | await waitJobs(server) | |
fdbda9e3 C |
52 | }) |
53 | ||
23687332 | 54 | it('Should run update host', async function () { |
e95561cd | 55 | this.timeout(30000) |
fdbda9e3 | 56 | |
9293139f | 57 | await killallServers([ server ]) |
40298b02 | 58 | // Run server with standard configuration |
254d3579 | 59 | await server.run() |
fdbda9e3 | 60 | |
89d241a7 | 61 | await server.cli.execWithEnv(`npm run update-host`) |
23687332 C |
62 | }) |
63 | ||
64 | it('Should have updated videos url', async function () { | |
89d241a7 | 65 | const { total, data } = await server.videos.list() |
d23dd9fb | 66 | expect(total).to.equal(2) |
23687332 | 67 | |
d23dd9fb | 68 | for (const video of data) { |
23687332 C |
69 | const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid) |
70 | ||
71 | expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid) | |
09209296 | 72 | |
89d241a7 | 73 | const videoDetails = await server.videos.get({ id: video.uuid }) |
09209296 C |
74 | |
75 | expect(videoDetails.trackerUrls[0]).to.include(server.host) | |
76 | expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host) | |
77 | expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host) | |
23687332 C |
78 | } |
79 | }) | |
80 | ||
81 | it('Should have updated video channels url', async function () { | |
89d241a7 | 82 | const { data, total } = await server.channels.list({ sort: '-name' }) |
a5461888 | 83 | expect(total).to.equal(3) |
23687332 | 84 | |
a5461888 | 85 | for (const channel of data) { |
240085d0 | 86 | const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name) |
23687332 | 87 | |
240085d0 | 88 | expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name) |
23687332 C |
89 | } |
90 | }) | |
91 | ||
09209296 | 92 | it('Should have updated accounts url', async function () { |
89d241a7 | 93 | const body = await server.accounts.list() |
9fff08cf | 94 | expect(body.total).to.equal(3) |
23687332 | 95 | |
9fff08cf | 96 | for (const account of body.data) { |
23687332 C |
97 | const usernameWithDomain = account.name |
98 | const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain) | |
99 | ||
100 | expect(body.id).to.equal('http://localhost:9002/accounts/' + usernameWithDomain) | |
101 | } | |
102 | }) | |
103 | ||
09209296 | 104 | it('Should have updated torrent hosts', async function () { |
23687332 | 105 | this.timeout(30000) |
fdbda9e3 | 106 | |
89d241a7 | 107 | const { data } = await server.videos.list() |
d23dd9fb | 108 | expect(data).to.have.lengthOf(2) |
fdbda9e3 | 109 | |
d23dd9fb | 110 | for (const video of data) { |
89d241a7 | 111 | const videoDetails = await server.videos.get({ id: video.id }) |
c729caf6 | 112 | const files = getAllFiles(videoDetails) |
fdbda9e3 | 113 | |
764b1a14 | 114 | expect(files).to.have.lengthOf(8) |
5f04dd2f | 115 | |
764b1a14 | 116 | for (const file of files) { |
40298b02 | 117 | expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket') |
764b1a14 | 118 | expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2F') |
fdbda9e3 | 119 | |
764b1a14 | 120 | const torrent = await parseTorrentVideo(server, file) |
adcaf1a8 C |
121 | const announceWS = torrent.announce.find(a => a === 'ws://localhost:9002/tracker/socket') |
122 | expect(announceWS).to.not.be.undefined | |
123 | ||
124 | const announceHttp = torrent.announce.find(a => a === 'http://localhost:9002/tracker/announce') | |
125 | expect(announceHttp).to.not.be.undefined | |
126 | ||
764b1a14 | 127 | expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/') |
40298b02 C |
128 | } |
129 | } | |
fdbda9e3 C |
130 | }) |
131 | ||
7c3b7976 C |
132 | after(async function () { |
133 | await cleanupTests([ server ]) | |
fdbda9e3 C |
134 | }) |
135 | }) |