]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/plugins/plugin-helpers.ts
Handle views for live videos
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / plugin-helpers.ts
CommitLineData
1b05d82d
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
1b05d82d 3import 'mocha'
ab3ead3a
C
4import {
5 checkVideoFilesWereRemoved,
80fdaf06 6 doubleFollow,
ab3ead3a
C
7 getPluginTestPath,
8 getVideo,
9 installPlugin,
80fdaf06 10 makePostBodyRequest,
ab3ead3a
C
11 setAccessTokensToServers,
12 uploadVideoAndGetId,
80fdaf06
C
13 viewVideo,
14 getVideosList,
15 waitJobs
ab3ead3a 16} from '../../../shared/extra-utils'
80fdaf06
C
17import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
18import { expect } from 'chai'
19
20function 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}
1b05d82d
C
31
32describe('Test plugin helpers', function () {
80fdaf06 33 let servers: ServerInfo[]
1b05d82d
C
34
35 before(async function () {
80fdaf06
C
36 this.timeout(60000)
37
38 servers = await flushAndRunMultipleServers(2)
39 await setAccessTokensToServers(servers)
1b05d82d 40
80fdaf06 41 await doubleFollow(servers[0], servers[1])
1b05d82d
C
42
43 await installPlugin({
80fdaf06
C
44 url: servers[0].url,
45 accessToken: servers[0].accessToken,
1b05d82d
C
46 path: getPluginTestPath('-four')
47 })
48 })
49
80fdaf06
C
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 })
1b05d82d
C
56 })
57
80fdaf06
C
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(15000)
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 })
1b05d82d
C
171 })
172
80fdaf06
C
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 })
ab3ead3a 180
80fdaf06
C
181 it('Should remove a video after a view', async function () {
182 this.timeout(20000)
ab3ead3a 183
80fdaf06
C
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)
ab3ead3a 188
80fdaf06 189 await waitUntilLog(servers[0], 'Video deleted by plugin four.')
ab3ead3a 190
80fdaf06
C
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 }
ab3ead3a 198
80fdaf06
C
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 })
ab3ead3a
C
205 })
206
1b05d82d 207 after(async function () {
80fdaf06 208 await cleanupTests(servers)
1b05d82d
C
209 })
210})