1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
7 addAccountToServerBlocklist,
8 addServerToAccountBlocklist,
11 flushAndRunMultipleServers,
16 removeAccountFromServerBlocklist,
19 setAccessTokensToServers,
22 } from '@shared/extra-utils'
24 describe('Official plugin auto-mute', function () {
25 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
26 let servers: ServerInfo[]
27 let blocklistServer: MockBlocklist
30 before(async function () {
33 servers = await flushAndRunMultipleServers(2)
34 await setAccessTokensToServers(servers)
36 for (const server of servers) {
37 await server.pluginsCommand.install({ npmName: 'peertube-plugin-auto-mute' })
40 blocklistServer = new MockBlocklist()
41 port = await blocklistServer.initialize()
43 await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
44 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
46 await doubleFollow(servers[0], servers[1])
49 it('Should update plugin settings', async function () {
50 await servers[0].pluginsCommand.updateSettings({
51 npmName: 'peertube-plugin-auto-mute',
53 'blocklist-urls': `http://localhost:${port}/blocklist`,
54 'check-seconds-interval': 1
59 it('Should add a server blocklist', async function () {
62 blocklistServer.replace({
65 value: 'localhost:' + servers[1].port
72 const res = await getVideosList(servers[0].url)
73 expect(res.body.total).to.equal(1)
76 it('Should remove a server blocklist', async function () {
79 blocklistServer.replace({
82 value: 'localhost:' + servers[1].port,
90 const res = await getVideosList(servers[0].url)
91 expect(res.body.total).to.equal(2)
94 it('Should add an account blocklist', async function () {
97 blocklistServer.replace({
100 value: 'root@localhost:' + servers[1].port
107 const res = await getVideosList(servers[0].url)
108 expect(res.body.total).to.equal(1)
111 it('Should remove an account blocklist', async function () {
114 blocklistServer.replace({
117 value: 'root@localhost:' + servers[1].port,
125 const res = await getVideosList(servers[0].url)
126 expect(res.body.total).to.equal(2)
129 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
132 const account = 'root@localhost:' + servers[1].port
134 blocklistServer.replace({
138 updatedAt: new Date().toISOString()
146 const res = await getVideosList(servers[0].url)
147 expect(res.body.total).to.equal(1)
150 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, account)
153 const res = await getVideosList(servers[0].url)
154 expect(res.body.total).to.equal(2)
157 killallServers([ servers[0] ])
158 await reRunServer(servers[0])
162 const res = await getVideosList(servers[0].url)
163 expect(res.body.total).to.equal(2)
167 it('Should not expose the auto mute list', async function () {
168 await makeGetRequest({
170 path: '/plugins/auto-mute/router/api/v1/mute-list',
171 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
175 it('Should enable auto mute list', async function () {
176 await servers[0].pluginsCommand.updateSettings({
177 npmName: 'peertube-plugin-auto-mute',
179 'blocklist-urls': '',
180 'check-seconds-interval': 1,
181 'expose-mute-list': true
185 await makeGetRequest({
187 path: '/plugins/auto-mute/router/api/v1/mute-list',
188 statusCodeExpected: HttpStatusCode.OK_200
192 it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
195 await servers[1].pluginsCommand.updateSettings({
196 npmName: 'peertube-plugin-auto-mute',
198 'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath,
199 'check-seconds-interval': 1,
200 'expose-mute-list': false
204 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)
205 await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
207 const res = await makeGetRequest({
209 path: '/plugins/auto-mute/router/api/v1/mute-list',
210 statusCodeExpected: HttpStatusCode.OK_200
213 const data = res.body.data
214 expect(data).to.have.lengthOf(1)
215 expect(data[0].updatedAt).to.exist
216 expect(data[0].value).to.equal('root@localhost:' + servers[1].port)
220 for (const server of servers) {
221 const res = await getVideosList(server.url)
222 expect(res.body.total).to.equal(1)
226 after(async function () {
227 await blocklistServer.terminate()
229 await cleanupTests(servers)