aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/tests/src/external-plugins/auto-mute.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/tests/src/external-plugins/auto-mute.ts')
-rw-r--r--packages/tests/src/external-plugins/auto-mute.ts216
1 files changed, 216 insertions, 0 deletions
diff --git a/packages/tests/src/external-plugins/auto-mute.ts b/packages/tests/src/external-plugins/auto-mute.ts
new file mode 100644
index 000000000..b4050e236
--- /dev/null
+++ b/packages/tests/src/external-plugins/auto-mute.ts
@@ -0,0 +1,216 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { wait } from '@peertube/peertube-core-utils'
5import { HttpStatusCode } from '@peertube/peertube-models'
6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 killallServers,
11 makeGetRequest,
12 PeerTubeServer,
13 setAccessTokensToServers
14} from '@peertube/peertube-server-commands'
15import { MockBlocklist } from '../shared/mock-servers/index.js'
16
17describe('Official plugin auto-mute', function () {
18 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
19 let servers: PeerTubeServer[]
20 let blocklistServer: MockBlocklist
21 let port: number
22
23 before(async function () {
24 this.timeout(120000)
25
26 servers = await createMultipleServers(2)
27 await setAccessTokensToServers(servers)
28
29 for (const server of servers) {
30 await server.plugins.install({ npmName: 'peertube-plugin-auto-mute' })
31 }
32
33 blocklistServer = new MockBlocklist()
34 port = await blocklistServer.initialize()
35
36 await servers[0].videos.quickUpload({ name: 'video server 1' })
37 await servers[1].videos.quickUpload({ name: 'video server 2' })
38
39 await doubleFollow(servers[0], servers[1])
40 })
41
42 it('Should update plugin settings', async function () {
43 await servers[0].plugins.updateSettings({
44 npmName: 'peertube-plugin-auto-mute',
45 settings: {
46 'blocklist-urls': `http://127.0.0.1:${port}/blocklist`,
47 'check-seconds-interval': 1
48 }
49 })
50 })
51
52 it('Should add a server blocklist', async function () {
53 blocklistServer.replace({
54 data: [
55 {
56 value: servers[1].host
57 }
58 ]
59 })
60
61 await wait(2000)
62
63 const { total } = await servers[0].videos.list()
64 expect(total).to.equal(1)
65 })
66
67 it('Should remove a server blocklist', async function () {
68 blocklistServer.replace({
69 data: [
70 {
71 value: servers[1].host,
72 action: 'remove'
73 }
74 ]
75 })
76
77 await wait(2000)
78
79 const { total } = await servers[0].videos.list()
80 expect(total).to.equal(2)
81 })
82
83 it('Should add an account blocklist', async function () {
84 blocklistServer.replace({
85 data: [
86 {
87 value: 'root@' + servers[1].host
88 }
89 ]
90 })
91
92 await wait(2000)
93
94 const { total } = await servers[0].videos.list()
95 expect(total).to.equal(1)
96 })
97
98 it('Should remove an account blocklist', async function () {
99 blocklistServer.replace({
100 data: [
101 {
102 value: 'root@' + servers[1].host,
103 action: 'remove'
104 }
105 ]
106 })
107
108 await wait(2000)
109
110 const { total } = await servers[0].videos.list()
111 expect(total).to.equal(2)
112 })
113
114 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
115 this.timeout(20000)
116
117 const account = 'root@' + servers[1].host
118
119 blocklistServer.replace({
120 data: [
121 {
122 value: account,
123 updatedAt: new Date().toISOString()
124 }
125 ]
126 })
127
128 await wait(2000)
129
130 {
131 const { total } = await servers[0].videos.list()
132 expect(total).to.equal(1)
133 }
134
135 await servers[0].blocklist.removeFromServerBlocklist({ account })
136
137 {
138 const { total } = await servers[0].videos.list()
139 expect(total).to.equal(2)
140 }
141
142 await killallServers([ servers[0] ])
143 await servers[0].run()
144 await wait(2000)
145
146 {
147 const { total } = await servers[0].videos.list()
148 expect(total).to.equal(2)
149 }
150 })
151
152 it('Should not expose the auto mute list', async function () {
153 await makeGetRequest({
154 url: servers[0].url,
155 path: '/plugins/auto-mute/router/api/v1/mute-list',
156 expectedStatus: HttpStatusCode.FORBIDDEN_403
157 })
158 })
159
160 it('Should enable auto mute list', async function () {
161 await servers[0].plugins.updateSettings({
162 npmName: 'peertube-plugin-auto-mute',
163 settings: {
164 'blocklist-urls': '',
165 'check-seconds-interval': 1,
166 'expose-mute-list': true
167 }
168 })
169
170 await makeGetRequest({
171 url: servers[0].url,
172 path: '/plugins/auto-mute/router/api/v1/mute-list',
173 expectedStatus: HttpStatusCode.OK_200
174 })
175 })
176
177 it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
178 this.timeout(20000)
179
180 await servers[1].plugins.updateSettings({
181 npmName: 'peertube-plugin-auto-mute',
182 settings: {
183 'blocklist-urls': 'http://' + servers[0].host + autoMuteListPath,
184 'check-seconds-interval': 1,
185 'expose-mute-list': false
186 }
187 })
188
189 await servers[0].blocklist.addToServerBlocklist({ account: 'root@' + servers[1].host })
190 await servers[0].blocklist.addToMyBlocklist({ server: servers[1].host })
191
192 const res = await makeGetRequest({
193 url: servers[0].url,
194 path: '/plugins/auto-mute/router/api/v1/mute-list',
195 expectedStatus: HttpStatusCode.OK_200
196 })
197
198 const data = res.body.data
199 expect(data).to.have.lengthOf(1)
200 expect(data[0].updatedAt).to.exist
201 expect(data[0].value).to.equal('root@' + servers[1].host)
202
203 await wait(2000)
204
205 for (const server of servers) {
206 const { total } = await server.videos.list()
207 expect(total).to.equal(1)
208 }
209 })
210
211 after(async function () {
212 await blocklistServer.terminate()
213
214 await cleanupTests(servers)
215 })
216})