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'
29 describe('Official plugin auto-mute', function () {
30 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
31 let servers: ServerInfo[]
32 let blocklistServer: MockBlocklist
34 before(async function () {
37 servers = await flushAndRunMultipleServers(2)
38 await setAccessTokensToServers(servers)
40 for (const server of servers) {
43 accessToken: server.accessToken,
44 npmName: 'peertube-plugin-auto-mute'
48 blocklistServer = new MockBlocklist()
49 await blocklistServer.initialize()
51 await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
52 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
54 await doubleFollow(servers[0], servers[1])
57 it('Should update plugin settings', async function () {
58 await updatePluginSettings({
60 accessToken: servers[0].accessToken,
61 npmName: 'peertube-plugin-auto-mute',
63 'blocklist-urls': 'http://localhost:42100/blocklist',
64 'check-seconds-interval': 1
69 it('Should add a server blocklist', async function () {
72 blocklistServer.replace({
75 value: 'localhost:' + servers[1].port
82 const res = await getVideosList(servers[0].url)
83 expect(res.body.total).to.equal(1)
86 it('Should remove a server blocklist', async function () {
89 blocklistServer.replace({
92 value: 'localhost:' + servers[1].port,
100 const res = await getVideosList(servers[0].url)
101 expect(res.body.total).to.equal(2)
104 it('Should add an account blocklist', async function () {
107 blocklistServer.replace({
110 value: 'root@localhost:' + servers[1].port
117 const res = await getVideosList(servers[0].url)
118 expect(res.body.total).to.equal(1)
121 it('Should remove an account blocklist', async function () {
124 blocklistServer.replace({
127 value: 'root@localhost:' + servers[1].port,
135 const res = await getVideosList(servers[0].url)
136 expect(res.body.total).to.equal(2)
139 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
142 const account = 'root@localhost:' + servers[1].port
144 blocklistServer.replace({
148 updatedAt: new Date().toISOString()
156 const res = await getVideosList(servers[0].url)
157 expect(res.body.total).to.equal(1)
160 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, account)
163 const res = await getVideosList(servers[0].url)
164 expect(res.body.total).to.equal(2)
167 killallServers([ servers[0] ])
168 await reRunServer(servers[0])
172 const res = await getVideosList(servers[0].url)
173 expect(res.body.total).to.equal(2)
177 it('Should not expose the auto mute list', async function () {
178 await makeGetRequest({
180 path: '/plugins/auto-mute/router/api/v1/mute-list',
181 statusCodeExpected: 403
185 it('Should enable auto mute list', async function () {
186 await updatePluginSettings({
188 accessToken: servers[0].accessToken,
189 npmName: 'peertube-plugin-auto-mute',
191 'blocklist-urls': '',
192 'check-seconds-interval': 1,
193 'expose-mute-list': true
197 await makeGetRequest({
199 path: '/plugins/auto-mute/router/api/v1/mute-list',
200 statusCodeExpected: 200
204 it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
207 await updatePluginSettings({
209 accessToken: servers[1].accessToken,
210 npmName: 'peertube-plugin-auto-mute',
212 'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath,
213 'check-seconds-interval': 1,
214 'expose-mute-list': false
218 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)
219 await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
221 const res = await makeGetRequest({
223 path: '/plugins/auto-mute/router/api/v1/mute-list',
224 statusCodeExpected: 200
227 const data = res.body.data
228 expect(data).to.have.lengthOf(1)
229 expect(data[0].updatedAt).to.exist
230 expect(data[0].value).to.equal('root@localhost:' + servers[1].port)
234 for (const server of servers) {
235 const res = await getVideosList(server.url)
236 expect(res.body.total).to.equal(1)
240 after(async function () {
241 await blocklistServer.terminate()
243 await cleanupTests(servers)