1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
6 addAccountToServerBlocklist,
7 addServerToAccountBlocklist,
8 removeAccountFromServerBlocklist
9 } from '@shared/extra-utils/users/blocklist'
16 setAccessTokensToServers,
20 } from '../../../shared/extra-utils'
23 flushAndRunMultipleServers,
27 } from '../../../shared/extra-utils/server/servers'
28 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
30 describe('Official plugin auto-mute', function () {
31 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
32 let servers: ServerInfo[]
33 let blocklistServer: MockBlocklist
36 before(async function () {
39 servers = await flushAndRunMultipleServers(2)
40 await setAccessTokensToServers(servers)
42 for (const server of servers) {
45 accessToken: server.accessToken,
46 npmName: 'peertube-plugin-auto-mute'
50 blocklistServer = new MockBlocklist()
51 port = await blocklistServer.initialize()
53 await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
54 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
56 await doubleFollow(servers[0], servers[1])
59 it('Should update plugin settings', async function () {
60 await updatePluginSettings({
62 accessToken: servers[0].accessToken,
63 npmName: 'peertube-plugin-auto-mute',
65 'blocklist-urls': `http://localhost:${port}/blocklist`,
66 'check-seconds-interval': 1
71 it('Should add a server blocklist', async function () {
74 blocklistServer.replace({
77 value: 'localhost:' + servers[1].port
84 const res = await getVideosList(servers[0].url)
85 expect(res.body.total).to.equal(1)
88 it('Should remove a server blocklist', async function () {
91 blocklistServer.replace({
94 value: 'localhost:' + servers[1].port,
102 const res = await getVideosList(servers[0].url)
103 expect(res.body.total).to.equal(2)
106 it('Should add an account blocklist', async function () {
109 blocklistServer.replace({
112 value: 'root@localhost:' + servers[1].port
119 const res = await getVideosList(servers[0].url)
120 expect(res.body.total).to.equal(1)
123 it('Should remove an account blocklist', async function () {
126 blocklistServer.replace({
129 value: 'root@localhost:' + servers[1].port,
137 const res = await getVideosList(servers[0].url)
138 expect(res.body.total).to.equal(2)
141 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
144 const account = 'root@localhost:' + servers[1].port
146 blocklistServer.replace({
150 updatedAt: new Date().toISOString()
158 const res = await getVideosList(servers[0].url)
159 expect(res.body.total).to.equal(1)
162 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, account)
165 const res = await getVideosList(servers[0].url)
166 expect(res.body.total).to.equal(2)
169 killallServers([ servers[0] ])
170 await reRunServer(servers[0])
174 const res = await getVideosList(servers[0].url)
175 expect(res.body.total).to.equal(2)
179 it('Should not expose the auto mute list', async function () {
180 await makeGetRequest({
182 path: '/plugins/auto-mute/router/api/v1/mute-list',
183 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
187 it('Should enable auto mute list', async function () {
188 await updatePluginSettings({
190 accessToken: servers[0].accessToken,
191 npmName: 'peertube-plugin-auto-mute',
193 'blocklist-urls': '',
194 'check-seconds-interval': 1,
195 'expose-mute-list': true
199 await makeGetRequest({
201 path: '/plugins/auto-mute/router/api/v1/mute-list',
202 statusCodeExpected: HttpStatusCode.OK_200
206 it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
209 await updatePluginSettings({
211 accessToken: servers[1].accessToken,
212 npmName: 'peertube-plugin-auto-mute',
214 'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath,
215 'check-seconds-interval': 1,
216 'expose-mute-list': false
220 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)
221 await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
223 const res = await makeGetRequest({
225 path: '/plugins/auto-mute/router/api/v1/mute-list',
226 statusCodeExpected: HttpStatusCode.OK_200
229 const data = res.body.data
230 expect(data).to.have.lengthOf(1)
231 expect(data[0].updatedAt).to.exist
232 expect(data[0].value).to.equal('root@localhost:' + servers[1].port)
236 for (const server of servers) {
237 const res = await getVideosList(server.url)
238 expect(res.body.total).to.equal(1)
242 after(async function () {
243 await blocklistServer.terminate()
245 await cleanupTests(servers)