]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { expect } from 'chai' | |
5 | import { | |
6 | cleanupTests, | |
7 | createSingleServer, | |
8 | killallServers, | |
9 | makeActivityPubGetRequest, | |
10 | parseTorrentVideo, | |
11 | PeerTubeServer, | |
12 | setAccessTokensToServers, | |
13 | waitJobs | |
14 | } from '@shared/server-commands' | |
15 | import { getAllFiles } from '../shared' | |
16 | ||
17 | describe('Test update host scripts', function () { | |
18 | let server: PeerTubeServer | |
19 | ||
20 | before(async function () { | |
21 | this.timeout(60000) | |
22 | ||
23 | const overrideConfig = { | |
24 | webserver: { | |
25 | port: 9256 | |
26 | } | |
27 | } | |
28 | // Run server 2 to have transcoding enabled | |
29 | server = await createSingleServer(2, overrideConfig) | |
30 | await setAccessTokensToServers([ server ]) | |
31 | ||
32 | // Upload two videos for our needs | |
33 | const { uuid: video1UUID } = await server.videos.upload() | |
34 | await server.videos.upload() | |
35 | ||
36 | // Create a user | |
37 | await server.users.create({ username: 'toto', password: 'coucou' }) | |
38 | ||
39 | // Create channel | |
40 | const videoChannel = { | |
41 | name: 'second_channel', | |
42 | displayName: 'second video channel', | |
43 | description: 'super video channel description' | |
44 | } | |
45 | await server.channels.create({ attributes: videoChannel }) | |
46 | ||
47 | // Create comments | |
48 | const text = 'my super first comment' | |
49 | await server.comments.createThread({ videoId: video1UUID, text }) | |
50 | ||
51 | await waitJobs(server) | |
52 | }) | |
53 | ||
54 | it('Should run update host', async function () { | |
55 | this.timeout(30000) | |
56 | ||
57 | await killallServers([ server ]) | |
58 | // Run server with standard configuration | |
59 | await server.run() | |
60 | ||
61 | await server.cli.execWithEnv(`npm run update-host`) | |
62 | }) | |
63 | ||
64 | it('Should have updated videos url', async function () { | |
65 | const { total, data } = await server.videos.list() | |
66 | expect(total).to.equal(2) | |
67 | ||
68 | for (const video of data) { | |
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) | |
72 | ||
73 | const videoDetails = await server.videos.get({ id: video.uuid }) | |
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) | |
78 | } | |
79 | }) | |
80 | ||
81 | it('Should have updated video channels url', async function () { | |
82 | const { data, total } = await server.channels.list({ sort: '-name' }) | |
83 | expect(total).to.equal(3) | |
84 | ||
85 | for (const channel of data) { | |
86 | const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name) | |
87 | ||
88 | expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name) | |
89 | } | |
90 | }) | |
91 | ||
92 | it('Should have updated accounts url', async function () { | |
93 | const body = await server.accounts.list() | |
94 | expect(body.total).to.equal(3) | |
95 | ||
96 | for (const account of body.data) { | |
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 | ||
104 | it('Should have updated torrent hosts', async function () { | |
105 | this.timeout(30000) | |
106 | ||
107 | const { data } = await server.videos.list() | |
108 | expect(data).to.have.lengthOf(2) | |
109 | ||
110 | for (const video of data) { | |
111 | const videoDetails = await server.videos.get({ id: video.id }) | |
112 | const files = getAllFiles(videoDetails) | |
113 | ||
114 | expect(files).to.have.lengthOf(8) | |
115 | ||
116 | for (const file of files) { | |
117 | expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket') | |
118 | expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2F') | |
119 | ||
120 | const torrent = await parseTorrentVideo(server, file) | |
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 | ||
127 | expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/') | |
128 | } | |
129 | } | |
130 | }) | |
131 | ||
132 | after(async function () { | |
133 | await cleanupTests([ server ]) | |
134 | }) | |
135 | }) |