aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/filter-hooks.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/plugins/filter-hooks.ts')
-rw-r--r--server/tests/plugins/filter-hooks.ts94
1 files changed, 39 insertions, 55 deletions
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index c82025f6a..e82aa3bfb 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -7,22 +7,12 @@ import {
7 cleanupTests, 7 cleanupTests,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 getAccountVideos,
11 getMyVideos,
12 getVideo,
13 getVideoChannelVideos,
14 getVideosList,
15 getVideosListPagination,
16 getVideoWithToken,
17 ImportsCommand, 10 ImportsCommand,
18 makeRawRequest, 11 makeRawRequest,
19 PluginsCommand, 12 PluginsCommand,
20 ServerInfo, 13 ServerInfo,
21 setAccessTokensToServers, 14 setAccessTokensToServers,
22 setDefaultVideoChannel, 15 setDefaultVideoChannel,
23 updateVideo,
24 uploadVideo,
25 uploadVideoAndGetId,
26 waitJobs 16 waitJobs
27} from '@shared/extra-utils' 17} from '@shared/extra-utils'
28import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' 18import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
@@ -46,11 +36,11 @@ describe('Test plugin filter hooks', function () {
46 await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) 36 await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') })
47 37
48 for (let i = 0; i < 10; i++) { 38 for (let i = 0; i < 10; i++) {
49 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) 39 await servers[0].videosCommand.upload({ attributes: { name: 'default video ' + i } })
50 } 40 }
51 41
52 const res = await getVideosList(servers[0].url) 42 const { data } = await servers[0].videosCommand.list()
53 videoUUID = res.body.data[0].uuid 43 videoUUID = data[0].uuid
54 44
55 await servers[0].configCommand.updateCustomSubConfig({ 45 await servers[0].configCommand.updateCustomSubConfig({
56 newConfig: { 46 newConfig: {
@@ -67,69 +57,68 @@ describe('Test plugin filter hooks', function () {
67 }) 57 })
68 58
69 it('Should run filter:api.videos.list.params', async function () { 59 it('Should run filter:api.videos.list.params', async function () {
70 const res = await getVideosListPagination(servers[0].url, 0, 2) 60 const { data } = await servers[0].videosCommand.list({ start: 0, count: 2 })
71 61
72 // 2 plugins do +1 to the count parameter 62 // 2 plugins do +1 to the count parameter
73 expect(res.body.data).to.have.lengthOf(4) 63 expect(data).to.have.lengthOf(4)
74 }) 64 })
75 65
76 it('Should run filter:api.videos.list.result', async function () { 66 it('Should run filter:api.videos.list.result', async function () {
77 const res = await getVideosListPagination(servers[0].url, 0, 0) 67 const { total } = await servers[0].videosCommand.list({ start: 0, count: 0 })
78 68
79 // Plugin do +1 to the total result 69 // Plugin do +1 to the total result
80 expect(res.body.total).to.equal(11) 70 expect(total).to.equal(11)
81 }) 71 })
82 72
83 it('Should run filter:api.accounts.videos.list.params', async function () { 73 it('Should run filter:api.accounts.videos.list.params', async function () {
84 const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) 74 const { data } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 })
85 75
86 // 1 plugin do +1 to the count parameter 76 // 1 plugin do +1 to the count parameter
87 expect(res.body.data).to.have.lengthOf(3) 77 expect(data).to.have.lengthOf(3)
88 }) 78 })
89 79
90 it('Should run filter:api.accounts.videos.list.result', async function () { 80 it('Should run filter:api.accounts.videos.list.result', async function () {
91 const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) 81 const { total } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 })
92 82
93 // Plugin do +2 to the total result 83 // Plugin do +2 to the total result
94 expect(res.body.total).to.equal(12) 84 expect(total).to.equal(12)
95 }) 85 })
96 86
97 it('Should run filter:api.video-channels.videos.list.params', async function () { 87 it('Should run filter:api.video-channels.videos.list.params', async function () {
98 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) 88 const { data } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 })
99 89
100 // 1 plugin do +3 to the count parameter 90 // 1 plugin do +3 to the count parameter
101 expect(res.body.data).to.have.lengthOf(5) 91 expect(data).to.have.lengthOf(5)
102 }) 92 })
103 93
104 it('Should run filter:api.video-channels.videos.list.result', async function () { 94 it('Should run filter:api.video-channels.videos.list.result', async function () {
105 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) 95 const { total } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 })
106 96
107 // Plugin do +3 to the total result 97 // Plugin do +3 to the total result
108 expect(res.body.total).to.equal(13) 98 expect(total).to.equal(13)
109 }) 99 })
110 100
111 it('Should run filter:api.user.me.videos.list.params', async function () { 101 it('Should run filter:api.user.me.videos.list.params', async function () {
112 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) 102 const { data } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 })
113 103
114 // 1 plugin do +4 to the count parameter 104 // 1 plugin do +4 to the count parameter
115 expect(res.body.data).to.have.lengthOf(6) 105 expect(data).to.have.lengthOf(6)
116 }) 106 })
117 107
118 it('Should run filter:api.user.me.videos.list.result', async function () { 108 it('Should run filter:api.user.me.videos.list.result', async function () {
119 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) 109 const { total } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 })
120 110
121 // Plugin do +4 to the total result 111 // Plugin do +4 to the total result
122 expect(res.body.total).to.equal(14) 112 expect(total).to.equal(14)
123 }) 113 })
124 114
125 it('Should run filter:api.video.get.result', async function () { 115 it('Should run filter:api.video.get.result', async function () {
126 const res = await getVideo(servers[0].url, videoUUID) 116 const video = await servers[0].videosCommand.get({ id: videoUUID })
127 117 expect(video.name).to.contain('<3')
128 expect(res.body.name).to.contain('<3')
129 }) 118 })
130 119
131 it('Should run filter:api.video.upload.accept.result', async function () { 120 it('Should run filter:api.video.upload.accept.result', async function () {
132 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, HttpStatusCode.FORBIDDEN_403) 121 await servers[0].videosCommand.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
133 }) 122 })
134 123
135 it('Should run filter:api.live-video.create.accept.result', async function () { 124 it('Should run filter:api.live-video.create.accept.result', async function () {
@@ -270,14 +259,13 @@ describe('Test plugin filter hooks', function () {
270 describe('Should run filter:video.auto-blacklist.result', function () { 259 describe('Should run filter:video.auto-blacklist.result', function () {
271 260
272 async function checkIsBlacklisted (id: number | string, value: boolean) { 261 async function checkIsBlacklisted (id: number | string, value: boolean) {
273 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id) 262 const video = await servers[0].videosCommand.getWithToken({ id })
274 const video: VideoDetails = res.body
275 expect(video.blacklisted).to.equal(value) 263 expect(video.blacklisted).to.equal(value)
276 } 264 }
277 265
278 it('Should blacklist on upload', async function () { 266 it('Should blacklist on upload', async function () {
279 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) 267 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video please blacklist me' } })
280 await checkIsBlacklisted(res.body.video.uuid, true) 268 await checkIsBlacklisted(uuid, true)
281 }) 269 })
282 270
283 it('Should blacklist on import', async function () { 271 it('Should blacklist on import', async function () {
@@ -293,36 +281,34 @@ describe('Test plugin filter hooks', function () {
293 }) 281 })
294 282
295 it('Should blacklist on update', async function () { 283 it('Should blacklist on update', async function () {
296 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) 284 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } })
297 const videoId = res.body.video.uuid 285 await checkIsBlacklisted(uuid, false)
298 await checkIsBlacklisted(videoId, false)
299 286
300 await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) 287 await servers[0].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } })
301 await checkIsBlacklisted(videoId, true) 288 await checkIsBlacklisted(uuid, true)
302 }) 289 })
303 290
304 it('Should blacklist on remote upload', async function () { 291 it('Should blacklist on remote upload', async function () {
305 this.timeout(120000) 292 this.timeout(120000)
306 293
307 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) 294 const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'remote please blacklist me' } })
308 await waitJobs(servers) 295 await waitJobs(servers)
309 296
310 await checkIsBlacklisted(res.body.video.uuid, true) 297 await checkIsBlacklisted(uuid, true)
311 }) 298 })
312 299
313 it('Should blacklist on remote update', async function () { 300 it('Should blacklist on remote update', async function () {
314 this.timeout(120000) 301 this.timeout(120000)
315 302
316 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' }) 303 const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video' } })
317 await waitJobs(servers) 304 await waitJobs(servers)
318 305
319 const videoId = res.body.video.uuid 306 await checkIsBlacklisted(uuid, false)
320 await checkIsBlacklisted(videoId, false)
321 307
322 await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) 308 await servers[1].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } })
323 await waitJobs(servers) 309 await waitJobs(servers)
324 310
325 await checkIsBlacklisted(videoId, true) 311 await checkIsBlacklisted(uuid, true)
326 }) 312 })
327 }) 313 })
328 314
@@ -370,15 +356,14 @@ describe('Test plugin filter hooks', function () {
370 const uuids: string[] = [] 356 const uuids: string[] = []
371 357
372 for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) { 358 for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) {
373 const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid 359 const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid
374 uuids.push(uuid) 360 uuids.push(uuid)
375 } 361 }
376 362
377 await waitJobs(servers) 363 await waitJobs(servers)
378 364
379 for (const uuid of uuids) { 365 for (const uuid of uuids) {
380 const res = await getVideo(servers[0].url, uuid) 366 downloadVideos.push(await servers[0].videosCommand.get({ id: uuid }))
381 downloadVideos.push(res.body)
382 } 367 }
383 }) 368 })
384 369
@@ -428,9 +413,8 @@ describe('Test plugin filter hooks', function () {
428 413
429 for (const name of [ 'bad embed', 'good embed' ]) { 414 for (const name of [ 'bad embed', 'good embed' ]) {
430 { 415 {
431 const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid 416 const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid
432 const res = await getVideo(servers[0].url, uuid) 417 embedVideos.push(await servers[0].videosCommand.get({ id: uuid }))
433 embedVideos.push(res.body)
434 } 418 }
435 419
436 { 420 {