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