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,
16 setAccessTokensToServers,
19 } from '@shared/extra-utils'
21 describe('Official plugin auto-mute', function () {
22 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
23 let servers: ServerInfo[]
24 let blocklistServer: MockBlocklist
27 before(async function () {
30 servers = await flushAndRunMultipleServers(2)
31 await setAccessTokensToServers(servers)
33 for (const server of servers) {
34 await server.pluginsCommand.install({ npmName: 'peertube-plugin-auto-mute' })
37 blocklistServer = new MockBlocklist()
38 port = await blocklistServer.initialize()
40 await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
41 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
43 await doubleFollow(servers[0], servers[1])
46 it('Should update plugin settings', async function () {
47 await servers[0].pluginsCommand.updateSettings({
48 npmName: 'peertube-plugin-auto-mute',
50 'blocklist-urls': `http://localhost:${port}/blocklist`,
51 'check-seconds-interval': 1
56 it('Should add a server blocklist', async function () {
59 blocklistServer.replace({
62 value: 'localhost:' + servers[1].port
69 const res = await getVideosList(servers[0].url)
70 expect(res.body.total).to.equal(1)
73 it('Should remove a server blocklist', async function () {
76 blocklistServer.replace({
79 value: 'localhost:' + servers[1].port,
87 const res = await getVideosList(servers[0].url)
88 expect(res.body.total).to.equal(2)
91 it('Should add an account blocklist', async function () {
94 blocklistServer.replace({
97 value: 'root@localhost:' + servers[1].port
104 const res = await getVideosList(servers[0].url)
105 expect(res.body.total).to.equal(1)
108 it('Should remove an account blocklist', async function () {
111 blocklistServer.replace({
114 value: 'root@localhost:' + servers[1].port,
122 const res = await getVideosList(servers[0].url)
123 expect(res.body.total).to.equal(2)
126 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
129 const account = 'root@localhost:' + servers[1].port
131 blocklistServer.replace({
135 updatedAt: new Date().toISOString()
143 const res = await getVideosList(servers[0].url)
144 expect(res.body.total).to.equal(1)
147 await servers[0].blocklistCommand.removeFromServerBlocklist({ account })
150 const res = await getVideosList(servers[0].url)
151 expect(res.body.total).to.equal(2)
154 await killallServers([ servers[0] ])
155 await reRunServer(servers[0])
159 const res = await getVideosList(servers[0].url)
160 expect(res.body.total).to.equal(2)
164 it('Should not expose the auto mute list', async function () {
165 await makeGetRequest({
167 path: '/plugins/auto-mute/router/api/v1/mute-list',
168 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
172 it('Should enable auto mute list', async function () {
173 await servers[0].pluginsCommand.updateSettings({
174 npmName: 'peertube-plugin-auto-mute',
176 'blocklist-urls': '',
177 'check-seconds-interval': 1,
178 'expose-mute-list': true
182 await makeGetRequest({
184 path: '/plugins/auto-mute/router/api/v1/mute-list',
185 statusCodeExpected: HttpStatusCode.OK_200
189 it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
192 await servers[1].pluginsCommand.updateSettings({
193 npmName: 'peertube-plugin-auto-mute',
195 'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath,
196 'check-seconds-interval': 1,
197 'expose-mute-list': false
201 await servers[0].blocklistCommand.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port })
202 await servers[0].blocklistCommand.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
204 const res = await makeGetRequest({
206 path: '/plugins/auto-mute/router/api/v1/mute-list',
207 statusCodeExpected: HttpStatusCode.OK_200
210 const data = res.body.data
211 expect(data).to.have.lengthOf(1)
212 expect(data[0].updatedAt).to.exist
213 expect(data[0].value).to.equal('root@localhost:' + servers[1].port)
217 for (const server of servers) {
218 const res = await getVideosList(server.url)
219 expect(res.body.total).to.equal(1)
223 after(async function () {
224 await blocklistServer.terminate()
226 await cleanupTests(servers)