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