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