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
35 before(async function () {
38 servers = await flushAndRunMultipleServers(2)
39 await setAccessTokensToServers(servers)
41 for (const server of servers) {
44 accessToken: server.accessToken,
45 npmName: 'peertube-plugin-auto-mute'
49 blocklistServer = new MockBlocklist()
50 await blocklistServer.initialize()
52 await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
53 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
55 await doubleFollow(servers[0], servers[1])
58 it('Should update plugin settings', async function () {
59 await updatePluginSettings({
61 accessToken: servers[0].accessToken,
62 npmName: 'peertube-plugin-auto-mute',
64 'blocklist-urls': 'http://localhost:42100/blocklist',
65 'check-seconds-interval': 1
70 it('Should add a server blocklist', async function () {
73 blocklistServer.replace({
76 value: 'localhost:' + servers[1].port
83 const res = await getVideosList(servers[0].url)
84 expect(res.body.total).to.equal(1)
87 it('Should remove a server blocklist', async function () {
90 blocklistServer.replace({
93 value: 'localhost:' + servers[1].port,
101 const res = await getVideosList(servers[0].url)
102 expect(res.body.total).to.equal(2)
105 it('Should add an account blocklist', async function () {
108 blocklistServer.replace({
111 value: 'root@localhost:' + servers[1].port
118 const res = await getVideosList(servers[0].url)
119 expect(res.body.total).to.equal(1)
122 it('Should remove an account blocklist', async function () {
125 blocklistServer.replace({
128 value: 'root@localhost:' + servers[1].port,
136 const res = await getVideosList(servers[0].url)
137 expect(res.body.total).to.equal(2)
140 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
143 const account = 'root@localhost:' + servers[1].port
145 blocklistServer.replace({
149 updatedAt: new Date().toISOString()
157 const res = await getVideosList(servers[0].url)
158 expect(res.body.total).to.equal(1)
161 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, account)
164 const res = await getVideosList(servers[0].url)
165 expect(res.body.total).to.equal(2)
168 killallServers([ servers[0] ])
169 await reRunServer(servers[0])
173 const res = await getVideosList(servers[0].url)
174 expect(res.body.total).to.equal(2)
178 it('Should not expose the auto mute list', async function () {
179 await makeGetRequest({
181 path: '/plugins/auto-mute/router/api/v1/mute-list',
182 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
186 it('Should enable auto mute list', async function () {
187 await updatePluginSettings({
189 accessToken: servers[0].accessToken,
190 npmName: 'peertube-plugin-auto-mute',
192 'blocklist-urls': '',
193 'check-seconds-interval': 1,
194 'expose-mute-list': true
198 await makeGetRequest({
200 path: '/plugins/auto-mute/router/api/v1/mute-list',
201 statusCodeExpected: HttpStatusCode.OK_200
205 it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
208 await updatePluginSettings({
210 accessToken: servers[1].accessToken,
211 npmName: 'peertube-plugin-auto-mute',
213 'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath,
214 'check-seconds-interval': 1,
215 'expose-mute-list': false
219 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)
220 await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
222 const res = await makeGetRequest({
224 path: '/plugins/auto-mute/router/api/v1/mute-list',
225 statusCodeExpected: HttpStatusCode.OK_200
228 const data = res.body.data
229 expect(data).to.have.lengthOf(1)
230 expect(data[0].updatedAt).to.exist
231 expect(data[0].value).to.equal('root@localhost:' + servers[1].port)
235 for (const server of servers) {
236 const res = await getVideosList(server.url)
237 expect(res.body.total).to.equal(1)
241 after(async function () {
242 await blocklistServer.terminate()
244 await cleanupTests(servers)