]>
Commit | Line | Data |
---|---|---|
1b05d82d C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
1b05d82d | 3 | import 'mocha' |
ab3ead3a C |
4 | import { |
5 | checkVideoFilesWereRemoved, | |
80fdaf06 | 6 | doubleFollow, |
ab3ead3a C |
7 | getPluginTestPath, |
8 | getVideo, | |
9 | installPlugin, | |
80fdaf06 | 10 | makePostBodyRequest, |
ab3ead3a C |
11 | setAccessTokensToServers, |
12 | uploadVideoAndGetId, | |
80fdaf06 C |
13 | viewVideo, |
14 | getVideosList, | |
22820226 C |
15 | waitJobs, |
16 | makeGetRequest | |
ab3ead3a | 17 | } from '../../../shared/extra-utils' |
80fdaf06 C |
18 | import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' |
19 | import { expect } from 'chai' | |
2d53be02 | 20 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
80fdaf06 C |
21 | |
22 | function postCommand (server: ServerInfo, command: string, bodyArg?: object) { | |
23 | const body = { command } | |
24 | if (bodyArg) Object.assign(body, bodyArg) | |
25 | ||
26 | return makePostBodyRequest({ | |
27 | url: server.url, | |
28 | path: '/plugins/test-four/router/commander', | |
29 | fields: body, | |
2d53be02 | 30 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
80fdaf06 C |
31 | }) |
32 | } | |
1b05d82d C |
33 | |
34 | describe('Test plugin helpers', function () { | |
80fdaf06 | 35 | let servers: ServerInfo[] |
1b05d82d C |
36 | |
37 | before(async function () { | |
80fdaf06 C |
38 | this.timeout(60000) |
39 | ||
40 | servers = await flushAndRunMultipleServers(2) | |
41 | await setAccessTokensToServers(servers) | |
1b05d82d | 42 | |
80fdaf06 | 43 | await doubleFollow(servers[0], servers[1]) |
1b05d82d C |
44 | |
45 | await installPlugin({ | |
80fdaf06 C |
46 | url: servers[0].url, |
47 | accessToken: servers[0].accessToken, | |
1b05d82d C |
48 | path: getPluginTestPath('-four') |
49 | }) | |
50 | }) | |
51 | ||
80fdaf06 C |
52 | describe('Logger', function () { |
53 | ||
54 | it('Should have logged things', async function () { | |
55 | await waitUntilLog(servers[0], 'localhost:' + servers[0].port + ' peertube-plugin-test-four', 1, false) | |
56 | await waitUntilLog(servers[0], 'Hello world from plugin four', 1) | |
57 | }) | |
1b05d82d C |
58 | }) |
59 | ||
80fdaf06 C |
60 | describe('Database', function () { |
61 | ||
62 | it('Should have made a query', async function () { | |
63 | await waitUntilLog(servers[0], `root email is admin${servers[0].internalServerNumber}@example.com`) | |
64 | }) | |
65 | }) | |
66 | ||
67 | describe('Config', function () { | |
68 | ||
69 | it('Should have the correct webserver url', async function () { | |
70 | await waitUntilLog(servers[0], `server url is http://localhost:${servers[0].port}`) | |
71 | }) | |
22820226 C |
72 | |
73 | it('Should have the correct config', async function () { | |
74 | const res = await makeGetRequest({ | |
75 | url: servers[0].url, | |
76 | path: '/plugins/test-four/router/server-config', | |
77 | statusCodeExpected: HttpStatusCode.OK_200 | |
78 | }) | |
79 | ||
80 | expect(res.body.serverConfig).to.exist | |
81 | expect(res.body.serverConfig.instance.name).to.equal('PeerTube') | |
82 | }) | |
80fdaf06 C |
83 | }) |
84 | ||
85 | describe('Server', function () { | |
86 | ||
87 | it('Should get the server actor', async function () { | |
88 | await waitUntilLog(servers[0], 'server actor name is peertube') | |
89 | }) | |
90 | }) | |
91 | ||
22820226 C |
92 | describe('Plugin', function () { |
93 | ||
94 | it('Should get the base static route', async function () { | |
95 | const res = await makeGetRequest({ | |
96 | url: servers[0].url, | |
97 | path: '/plugins/test-four/router/static-route', | |
98 | statusCodeExpected: HttpStatusCode.OK_200 | |
99 | }) | |
100 | ||
101 | expect(res.body.staticRoute).to.equal('/plugins/test-four/0.0.1/static/') | |
102 | }) | |
302eba0d C |
103 | |
104 | it('Should get the base static route', async function () { | |
105 | const baseRouter = '/plugins/test-four/0.0.1/router/' | |
106 | ||
107 | const res = await makeGetRequest({ | |
108 | url: servers[0].url, | |
109 | path: baseRouter + 'router-route', | |
110 | statusCodeExpected: HttpStatusCode.OK_200 | |
111 | }) | |
112 | ||
113 | expect(res.body.routerRoute).to.equal(baseRouter) | |
114 | }) | |
115 | }) | |
116 | ||
117 | describe('User', function () { | |
118 | ||
119 | it('Should not get a user if not authenticated', async function () { | |
120 | const res = await makeGetRequest({ | |
121 | url: servers[0].url, | |
122 | path: '/plugins/test-four/router/user', | |
123 | statusCodeExpected: HttpStatusCode.OK_200 | |
124 | }) | |
125 | ||
126 | expect(res.body.user).to.be.undefined | |
127 | }) | |
128 | ||
129 | it('Should get a user if authenticated', async function () { | |
130 | const res = await makeGetRequest({ | |
131 | url: servers[0].url, | |
132 | token: servers[0].accessToken, | |
133 | path: '/plugins/test-four/router/user', | |
134 | statusCodeExpected: HttpStatusCode.OK_200 | |
135 | }) | |
136 | ||
137 | expect(res.body.user).to.exist | |
138 | expect(res.body.username).to.equal('root') | |
139 | expect(res.body.isAdmin).to.be.true | |
140 | expect(res.body.isModerator).to.be.false | |
141 | expect(res.body.isUser).to.be.false | |
142 | }) | |
22820226 C |
143 | }) |
144 | ||
80fdaf06 C |
145 | describe('Moderation', function () { |
146 | let videoUUIDServer1: string | |
147 | ||
148 | before(async function () { | |
c655c9ef | 149 | this.timeout(30000) |
80fdaf06 C |
150 | |
151 | { | |
152 | const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) | |
153 | videoUUIDServer1 = res.uuid | |
154 | } | |
155 | ||
156 | { | |
157 | await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) | |
158 | } | |
159 | ||
160 | await waitJobs(servers) | |
161 | ||
162 | const res = await getVideosList(servers[0].url) | |
163 | const videos = res.body.data | |
164 | ||
165 | expect(videos).to.have.lengthOf(2) | |
166 | }) | |
167 | ||
168 | it('Should mute server 2', async function () { | |
169 | this.timeout(10000) | |
170 | await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` }) | |
171 | ||
172 | const res = await getVideosList(servers[0].url) | |
173 | const videos = res.body.data | |
174 | ||
175 | expect(videos).to.have.lengthOf(1) | |
176 | expect(videos[0].name).to.equal('video server 1') | |
177 | }) | |
178 | ||
179 | it('Should unmute server 2', async function () { | |
180 | await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` }) | |
181 | ||
182 | const res = await getVideosList(servers[0].url) | |
183 | const videos = res.body.data | |
184 | ||
185 | expect(videos).to.have.lengthOf(2) | |
186 | }) | |
187 | ||
188 | it('Should mute account of server 2', async function () { | |
189 | await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` }) | |
190 | ||
191 | const res = await getVideosList(servers[0].url) | |
192 | const videos = res.body.data | |
193 | ||
194 | expect(videos).to.have.lengthOf(1) | |
195 | expect(videos[0].name).to.equal('video server 1') | |
196 | }) | |
197 | ||
198 | it('Should unmute account of server 2', async function () { | |
199 | await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` }) | |
200 | ||
201 | const res = await getVideosList(servers[0].url) | |
202 | const videos = res.body.data | |
203 | ||
204 | expect(videos).to.have.lengthOf(2) | |
205 | }) | |
206 | ||
207 | it('Should blacklist video', async function () { | |
208 | this.timeout(10000) | |
209 | ||
210 | await postCommand(servers[0], 'blacklist', { videoUUID: videoUUIDServer1, unfederate: true }) | |
211 | ||
212 | await waitJobs(servers) | |
213 | ||
214 | for (const server of servers) { | |
215 | const res = await getVideosList(server.url) | |
216 | const videos = res.body.data | |
217 | ||
218 | expect(videos).to.have.lengthOf(1) | |
219 | expect(videos[0].name).to.equal('video server 2') | |
220 | } | |
221 | }) | |
222 | ||
223 | it('Should unblacklist video', async function () { | |
224 | this.timeout(10000) | |
225 | ||
226 | await postCommand(servers[0], 'unblacklist', { videoUUID: videoUUIDServer1 }) | |
227 | ||
228 | await waitJobs(servers) | |
229 | ||
230 | for (const server of servers) { | |
231 | const res = await getVideosList(server.url) | |
232 | const videos = res.body.data | |
233 | ||
234 | expect(videos).to.have.lengthOf(2) | |
235 | } | |
236 | }) | |
1b05d82d C |
237 | }) |
238 | ||
80fdaf06 C |
239 | describe('Videos', function () { |
240 | let videoUUID: string | |
241 | ||
242 | before(async () => { | |
243 | const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video1' }) | |
244 | videoUUID = res.uuid | |
245 | }) | |
ab3ead3a | 246 | |
80fdaf06 | 247 | it('Should remove a video after a view', async function () { |
59fd824c | 248 | this.timeout(40000) |
ab3ead3a | 249 | |
80fdaf06 C |
250 | // Should not throw -> video exists |
251 | await getVideo(servers[0].url, videoUUID) | |
252 | // Should delete the video | |
253 | await viewVideo(servers[0].url, videoUUID) | |
ab3ead3a | 254 | |
80fdaf06 | 255 | await waitUntilLog(servers[0], 'Video deleted by plugin four.') |
ab3ead3a | 256 | |
80fdaf06 C |
257 | try { |
258 | // Should throw because the video should have been deleted | |
259 | await getVideo(servers[0].url, videoUUID) | |
260 | throw new Error('Video exists') | |
261 | } catch (err) { | |
262 | if (err.message.includes('exists')) throw err | |
263 | } | |
ab3ead3a | 264 | |
80fdaf06 C |
265 | await checkVideoFilesWereRemoved(videoUUID, servers[0].internalServerNumber) |
266 | }) | |
267 | ||
268 | it('Should have fetched the video by URL', async function () { | |
269 | await waitUntilLog(servers[0], `video from DB uuid is ${videoUUID}`) | |
270 | }) | |
ab3ead3a C |
271 | }) |
272 | ||
1b05d82d | 273 | after(async function () { |
80fdaf06 | 274 | await cleanupTests(servers) |
1b05d82d C |
275 | }) |
276 | }) |