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'
20 function postCommand (server: ServerInfo, command: string, bodyArg?: object) {
21 const body = { command }
22 if (bodyArg) Object.assign(body, bodyArg)
24 return makePostBodyRequest({
26 path: '/plugins/test-four/router/commander',
28 statusCodeExpected: 204
32 describe('Test plugin helpers', function () {
33 let servers: ServerInfo[]
35 before(async function () {
38 servers = await flushAndRunMultipleServers(2)
39 await setAccessTokensToServers(servers)
41 await doubleFollow(servers[0], servers[1])
45 accessToken: servers[0].accessToken,
46 path: getPluginTestPath('-four')
50 describe('Logger', function () {
52 it('Should have logged things', async function () {
53 await waitUntilLog(servers[0], 'localhost:' + servers[0].port + ' peertube-plugin-test-four', 1, false)
54 await waitUntilLog(servers[0], 'Hello world from plugin four', 1)
58 describe('Database', function () {
60 it('Should have made a query', async function () {
61 await waitUntilLog(servers[0], `root email is admin${servers[0].internalServerNumber}@example.com`)
65 describe('Config', function () {
67 it('Should have the correct webserver url', async function () {
68 await waitUntilLog(servers[0], `server url is http://localhost:${servers[0].port}`)
72 describe('Server', function () {
74 it('Should get the server actor', async function () {
75 await waitUntilLog(servers[0], 'server actor name is peertube')
79 describe('Moderation', function () {
80 let videoUUIDServer1: string
82 before(async function () {
86 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
87 videoUUIDServer1 = res.uuid
91 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
94 await waitJobs(servers)
96 const res = await getVideosList(servers[0].url)
97 const videos = res.body.data
99 expect(videos).to.have.lengthOf(2)
102 it('Should mute server 2', async function () {
104 await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` })
106 const res = await getVideosList(servers[0].url)
107 const videos = res.body.data
109 expect(videos).to.have.lengthOf(1)
110 expect(videos[0].name).to.equal('video server 1')
113 it('Should unmute server 2', async function () {
114 await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` })
116 const res = await getVideosList(servers[0].url)
117 const videos = res.body.data
119 expect(videos).to.have.lengthOf(2)
122 it('Should mute account of server 2', async function () {
123 await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` })
125 const res = await getVideosList(servers[0].url)
126 const videos = res.body.data
128 expect(videos).to.have.lengthOf(1)
129 expect(videos[0].name).to.equal('video server 1')
132 it('Should unmute account of server 2', async function () {
133 await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` })
135 const res = await getVideosList(servers[0].url)
136 const videos = res.body.data
138 expect(videos).to.have.lengthOf(2)
141 it('Should blacklist video', async function () {
144 await postCommand(servers[0], 'blacklist', { videoUUID: videoUUIDServer1, unfederate: true })
146 await waitJobs(servers)
148 for (const server of servers) {
149 const res = await getVideosList(server.url)
150 const videos = res.body.data
152 expect(videos).to.have.lengthOf(1)
153 expect(videos[0].name).to.equal('video server 2')
157 it('Should unblacklist video', async function () {
160 await postCommand(servers[0], 'unblacklist', { videoUUID: videoUUIDServer1 })
162 await waitJobs(servers)
164 for (const server of servers) {
165 const res = await getVideosList(server.url)
166 const videos = res.body.data
168 expect(videos).to.have.lengthOf(2)
173 describe('Videos', function () {
174 let videoUUID: string
177 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video1' })
181 it('Should remove a video after a view', async function () {
184 // Should not throw -> video exists
185 await getVideo(servers[0].url, videoUUID)
186 // Should delete the video
187 await viewVideo(servers[0].url, videoUUID)
189 await waitUntilLog(servers[0], 'Video deleted by plugin four.')
192 // Should throw because the video should have been deleted
193 await getVideo(servers[0].url, videoUUID)
194 throw new Error('Video exists')
196 if (err.message.includes('exists')) throw err
199 await checkVideoFilesWereRemoved(videoUUID, servers[0].internalServerNumber)
202 it('Should have fetched the video by URL', async function () {
203 await waitUntilLog(servers[0], `video from DB uuid is ${videoUUID}`)
207 after(async function () {
208 await cleanupTests(servers)