1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
9 flushAndRunMultipleServers,
15 setAccessTokensToServers,
17 } from '@shared/extra-utils'
19 describe('Official plugin auto-mute', function () {
20 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
21 let servers: ServerInfo[]
22 let blocklistServer: MockBlocklist
25 before(async function () {
28 servers = await flushAndRunMultipleServers(2)
29 await setAccessTokensToServers(servers)
31 for (const server of servers) {
32 await server.pluginsCommand.install({ npmName: 'peertube-plugin-auto-mute' })
35 blocklistServer = new MockBlocklist()
36 port = await blocklistServer.initialize()
38 await await servers[0].videosCommand.quickUpload({ name: 'video server 1' })
39 await await servers[1].videosCommand.quickUpload({ name: 'video server 2' })
41 await doubleFollow(servers[0], servers[1])
44 it('Should update plugin settings', async function () {
45 await servers[0].pluginsCommand.updateSettings({
46 npmName: 'peertube-plugin-auto-mute',
48 'blocklist-urls': `http://localhost:${port}/blocklist`,
49 'check-seconds-interval': 1
54 it('Should add a server blocklist', async function () {
57 blocklistServer.replace({
60 value: 'localhost:' + servers[1].port
67 const { total } = await servers[0].videosCommand.list()
68 expect(total).to.equal(1)
71 it('Should remove a server blocklist', async function () {
74 blocklistServer.replace({
77 value: 'localhost:' + servers[1].port,
85 const { total } = await servers[0].videosCommand.list()
86 expect(total).to.equal(2)
89 it('Should add an account blocklist', async function () {
92 blocklistServer.replace({
95 value: 'root@localhost:' + servers[1].port
102 const { total } = await servers[0].videosCommand.list()
103 expect(total).to.equal(1)
106 it('Should remove an account blocklist', async function () {
109 blocklistServer.replace({
112 value: 'root@localhost:' + servers[1].port,
120 const { total } = await servers[0].videosCommand.list()
121 expect(total).to.equal(2)
124 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
127 const account = 'root@localhost:' + servers[1].port
129 blocklistServer.replace({
133 updatedAt: new Date().toISOString()
141 const { total } = await servers[0].videosCommand.list()
142 expect(total).to.equal(1)
145 await servers[0].blocklistCommand.removeFromServerBlocklist({ account })
148 const { total } = await servers[0].videosCommand.list()
149 expect(total).to.equal(2)
152 await killallServers([ servers[0] ])
153 await reRunServer(servers[0])
157 const { total } = await servers[0].videosCommand.list()
158 expect(total).to.equal(2)
162 it('Should not expose the auto mute list', async function () {
163 await makeGetRequest({
165 path: '/plugins/auto-mute/router/api/v1/mute-list',
166 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
170 it('Should enable auto mute list', async function () {
171 await servers[0].pluginsCommand.updateSettings({
172 npmName: 'peertube-plugin-auto-mute',
174 'blocklist-urls': '',
175 'check-seconds-interval': 1,
176 'expose-mute-list': true
180 await makeGetRequest({
182 path: '/plugins/auto-mute/router/api/v1/mute-list',
183 statusCodeExpected: HttpStatusCode.OK_200
187 it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
190 await servers[1].pluginsCommand.updateSettings({
191 npmName: 'peertube-plugin-auto-mute',
193 'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath,
194 'check-seconds-interval': 1,
195 'expose-mute-list': false
199 await servers[0].blocklistCommand.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port })
200 await servers[0].blocklistCommand.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
202 const res = await makeGetRequest({
204 path: '/plugins/auto-mute/router/api/v1/mute-list',
205 statusCodeExpected: HttpStatusCode.OK_200
208 const data = res.body.data
209 expect(data).to.have.lengthOf(1)
210 expect(data[0].updatedAt).to.exist
211 expect(data[0].value).to.equal('root@localhost:' + servers[1].port)
215 for (const server of servers) {
216 const { total } = await server.videosCommand.list()
217 expect(total).to.equal(1)
221 after(async function () {
222 await blocklistServer.terminate()
224 await cleanupTests(servers)