1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { wait } from '@shared/core-utils'
5 import { HttpStatusCode } from '@shared/models'
13 setAccessTokensToServers
14 } from '@shared/server-commands'
15 import { MockBlocklist } from '../shared'
17 describe('Official plugin auto-mute', function () {
18 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
19 let servers: PeerTubeServer[]
20 let blocklistServer: MockBlocklist
23 before(async function () {
26 servers = await createMultipleServers(2)
27 await setAccessTokensToServers(servers)
29 for (const server of servers) {
30 await server.plugins.install({ npmName: 'peertube-plugin-auto-mute' })
33 blocklistServer = new MockBlocklist()
34 port = await blocklistServer.initialize()
36 await servers[0].videos.quickUpload({ name: 'video server 1' })
37 await servers[1].videos.quickUpload({ name: 'video server 2' })
39 await doubleFollow(servers[0], servers[1])
42 it('Should update plugin settings', async function () {
43 await servers[0].plugins.updateSettings({
44 npmName: 'peertube-plugin-auto-mute',
46 'blocklist-urls': `http://127.0.0.1:${port}/blocklist`,
47 'check-seconds-interval': 1
52 it('Should add a server blocklist', async function () {
55 blocklistServer.replace({
58 value: servers[1].host
65 const { total } = await servers[0].videos.list()
66 expect(total).to.equal(1)
69 it('Should remove a server blocklist', async function () {
72 blocklistServer.replace({
75 value: servers[1].host,
83 const { total } = await servers[0].videos.list()
84 expect(total).to.equal(2)
87 it('Should add an account blocklist', async function () {
90 blocklistServer.replace({
93 value: 'root@' + servers[1].host
100 const { total } = await servers[0].videos.list()
101 expect(total).to.equal(1)
104 it('Should remove an account blocklist', async function () {
107 blocklistServer.replace({
110 value: 'root@' + servers[1].host,
118 const { total } = await servers[0].videos.list()
119 expect(total).to.equal(2)
122 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
125 const account = 'root@' + servers[1].host
127 blocklistServer.replace({
131 updatedAt: new Date().toISOString()
139 const { total } = await servers[0].videos.list()
140 expect(total).to.equal(1)
143 await servers[0].blocklist.removeFromServerBlocklist({ account })
146 const { total } = await servers[0].videos.list()
147 expect(total).to.equal(2)
150 await killallServers([ servers[0] ])
151 await servers[0].run()
155 const { total } = await servers[0].videos.list()
156 expect(total).to.equal(2)
160 it('Should not expose the auto mute list', async function () {
161 await makeGetRequest({
163 path: '/plugins/auto-mute/router/api/v1/mute-list',
164 expectedStatus: HttpStatusCode.FORBIDDEN_403
168 it('Should enable auto mute list', async function () {
169 await servers[0].plugins.updateSettings({
170 npmName: 'peertube-plugin-auto-mute',
172 'blocklist-urls': '',
173 'check-seconds-interval': 1,
174 'expose-mute-list': true
178 await makeGetRequest({
180 path: '/plugins/auto-mute/router/api/v1/mute-list',
181 expectedStatus: HttpStatusCode.OK_200
185 it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
188 await servers[1].plugins.updateSettings({
189 npmName: 'peertube-plugin-auto-mute',
191 'blocklist-urls': 'http://' + servers[0].host + autoMuteListPath,
192 'check-seconds-interval': 1,
193 'expose-mute-list': false
197 await servers[0].blocklist.addToServerBlocklist({ account: 'root@' + servers[1].host })
198 await servers[0].blocklist.addToMyBlocklist({ server: servers[1].host })
200 const res = await makeGetRequest({
202 path: '/plugins/auto-mute/router/api/v1/mute-list',
203 expectedStatus: HttpStatusCode.OK_200
206 const data = res.body.data
207 expect(data).to.have.lengthOf(1)
208 expect(data[0].updatedAt).to.exist
209 expect(data[0].value).to.equal('root@' + servers[1].host)
213 for (const server of servers) {
214 const { total } = await server.videos.list()
215 expect(total).to.equal(1)
219 after(async function () {
220 await blocklistServer.terminate()
222 await cleanupTests(servers)