aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-05-07 14:58:24 +0200
committerChocobozzz <me@florianbigard.com>2020-05-07 15:07:01 +0200
commit80fdaf064562aff968f4c9cea1cf220bc12a70da (patch)
treea0ec49f433b828660f741b394dfd87056cd2c6ef /server/tests/plugins
parent3cc665f48fd233d09f778d7e887488dde6f03ef6 (diff)
downloadPeerTube-80fdaf064562aff968f4c9cea1cf220bc12a70da.tar.gz
PeerTube-80fdaf064562aff968f4c9cea1cf220bc12a70da.tar.zst
PeerTube-80fdaf064562aff968f4c9cea1cf220bc12a70da.zip
Add moderation helpers to plugins
Diffstat (limited to 'server/tests/plugins')
-rw-r--r--server/tests/plugins/plugin-helpers.ts204
1 files changed, 174 insertions, 30 deletions
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts
index dfe8ebe55..0915603d0 100644
--- a/server/tests/plugins/plugin-helpers.ts
+++ b/server/tests/plugins/plugin-helpers.ts
@@ -1,66 +1,210 @@
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 { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
5import { 4import {
6 checkVideoFilesWereRemoved, 5 checkVideoFilesWereRemoved,
6 doubleFollow,
7 getPluginTestPath, 7 getPluginTestPath,
8 getVideo, 8 getVideo,
9 installPlugin, 9 installPlugin,
10 makePostBodyRequest,
10 setAccessTokensToServers, 11 setAccessTokensToServers,
11 uploadVideoAndGetId, 12 uploadVideoAndGetId,
12 viewVideo 13 viewVideo,
14 getVideosList,
15 waitJobs
13} from '../../../shared/extra-utils' 16} from '../../../shared/extra-utils'
17import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
18import { expect } from 'chai'
19
20function postCommand (server: ServerInfo, command: string, bodyArg?: object) {
21 const body = { command }
22 if (bodyArg) Object.assign(body, bodyArg)
23
24 return makePostBodyRequest({
25 url: server.url,
26 path: '/plugins/test-four/router/commander',
27 fields: body,
28 statusCodeExpected: 204
29 })
30}
14 31
15describe('Test plugin helpers', function () { 32describe('Test plugin helpers', function () {
16 let server: ServerInfo 33 let servers: ServerInfo[]
17 34
18 before(async function () { 35 before(async function () {
19 this.timeout(30000) 36 this.timeout(60000)
37
38 servers = await flushAndRunMultipleServers(2)
39 await setAccessTokensToServers(servers)
20 40
21 server = await flushAndRunServer(1) 41 await doubleFollow(servers[0], servers[1])
22 await setAccessTokensToServers([ server ])
23 42
24 await installPlugin({ 43 await installPlugin({
25 url: server.url, 44 url: servers[0].url,
26 accessToken: server.accessToken, 45 accessToken: servers[0].accessToken,
27 path: getPluginTestPath('-four') 46 path: getPluginTestPath('-four')
28 }) 47 })
29 }) 48 })
30 49
31 it('Should have logged things', async function () { 50 describe('Logger', function () {
32 await waitUntilLog(server, 'localhost:' + server.port + ' peertube-plugin-test-four', 1, false) 51
33 await waitUntilLog(server, 'Hello world from plugin four', 1) 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 })
34 }) 56 })
35 57
36 it('Should have made a query', async function () { 58 describe('Database', function () {
37 await waitUntilLog(server, `root email is admin${server.internalServerNumber}@example.com`, 1) 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 })
70 })
71
72 describe('Server', function () {
73
74 it('Should get the server actor', async function () {
75 await waitUntilLog(servers[0], 'server actor name is peertube')
76 })
77 })
78
79 describe('Moderation', function () {
80 let videoUUIDServer1: string
81
82 before(async function () {
83 this.timeout(15000)
84
85 {
86 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
87 videoUUIDServer1 = res.uuid
88 }
89
90 {
91 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
92 }
93
94 await waitJobs(servers)
95
96 const res = await getVideosList(servers[0].url)
97 const videos = res.body.data
98
99 expect(videos).to.have.lengthOf(2)
100 })
101
102 it('Should mute server 2', async function () {
103 this.timeout(10000)
104 await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` })
105
106 const res = await getVideosList(servers[0].url)
107 const videos = res.body.data
108
109 expect(videos).to.have.lengthOf(1)
110 expect(videos[0].name).to.equal('video server 1')
111 })
112
113 it('Should unmute server 2', async function () {
114 await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` })
115
116 const res = await getVideosList(servers[0].url)
117 const videos = res.body.data
118
119 expect(videos).to.have.lengthOf(2)
120 })
121
122 it('Should mute account of server 2', async function () {
123 await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` })
124
125 const res = await getVideosList(servers[0].url)
126 const videos = res.body.data
127
128 expect(videos).to.have.lengthOf(1)
129 expect(videos[0].name).to.equal('video server 1')
130 })
131
132 it('Should unmute account of server 2', async function () {
133 await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` })
134
135 const res = await getVideosList(servers[0].url)
136 const videos = res.body.data
137
138 expect(videos).to.have.lengthOf(2)
139 })
140
141 it('Should blacklist video', async function () {
142 this.timeout(10000)
143
144 await postCommand(servers[0], 'blacklist', { videoUUID: videoUUIDServer1, unfederate: true })
145
146 await waitJobs(servers)
147
148 for (const server of servers) {
149 const res = await getVideosList(server.url)
150 const videos = res.body.data
151
152 expect(videos).to.have.lengthOf(1)
153 expect(videos[0].name).to.equal('video server 2')
154 }
155 })
156
157 it('Should unblacklist video', async function () {
158 this.timeout(10000)
159
160 await postCommand(servers[0], 'unblacklist', { videoUUID: videoUUIDServer1 })
161
162 await waitJobs(servers)
163
164 for (const server of servers) {
165 const res = await getVideosList(server.url)
166 const videos = res.body.data
167
168 expect(videos).to.have.lengthOf(2)
169 }
170 })
38 }) 171 })
39 172
40 it('Should remove a video after a view', async function () { 173 describe('Videos', function () {
41 this.timeout(20000) 174 let videoUUID: string
175
176 before(async () => {
177 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video1' })
178 videoUUID = res.uuid
179 })
42 180
43 const videoUUID = (await uploadVideoAndGetId({ server: server, videoName: 'video1' })).uuid 181 it('Should remove a video after a view', async function () {
182 this.timeout(20000)
44 183
45 // Should not throw -> video exists 184 // Should not throw -> video exists
46 await getVideo(server.url, videoUUID) 185 await getVideo(servers[0].url, videoUUID)
47 // Should delete the video 186 // Should delete the video
48 await viewVideo(server.url, videoUUID) 187 await viewVideo(servers[0].url, videoUUID)
49 188
50 await waitUntilLog(server, 'Video deleted by plugin four.', 1) 189 await waitUntilLog(servers[0], 'Video deleted by plugin four.')
51 190
52 try { 191 try {
53 // Should throw because the video should have been deleted 192 // Should throw because the video should have been deleted
54 await getVideo(server.url, videoUUID) 193 await getVideo(servers[0].url, videoUUID)
55 throw new Error('Video exists') 194 throw new Error('Video exists')
56 } catch (err) { 195 } catch (err) {
57 if (err.message.includes('exists')) throw err 196 if (err.message.includes('exists')) throw err
58 } 197 }
59 198
60 await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber) 199 await checkVideoFilesWereRemoved(videoUUID, servers[0].internalServerNumber)
200 })
201
202 it('Should have fetched the video by URL', async function () {
203 await waitUntilLog(servers[0], `video from DB uuid is ${videoUUID}`)
204 })
61 }) 205 })
62 206
63 after(async function () { 207 after(async function () {
64 await cleanupTests([ server ]) 208 await cleanupTests(servers)
65 }) 209 })
66}) 210})