diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-08 16:49:51 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | 6910f20f114b5bd020258a3a9a3f2117819a60c2 (patch) | |
tree | 0f50d33e20814b581dd9b2c175e511ac7a66f8df /server/tests/plugins | |
parent | 313228e9c3b5bcef5391228c9b949d05d32ad7bb (diff) | |
download | PeerTube-6910f20f114b5bd020258a3a9a3f2117819a60c2.tar.gz PeerTube-6910f20f114b5bd020258a3a9a3f2117819a60c2.tar.zst PeerTube-6910f20f114b5bd020258a3a9a3f2117819a60c2.zip |
Introduce import command
Diffstat (limited to 'server/tests/plugins')
-rw-r--r-- | server/tests/plugins/filter-hooks.ts | 67 |
1 files changed, 28 insertions, 39 deletions
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 203642d8d..a3c3c0551 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts | |||
@@ -18,6 +18,7 @@ import { | |||
18 | getVideosListPagination, | 18 | getVideosListPagination, |
19 | getVideoThreadComments, | 19 | getVideoThreadComments, |
20 | getVideoWithToken, | 20 | getVideoWithToken, |
21 | ImportsCommand, | ||
21 | makeRawRequest, | 22 | makeRawRequest, |
22 | PluginsCommand, | 23 | PluginsCommand, |
23 | registerUser, | 24 | registerUser, |
@@ -30,16 +31,7 @@ import { | |||
30 | waitJobs, | 31 | waitJobs, |
31 | waitUntilLog | 32 | waitUntilLog |
32 | } from '@shared/extra-utils' | 33 | } from '@shared/extra-utils' |
33 | import { getGoodVideoUrl, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports' | 34 | import { VideoCommentThreadTree, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' |
34 | import { | ||
35 | VideoCommentThreadTree, | ||
36 | VideoDetails, | ||
37 | VideoImport, | ||
38 | VideoImportState, | ||
39 | VideoPlaylist, | ||
40 | VideoPlaylistPrivacy, | ||
41 | VideoPrivacy | ||
42 | } from '@shared/models' | ||
43 | 35 | ||
44 | const expect = chai.expect | 36 | const expect = chai.expect |
45 | 37 | ||
@@ -157,23 +149,23 @@ describe('Test plugin filter hooks', function () { | |||
157 | }) | 149 | }) |
158 | 150 | ||
159 | it('Should run filter:api.video.pre-import-url.accept.result', async function () { | 151 | it('Should run filter:api.video.pre-import-url.accept.result', async function () { |
160 | const baseAttributes = { | 152 | const attributes = { |
161 | name: 'normal title', | 153 | name: 'normal title', |
162 | privacy: VideoPrivacy.PUBLIC, | 154 | privacy: VideoPrivacy.PUBLIC, |
163 | channelId: servers[0].videoChannel.id, | 155 | channelId: servers[0].videoChannel.id, |
164 | targetUrl: getGoodVideoUrl() + 'bad' | 156 | targetUrl: ImportsCommand.getGoodVideoUrl() + 'bad' |
165 | } | 157 | } |
166 | await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) | 158 | await servers[0].importsCommand.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
167 | }) | 159 | }) |
168 | 160 | ||
169 | it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { | 161 | it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { |
170 | const baseAttributes = { | 162 | const attributes = { |
171 | name: 'bad torrent', | 163 | name: 'bad torrent', |
172 | privacy: VideoPrivacy.PUBLIC, | 164 | privacy: VideoPrivacy.PUBLIC, |
173 | channelId: servers[0].videoChannel.id, | 165 | channelId: servers[0].videoChannel.id, |
174 | torrentfile: 'video-720p.torrent' as any | 166 | torrentfile: 'video-720p.torrent' as any |
175 | } | 167 | } |
176 | await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) | 168 | await servers[0].importsCommand.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
177 | }) | 169 | }) |
178 | 170 | ||
179 | it('Should run filter:api.video.post-import-url.accept.result', async function () { | 171 | it('Should run filter:api.video.post-import-url.accept.result', async function () { |
@@ -182,21 +174,21 @@ describe('Test plugin filter hooks', function () { | |||
182 | let videoImportId: number | 174 | let videoImportId: number |
183 | 175 | ||
184 | { | 176 | { |
185 | const baseAttributes = { | 177 | const attributes = { |
186 | name: 'title with bad word', | 178 | name: 'title with bad word', |
187 | privacy: VideoPrivacy.PUBLIC, | 179 | privacy: VideoPrivacy.PUBLIC, |
188 | channelId: servers[0].videoChannel.id, | 180 | channelId: servers[0].videoChannel.id, |
189 | targetUrl: getGoodVideoUrl() | 181 | targetUrl: ImportsCommand.getGoodVideoUrl() |
190 | } | 182 | } |
191 | const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) | 183 | const body = await servers[0].importsCommand.importVideo({ attributes }) |
192 | videoImportId = res.body.id | 184 | videoImportId = body.id |
193 | } | 185 | } |
194 | 186 | ||
195 | await waitJobs(servers) | 187 | await waitJobs(servers) |
196 | 188 | ||
197 | { | 189 | { |
198 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) | 190 | const body = await servers[0].importsCommand.getMyVideoImports() |
199 | const videoImports = res.body.data as VideoImport[] | 191 | const videoImports = body.data |
200 | 192 | ||
201 | const videoImport = videoImports.find(i => i.id === videoImportId) | 193 | const videoImport = videoImports.find(i => i.id === videoImportId) |
202 | 194 | ||
@@ -211,21 +203,20 @@ describe('Test plugin filter hooks', function () { | |||
211 | let videoImportId: number | 203 | let videoImportId: number |
212 | 204 | ||
213 | { | 205 | { |
214 | const baseAttributes = { | 206 | const attributes = { |
215 | name: 'title with bad word', | 207 | name: 'title with bad word', |
216 | privacy: VideoPrivacy.PUBLIC, | 208 | privacy: VideoPrivacy.PUBLIC, |
217 | channelId: servers[0].videoChannel.id, | 209 | channelId: servers[0].videoChannel.id, |
218 | torrentfile: 'video-720p.torrent' as any | 210 | torrentfile: 'video-720p.torrent' as any |
219 | } | 211 | } |
220 | const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) | 212 | const body = await servers[0].importsCommand.importVideo({ attributes }) |
221 | videoImportId = res.body.id | 213 | videoImportId = body.id |
222 | } | 214 | } |
223 | 215 | ||
224 | await waitJobs(servers) | 216 | await waitJobs(servers) |
225 | 217 | ||
226 | { | 218 | { |
227 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) | 219 | const { data: videoImports } = await servers[0].importsCommand.getMyVideoImports() |
228 | const videoImports = res.body.data as VideoImport[] | ||
229 | 220 | ||
230 | const videoImport = videoImports.find(i => i.id === videoImportId) | 221 | const videoImport = videoImports.find(i => i.id === videoImportId) |
231 | 222 | ||
@@ -278,17 +269,15 @@ describe('Test plugin filter hooks', function () { | |||
278 | 269 | ||
279 | describe('Should run filter:video.auto-blacklist.result', function () { | 270 | describe('Should run filter:video.auto-blacklist.result', function () { |
280 | 271 | ||
281 | async function checkIsBlacklisted (oldRes: any, value: boolean) { | 272 | async function checkIsBlacklisted (id: number | string, value: boolean) { |
282 | const videoId = oldRes.body.video.uuid | 273 | const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id) |
283 | |||
284 | const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId) | ||
285 | const video: VideoDetails = res.body | 274 | const video: VideoDetails = res.body |
286 | expect(video.blacklisted).to.equal(value) | 275 | expect(video.blacklisted).to.equal(value) |
287 | } | 276 | } |
288 | 277 | ||
289 | it('Should blacklist on upload', async function () { | 278 | it('Should blacklist on upload', async function () { |
290 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) | 279 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) |
291 | await checkIsBlacklisted(res, true) | 280 | await checkIsBlacklisted(res.body.video.uuid, true) |
292 | }) | 281 | }) |
293 | 282 | ||
294 | it('Should blacklist on import', async function () { | 283 | it('Should blacklist on import', async function () { |
@@ -296,20 +285,20 @@ describe('Test plugin filter hooks', function () { | |||
296 | 285 | ||
297 | const attributes = { | 286 | const attributes = { |
298 | name: 'video please blacklist me', | 287 | name: 'video please blacklist me', |
299 | targetUrl: getGoodVideoUrl(), | 288 | targetUrl: ImportsCommand.getGoodVideoUrl(), |
300 | channelId: servers[0].videoChannel.id | 289 | channelId: servers[0].videoChannel.id |
301 | } | 290 | } |
302 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | 291 | const body = await servers[0].importsCommand.importVideo({ attributes }) |
303 | await checkIsBlacklisted(res, true) | 292 | await checkIsBlacklisted(body.video.uuid, true) |
304 | }) | 293 | }) |
305 | 294 | ||
306 | it('Should blacklist on update', async function () { | 295 | it('Should blacklist on update', async function () { |
307 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) | 296 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) |
308 | const videoId = res.body.video.uuid | 297 | const videoId = res.body.video.uuid |
309 | await checkIsBlacklisted(res, false) | 298 | await checkIsBlacklisted(videoId, false) |
310 | 299 | ||
311 | await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) | 300 | await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) |
312 | await checkIsBlacklisted(res, true) | 301 | await checkIsBlacklisted(videoId, true) |
313 | }) | 302 | }) |
314 | 303 | ||
315 | it('Should blacklist on remote upload', async function () { | 304 | it('Should blacklist on remote upload', async function () { |
@@ -318,7 +307,7 @@ describe('Test plugin filter hooks', function () { | |||
318 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) | 307 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) |
319 | await waitJobs(servers) | 308 | await waitJobs(servers) |
320 | 309 | ||
321 | await checkIsBlacklisted(res, true) | 310 | await checkIsBlacklisted(res.body.video.uuid, true) |
322 | }) | 311 | }) |
323 | 312 | ||
324 | it('Should blacklist on remote update', async function () { | 313 | it('Should blacklist on remote update', async function () { |
@@ -328,12 +317,12 @@ describe('Test plugin filter hooks', function () { | |||
328 | await waitJobs(servers) | 317 | await waitJobs(servers) |
329 | 318 | ||
330 | const videoId = res.body.video.uuid | 319 | const videoId = res.body.video.uuid |
331 | await checkIsBlacklisted(res, false) | 320 | await checkIsBlacklisted(videoId, false) |
332 | 321 | ||
333 | await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) | 322 | await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) |
334 | await waitJobs(servers) | 323 | await waitJobs(servers) |
335 | 324 | ||
336 | await checkIsBlacklisted(res, true) | 325 | await checkIsBlacklisted(videoId, true) |
337 | }) | 326 | }) |
338 | }) | 327 | }) |
339 | 328 | ||