]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/plugins/plugin-helpers.ts
Update ffmpeg static version for tests
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / plugin-helpers.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import {
5 checkVideoFilesWereRemoved,
6 doubleFollow,
7 getPluginTestPath,
8 getVideo,
9 installPlugin,
10 makePostBodyRequest,
11 setAccessTokensToServers,
12 uploadVideoAndGetId,
13 viewVideo,
14 getVideosList,
15 waitJobs
16 } from '../../../shared/extra-utils'
17 import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
18 import { expect } from 'chai'
19
20 function postCommand (server: ServerInfo, command: string, bodyArg?: object) {
21 const body = { command }
22 if (bodyArg) Object.assign(body, bodyArg)
23
24 return makePostBodyRequest({
25 url: server.url,
26 path: '/plugins/test-four/router/commander',
27 fields: body,
28 statusCodeExpected: 204
29 })
30 }
31
32 describe('Test plugin helpers', function () {
33 let servers: ServerInfo[]
34
35 before(async function () {
36 this.timeout(60000)
37
38 servers = await flushAndRunMultipleServers(2)
39 await setAccessTokensToServers(servers)
40
41 await doubleFollow(servers[0], servers[1])
42
43 await installPlugin({
44 url: servers[0].url,
45 accessToken: servers[0].accessToken,
46 path: getPluginTestPath('-four')
47 })
48 })
49
50 describe('Logger', function () {
51
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)
55 })
56 })
57
58 describe('Database', function () {
59
60 it('Should have made a query', async function () {
61 await waitUntilLog(servers[0], `root email is admin${servers[0].internalServerNumber}@example.com`)
62 })
63 })
64
65 describe('Config', function () {
66
67 it('Should have the correct webserver url', async function () {
68 await waitUntilLog(servers[0], `server url is http://localhost:${servers[0].port}`)
69 })
70 })
71
72 describe('Server', function () {
73
74 it('Should get the server actor', async function () {
75 await waitUntilLog(servers[0], 'server actor name is peertube')
76 })
77 })
78
79 describe('Moderation', function () {
80 let videoUUIDServer1: string
81
82 before(async function () {
83 this.timeout(30000)
84
85 {
86 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
87 videoUUIDServer1 = res.uuid
88 }
89
90 {
91 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
92 }
93
94 await waitJobs(servers)
95
96 const res = await getVideosList(servers[0].url)
97 const videos = res.body.data
98
99 expect(videos).to.have.lengthOf(2)
100 })
101
102 it('Should mute server 2', async function () {
103 this.timeout(10000)
104 await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` })
105
106 const res = await getVideosList(servers[0].url)
107 const videos = res.body.data
108
109 expect(videos).to.have.lengthOf(1)
110 expect(videos[0].name).to.equal('video server 1')
111 })
112
113 it('Should unmute server 2', async function () {
114 await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` })
115
116 const res = await getVideosList(servers[0].url)
117 const videos = res.body.data
118
119 expect(videos).to.have.lengthOf(2)
120 })
121
122 it('Should mute account of server 2', async function () {
123 await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` })
124
125 const res = await getVideosList(servers[0].url)
126 const videos = res.body.data
127
128 expect(videos).to.have.lengthOf(1)
129 expect(videos[0].name).to.equal('video server 1')
130 })
131
132 it('Should unmute account of server 2', async function () {
133 await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` })
134
135 const res = await getVideosList(servers[0].url)
136 const videos = res.body.data
137
138 expect(videos).to.have.lengthOf(2)
139 })
140
141 it('Should blacklist video', async function () {
142 this.timeout(10000)
143
144 await postCommand(servers[0], 'blacklist', { videoUUID: videoUUIDServer1, unfederate: true })
145
146 await waitJobs(servers)
147
148 for (const server of servers) {
149 const res = await getVideosList(server.url)
150 const videos = res.body.data
151
152 expect(videos).to.have.lengthOf(1)
153 expect(videos[0].name).to.equal('video server 2')
154 }
155 })
156
157 it('Should unblacklist video', async function () {
158 this.timeout(10000)
159
160 await postCommand(servers[0], 'unblacklist', { videoUUID: videoUUIDServer1 })
161
162 await waitJobs(servers)
163
164 for (const server of servers) {
165 const res = await getVideosList(server.url)
166 const videos = res.body.data
167
168 expect(videos).to.have.lengthOf(2)
169 }
170 })
171 })
172
173 describe('Videos', function () {
174 let videoUUID: string
175
176 before(async () => {
177 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video1' })
178 videoUUID = res.uuid
179 })
180
181 it('Should remove a video after a view', async function () {
182 this.timeout(20000)
183
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)
188
189 await waitUntilLog(servers[0], 'Video deleted by plugin four.')
190
191 try {
192 // Should throw because the video should have been deleted
193 await getVideo(servers[0].url, videoUUID)
194 throw new Error('Video exists')
195 } catch (err) {
196 if (err.message.includes('exists')) throw err
197 }
198
199 await checkVideoFilesWereRemoved(videoUUID, servers[0].internalServerNumber)
200 })
201
202 it('Should have fetched the video by URL', async function () {
203 await waitUntilLog(servers[0], `video from DB uuid is ${videoUUID}`)
204 })
205 })
206
207 after(async function () {
208 await cleanupTests(servers)
209 })
210 })