1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5 checkVideoFilesWereRemoved,
11 setAccessTokensToServers,
16 } from '../../../shared/extra-utils'
17 import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
18 import { expect } from 'chai'
19 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
21 function postCommand (server: ServerInfo, command: string, bodyArg?: object) {
22 const body = { command }
23 if (bodyArg) Object.assign(body, bodyArg)
25 return makePostBodyRequest({
27 path: '/plugins/test-four/router/commander',
29 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
33 describe('Test plugin helpers', function () {
34 let servers: ServerInfo[]
36 before(async function () {
39 servers = await flushAndRunMultipleServers(2)
40 await setAccessTokensToServers(servers)
42 await doubleFollow(servers[0], servers[1])
46 accessToken: servers[0].accessToken,
47 path: getPluginTestPath('-four')
51 describe('Logger', function () {
53 it('Should have logged things', async function () {
54 await waitUntilLog(servers[0], 'localhost:' + servers[0].port + ' peertube-plugin-test-four', 1, false)
55 await waitUntilLog(servers[0], 'Hello world from plugin four', 1)
59 describe('Database', function () {
61 it('Should have made a query', async function () {
62 await waitUntilLog(servers[0], `root email is admin${servers[0].internalServerNumber}@example.com`)
66 describe('Config', function () {
68 it('Should have the correct webserver url', async function () {
69 await waitUntilLog(servers[0], `server url is http://localhost:${servers[0].port}`)
73 describe('Server', function () {
75 it('Should get the server actor', async function () {
76 await waitUntilLog(servers[0], 'server actor name is peertube')
80 describe('Moderation', function () {
81 let videoUUIDServer1: string
83 before(async function () {
87 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
88 videoUUIDServer1 = res.uuid
92 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
95 await waitJobs(servers)
97 const res = await getVideosList(servers[0].url)
98 const videos = res.body.data
100 expect(videos).to.have.lengthOf(2)
103 it('Should mute server 2', async function () {
105 await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` })
107 const res = await getVideosList(servers[0].url)
108 const videos = res.body.data
110 expect(videos).to.have.lengthOf(1)
111 expect(videos[0].name).to.equal('video server 1')
114 it('Should unmute server 2', async function () {
115 await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` })
117 const res = await getVideosList(servers[0].url)
118 const videos = res.body.data
120 expect(videos).to.have.lengthOf(2)
123 it('Should mute account of server 2', async function () {
124 await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` })
126 const res = await getVideosList(servers[0].url)
127 const videos = res.body.data
129 expect(videos).to.have.lengthOf(1)
130 expect(videos[0].name).to.equal('video server 1')
133 it('Should unmute account of server 2', async function () {
134 await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` })
136 const res = await getVideosList(servers[0].url)
137 const videos = res.body.data
139 expect(videos).to.have.lengthOf(2)
142 it('Should blacklist video', async function () {
145 await postCommand(servers[0], 'blacklist', { videoUUID: videoUUIDServer1, unfederate: true })
147 await waitJobs(servers)
149 for (const server of servers) {
150 const res = await getVideosList(server.url)
151 const videos = res.body.data
153 expect(videos).to.have.lengthOf(1)
154 expect(videos[0].name).to.equal('video server 2')
158 it('Should unblacklist video', async function () {
161 await postCommand(servers[0], 'unblacklist', { videoUUID: videoUUIDServer1 })
163 await waitJobs(servers)
165 for (const server of servers) {
166 const res = await getVideosList(server.url)
167 const videos = res.body.data
169 expect(videos).to.have.lengthOf(2)
174 describe('Videos', function () {
175 let videoUUID: string
178 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video1' })
182 it('Should remove a video after a view', async function () {
185 // Should not throw -> video exists
186 await getVideo(servers[0].url, videoUUID)
187 // Should delete the video
188 await viewVideo(servers[0].url, videoUUID)
190 await waitUntilLog(servers[0], 'Video deleted by plugin four.')
193 // Should throw because the video should have been deleted
194 await getVideo(servers[0].url, videoUUID)
195 throw new Error('Video exists')
197 if (err.message.includes('exists')) throw err
200 await checkVideoFilesWereRemoved(videoUUID, servers[0].internalServerNumber)
203 it('Should have fetched the video by URL', async function () {
204 await waitUntilLog(servers[0], `video from DB uuid is ${videoUUID}`)
208 after(async function () {
209 await cleanupTests(servers)