aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/external-plugins/auto-mute.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/external-plugins/auto-mute.ts')
-rw-r--r--server/tests/external-plugins/auto-mute.ts98
1 files changed, 38 insertions, 60 deletions
diff --git a/server/tests/external-plugins/auto-mute.ts b/server/tests/external-plugins/auto-mute.ts
index 09355d932..271779dd4 100644
--- a/server/tests/external-plugins/auto-mute.ts
+++ b/server/tests/external-plugins/auto-mute.ts
@@ -3,63 +3,45 @@
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { 5import {
6 addAccountToServerBlocklist, 6 cleanupTests,
7 addServerToAccountBlocklist, 7 createMultipleServers,
8 removeAccountFromServerBlocklist
9} from '@shared/extra-utils/users/blocklist'
10import {
11 doubleFollow, 8 doubleFollow,
12 getVideosList, 9 killallServers,
13 installPlugin,
14 makeGetRequest, 10 makeGetRequest,
15 MockBlocklist, 11 MockBlocklist,
12 PeerTubeServer,
16 setAccessTokensToServers, 13 setAccessTokensToServers,
17 updatePluginSettings,
18 uploadVideoAndGetId,
19 wait 14 wait
20} from '../../../shared/extra-utils' 15} from '@shared/extra-utils'
21import { 16import { HttpStatusCode } from '@shared/models'
22 cleanupTests,
23 flushAndRunMultipleServers,
24 killallServers,
25 reRunServer,
26 ServerInfo
27} from '../../../shared/extra-utils/server/servers'
28import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
29 17
30describe('Official plugin auto-mute', function () { 18describe('Official plugin auto-mute', function () {
31 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list' 19 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
32 let servers: ServerInfo[] 20 let servers: PeerTubeServer[]
33 let blocklistServer: MockBlocklist 21 let blocklistServer: MockBlocklist
34 let port: number 22 let port: number
35 23
36 before(async function () { 24 before(async function () {
37 this.timeout(30000) 25 this.timeout(30000)
38 26
39 servers = await flushAndRunMultipleServers(2) 27 servers = await createMultipleServers(2)
40 await setAccessTokensToServers(servers) 28 await setAccessTokensToServers(servers)
41 29
42 for (const server of servers) { 30 for (const server of servers) {
43 await installPlugin({ 31 await server.plugins.install({ npmName: 'peertube-plugin-auto-mute' })
44 url: server.url,
45 accessToken: server.accessToken,
46 npmName: 'peertube-plugin-auto-mute'
47 })
48 } 32 }
49 33
50 blocklistServer = new MockBlocklist() 34 blocklistServer = new MockBlocklist()
51 port = await blocklistServer.initialize() 35 port = await blocklistServer.initialize()
52 36
53 await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) 37 await servers[0].videos.quickUpload({ name: 'video server 1' })
54 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) 38 await servers[1].videos.quickUpload({ name: 'video server 2' })
55 39
56 await doubleFollow(servers[0], servers[1]) 40 await doubleFollow(servers[0], servers[1])
57 }) 41 })
58 42
59 it('Should update plugin settings', async function () { 43 it('Should update plugin settings', async function () {
60 await updatePluginSettings({ 44 await servers[0].plugins.updateSettings({
61 url: servers[0].url,
62 accessToken: servers[0].accessToken,
63 npmName: 'peertube-plugin-auto-mute', 45 npmName: 'peertube-plugin-auto-mute',
64 settings: { 46 settings: {
65 'blocklist-urls': `http://localhost:${port}/blocklist`, 47 'blocklist-urls': `http://localhost:${port}/blocklist`,
@@ -81,8 +63,8 @@ describe('Official plugin auto-mute', function () {
81 63
82 await wait(2000) 64 await wait(2000)
83 65
84 const res = await getVideosList(servers[0].url) 66 const { total } = await servers[0].videos.list()
85 expect(res.body.total).to.equal(1) 67 expect(total).to.equal(1)
86 }) 68 })
87 69
88 it('Should remove a server blocklist', async function () { 70 it('Should remove a server blocklist', async function () {
@@ -99,8 +81,8 @@ describe('Official plugin auto-mute', function () {
99 81
100 await wait(2000) 82 await wait(2000)
101 83
102 const res = await getVideosList(servers[0].url) 84 const { total } = await servers[0].videos.list()
103 expect(res.body.total).to.equal(2) 85 expect(total).to.equal(2)
104 }) 86 })
105 87
106 it('Should add an account blocklist', async function () { 88 it('Should add an account blocklist', async function () {
@@ -116,8 +98,8 @@ describe('Official plugin auto-mute', function () {
116 98
117 await wait(2000) 99 await wait(2000)
118 100
119 const res = await getVideosList(servers[0].url) 101 const { total } = await servers[0].videos.list()
120 expect(res.body.total).to.equal(1) 102 expect(total).to.equal(1)
121 }) 103 })
122 104
123 it('Should remove an account blocklist', async function () { 105 it('Should remove an account blocklist', async function () {
@@ -134,8 +116,8 @@ describe('Official plugin auto-mute', function () {
134 116
135 await wait(2000) 117 await wait(2000)
136 118
137 const res = await getVideosList(servers[0].url) 119 const { total } = await servers[0].videos.list()
138 expect(res.body.total).to.equal(2) 120 expect(total).to.equal(2)
139 }) 121 })
140 122
141 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () { 123 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
@@ -155,24 +137,24 @@ describe('Official plugin auto-mute', function () {
155 await wait(2000) 137 await wait(2000)
156 138
157 { 139 {
158 const res = await getVideosList(servers[0].url) 140 const { total } = await servers[0].videos.list()
159 expect(res.body.total).to.equal(1) 141 expect(total).to.equal(1)
160 } 142 }
161 143
162 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, account) 144 await servers[0].blocklist.removeFromServerBlocklist({ account })
163 145
164 { 146 {
165 const res = await getVideosList(servers[0].url) 147 const { total } = await servers[0].videos.list()
166 expect(res.body.total).to.equal(2) 148 expect(total).to.equal(2)
167 } 149 }
168 150
169 killallServers([ servers[0] ]) 151 await killallServers([ servers[0] ])
170 await reRunServer(servers[0]) 152 await servers[0].run()
171 await wait(2000) 153 await wait(2000)
172 154
173 { 155 {
174 const res = await getVideosList(servers[0].url) 156 const { total } = await servers[0].videos.list()
175 expect(res.body.total).to.equal(2) 157 expect(total).to.equal(2)
176 } 158 }
177 }) 159 })
178 160
@@ -180,14 +162,12 @@ describe('Official plugin auto-mute', function () {
180 await makeGetRequest({ 162 await makeGetRequest({
181 url: servers[0].url, 163 url: servers[0].url,
182 path: '/plugins/auto-mute/router/api/v1/mute-list', 164 path: '/plugins/auto-mute/router/api/v1/mute-list',
183 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 165 expectedStatus: HttpStatusCode.FORBIDDEN_403
184 }) 166 })
185 }) 167 })
186 168
187 it('Should enable auto mute list', async function () { 169 it('Should enable auto mute list', async function () {
188 await updatePluginSettings({ 170 await servers[0].plugins.updateSettings({
189 url: servers[0].url,
190 accessToken: servers[0].accessToken,
191 npmName: 'peertube-plugin-auto-mute', 171 npmName: 'peertube-plugin-auto-mute',
192 settings: { 172 settings: {
193 'blocklist-urls': '', 173 'blocklist-urls': '',
@@ -199,16 +179,14 @@ describe('Official plugin auto-mute', function () {
199 await makeGetRequest({ 179 await makeGetRequest({
200 url: servers[0].url, 180 url: servers[0].url,
201 path: '/plugins/auto-mute/router/api/v1/mute-list', 181 path: '/plugins/auto-mute/router/api/v1/mute-list',
202 statusCodeExpected: HttpStatusCode.OK_200 182 expectedStatus: HttpStatusCode.OK_200
203 }) 183 })
204 }) 184 })
205 185
206 it('Should mute an account on server 1, and server 2 auto mutes it', async function () { 186 it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
207 this.timeout(20000) 187 this.timeout(20000)
208 188
209 await updatePluginSettings({ 189 await servers[1].plugins.updateSettings({
210 url: servers[1].url,
211 accessToken: servers[1].accessToken,
212 npmName: 'peertube-plugin-auto-mute', 190 npmName: 'peertube-plugin-auto-mute',
213 settings: { 191 settings: {
214 'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath, 192 'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath,
@@ -217,13 +195,13 @@ describe('Official plugin auto-mute', function () {
217 } 195 }
218 }) 196 })
219 197
220 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port) 198 await servers[0].blocklist.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port })
221 await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) 199 await servers[0].blocklist.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
222 200
223 const res = await makeGetRequest({ 201 const res = await makeGetRequest({
224 url: servers[0].url, 202 url: servers[0].url,
225 path: '/plugins/auto-mute/router/api/v1/mute-list', 203 path: '/plugins/auto-mute/router/api/v1/mute-list',
226 statusCodeExpected: HttpStatusCode.OK_200 204 expectedStatus: HttpStatusCode.OK_200
227 }) 205 })
228 206
229 const data = res.body.data 207 const data = res.body.data
@@ -234,8 +212,8 @@ describe('Official plugin auto-mute', function () {
234 await wait(2000) 212 await wait(2000)
235 213
236 for (const server of servers) { 214 for (const server of servers) {
237 const res = await getVideosList(server.url) 215 const { total } = await server.videos.list()
238 expect(res.body.total).to.equal(1) 216 expect(total).to.equal(1)
239 } 217 }
240 }) 218 })
241 219