1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5 checkVideoFilesWereRemoved,
11 setAccessTokensToServers,
17 } from '../../../shared/extra-utils'
18 import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
19 import { expect } from 'chai'
20 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
22 function postCommand (server: ServerInfo, command: string, bodyArg?: object) {
23 const body = { command }
24 if (bodyArg) Object.assign(body, bodyArg)
26 return makePostBodyRequest({
28 path: '/plugins/test-four/router/commander',
30 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
34 describe('Test plugin helpers', function () {
35 let servers: ServerInfo[]
37 before(async function () {
40 servers = await flushAndRunMultipleServers(2)
41 await setAccessTokensToServers(servers)
43 await doubleFollow(servers[0], servers[1])
47 accessToken: servers[0].accessToken,
48 path: getPluginTestPath('-four')
52 describe('Logger', function () {
54 it('Should have logged things', async function () {
55 await waitUntilLog(servers[0], 'localhost:' + servers[0].port + ' peertube-plugin-test-four', 1, false)
56 await waitUntilLog(servers[0], 'Hello world from plugin four', 1)
60 describe('Database', function () {
62 it('Should have made a query', async function () {
63 await waitUntilLog(servers[0], `root email is admin${servers[0].internalServerNumber}@example.com`)
67 describe('Config', function () {
69 it('Should have the correct webserver url', async function () {
70 await waitUntilLog(servers[0], `server url is http://localhost:${servers[0].port}`)
73 it('Should have the correct config', async function () {
74 const res = await makeGetRequest({
76 path: '/plugins/test-four/router/server-config',
77 statusCodeExpected: HttpStatusCode.OK_200
80 expect(res.body.serverConfig).to.exist
81 expect(res.body.serverConfig.instance.name).to.equal('PeerTube')
85 describe('Server', function () {
87 it('Should get the server actor', async function () {
88 await waitUntilLog(servers[0], 'server actor name is peertube')
92 describe('Plugin', function () {
94 it('Should get the base static route', async function () {
95 const res = await makeGetRequest({
97 path: '/plugins/test-four/router/static-route',
98 statusCodeExpected: HttpStatusCode.OK_200
101 expect(res.body.staticRoute).to.equal('/plugins/test-four/0.0.1/static/')
105 describe('Moderation', function () {
106 let videoUUIDServer1: string
108 before(async function () {
112 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
113 videoUUIDServer1 = res.uuid
117 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
120 await waitJobs(servers)
122 const res = await getVideosList(servers[0].url)
123 const videos = res.body.data
125 expect(videos).to.have.lengthOf(2)
128 it('Should mute server 2', async function () {
130 await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` })
132 const res = await getVideosList(servers[0].url)
133 const videos = res.body.data
135 expect(videos).to.have.lengthOf(1)
136 expect(videos[0].name).to.equal('video server 1')
139 it('Should unmute server 2', async function () {
140 await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` })
142 const res = await getVideosList(servers[0].url)
143 const videos = res.body.data
145 expect(videos).to.have.lengthOf(2)
148 it('Should mute account of server 2', async function () {
149 await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` })
151 const res = await getVideosList(servers[0].url)
152 const videos = res.body.data
154 expect(videos).to.have.lengthOf(1)
155 expect(videos[0].name).to.equal('video server 1')
158 it('Should unmute account of server 2', async function () {
159 await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` })
161 const res = await getVideosList(servers[0].url)
162 const videos = res.body.data
164 expect(videos).to.have.lengthOf(2)
167 it('Should blacklist video', async function () {
170 await postCommand(servers[0], 'blacklist', { videoUUID: videoUUIDServer1, unfederate: true })
172 await waitJobs(servers)
174 for (const server of servers) {
175 const res = await getVideosList(server.url)
176 const videos = res.body.data
178 expect(videos).to.have.lengthOf(1)
179 expect(videos[0].name).to.equal('video server 2')
183 it('Should unblacklist video', async function () {
186 await postCommand(servers[0], 'unblacklist', { videoUUID: videoUUIDServer1 })
188 await waitJobs(servers)
190 for (const server of servers) {
191 const res = await getVideosList(server.url)
192 const videos = res.body.data
194 expect(videos).to.have.lengthOf(2)
199 describe('Videos', function () {
200 let videoUUID: string
203 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video1' })
207 it('Should remove a video after a view', async function () {
210 // Should not throw -> video exists
211 await getVideo(servers[0].url, videoUUID)
212 // Should delete the video
213 await viewVideo(servers[0].url, videoUUID)
215 await waitUntilLog(servers[0], 'Video deleted by plugin four.')
218 // Should throw because the video should have been deleted
219 await getVideo(servers[0].url, videoUUID)
220 throw new Error('Video exists')
222 if (err.message.includes('exists')) throw err
225 await checkVideoFilesWereRemoved(videoUUID, servers[0].internalServerNumber)
228 it('Should have fetched the video by URL', async function () {
229 await waitUntilLog(servers[0], `video from DB uuid is ${videoUUID}`)
233 after(async function () {
234 await cleanupTests(servers)