aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/tests/api/check-params/upload-quota.ts16
-rw-r--r--server/tests/api/check-params/video-imports.ts6
-rw-r--r--server/tests/api/moderation/video-blacklist.ts10
-rw-r--r--server/tests/api/notifications/user-notifications.ts30
-rw-r--r--server/tests/api/videos/video-imports.ts72
-rw-r--r--server/tests/cli/peertube.ts7
-rw-r--r--server/tests/plugins/filter-hooks.ts67
7 files changed, 93 insertions, 115 deletions
diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts
index d0fbec415..c444663b8 100644
--- a/server/tests/api/check-params/upload-quota.ts
+++ b/server/tests/api/check-params/upload-quota.ts
@@ -3,13 +3,12 @@
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode, randomInt } from '@shared/core-utils' 5import { HttpStatusCode, randomInt } from '@shared/core-utils'
6import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports' 6import { MyUser, VideoImportState, VideoPrivacy } from '@shared/models'
7import { MyUser, VideoImport, VideoImportState, VideoPrivacy } from '@shared/models'
8import { 7import {
9 cleanupTests, 8 cleanupTests,
10 flushAndRunServer, 9 flushAndRunServer,
11 getMyUserInformation, 10 getMyUserInformation,
12 immutableAssign, 11 ImportsCommand,
13 registerUser, 12 registerUser,
14 ServerInfo, 13 ServerInfo,
15 setAccessTokensToServers, 14 setAccessTokensToServers,
@@ -83,16 +82,15 @@ describe('Test upload quota', function () {
83 channelId: server.videoChannel.id, 82 channelId: server.videoChannel.id,
84 privacy: VideoPrivacy.PUBLIC 83 privacy: VideoPrivacy.PUBLIC
85 } 84 }
86 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getGoodVideoUrl() })) 85 await server.importsCommand.importVideo({ attributes: { ...baseAttributes, targetUrl: ImportsCommand.getGoodVideoUrl() } })
87 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() })) 86 await server.importsCommand.importVideo({ attributes: { ...baseAttributes, magnetUri: ImportsCommand.getMagnetURI() } })
88 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any })) 87 await server.importsCommand.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } })
89 88
90 await waitJobs([ server ]) 89 await waitJobs([ server ])
91 90
92 const res = await getMyVideoImports(server.url, server.accessToken) 91 const { total, data: videoImports } = await server.importsCommand.getMyVideoImports()
92 expect(total).to.equal(3)
93 93
94 expect(res.body.total).to.equal(3)
95 const videoImports: VideoImport[] = res.body.data
96 expect(videoImports).to.have.lengthOf(3) 94 expect(videoImports).to.have.lengthOf(3)
97 95
98 for (const videoImport of videoImports) { 96 for (const videoImport of videoImports) {
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index dae3860ef..ea473191e 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -13,6 +13,7 @@ import {
13 flushAndRunServer, 13 flushAndRunServer,
14 getMyUserInformation, 14 getMyUserInformation,
15 immutableAssign, 15 immutableAssign,
16 ImportsCommand,
16 makeGetRequest, 17 makeGetRequest,
17 makePostBodyRequest, 18 makePostBodyRequest,
18 makeUploadRequest, 19 makeUploadRequest,
@@ -20,7 +21,6 @@ import {
20 setAccessTokensToServers, 21 setAccessTokensToServers,
21 userLogin 22 userLogin
22} from '@shared/extra-utils' 23} from '@shared/extra-utils'
23import { getGoodVideoUrl, getMagnetURI } from '@shared/extra-utils/videos/video-imports'
24import { VideoPrivacy } from '@shared/models' 24import { VideoPrivacy } from '@shared/models'
25 25
26describe('Test video imports API validator', function () { 26describe('Test video imports API validator', function () {
@@ -74,7 +74,7 @@ describe('Test video imports API validator', function () {
74 74
75 before(function () { 75 before(function () {
76 baseCorrectParams = { 76 baseCorrectParams = {
77 targetUrl: getGoodVideoUrl(), 77 targetUrl: ImportsCommand.getGoodVideoUrl(),
78 name: 'my super name', 78 name: 'my super name',
79 category: 5, 79 category: 5,
80 licence: 1, 80 licence: 1,
@@ -301,7 +301,7 @@ describe('Test video imports API validator', function () {
301 }) 301 })
302 302
303 let fields = omit(baseCorrectParams, 'targetUrl') 303 let fields = omit(baseCorrectParams, 'targetUrl')
304 fields = immutableAssign(fields, { magnetUri: getMagnetURI() }) 304 fields = immutableAssign(fields, { magnetUri: ImportsCommand.getMagnetURI() })
305 305
306 await makePostBodyRequest({ 306 await makePostBodyRequest({
307 url: server.url, 307 url: server.url,
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts
index 17a68e4a6..c72ebc16b 100644
--- a/server/tests/api/moderation/video-blacklist.ts
+++ b/server/tests/api/moderation/video-blacklist.ts
@@ -12,6 +12,7 @@ import {
12 getMyUserInformation, 12 getMyUserInformation,
13 getMyVideos, 13 getMyVideos,
14 getVideosList, 14 getVideosList,
15 ImportsCommand,
15 killallServers, 16 killallServers,
16 reRunServer, 17 reRunServer,
17 ServerInfo, 18 ServerInfo,
@@ -21,7 +22,6 @@ import {
21 userLogin, 22 userLogin,
22 waitJobs 23 waitJobs
23} from '@shared/extra-utils' 24} from '@shared/extra-utils'
24import { getGoodVideoUrl, getMagnetURI, importVideo } from '@shared/extra-utils/videos/video-imports'
25import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' 25import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
26 26
27const expect = chai.expect 27const expect = chai.expect
@@ -402,11 +402,11 @@ describe('Test video blacklist', function () {
402 this.timeout(15000) 402 this.timeout(15000)
403 403
404 const attributes = { 404 const attributes = {
405 targetUrl: getGoodVideoUrl(), 405 targetUrl: ImportsCommand.getGoodVideoUrl(),
406 name: 'URL import', 406 name: 'URL import',
407 channelId: channelOfUserWithoutFlag 407 channelId: channelOfUserWithoutFlag
408 } 408 }
409 await importVideo(servers[0].url, userWithoutFlag, attributes) 409 await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes })
410 410
411 const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) 411 const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
412 expect(body.total).to.equal(2) 412 expect(body.total).to.equal(2)
@@ -415,11 +415,11 @@ describe('Test video blacklist', function () {
415 415
416 it('Should auto blacklist a video on torrent import', async function () { 416 it('Should auto blacklist a video on torrent import', async function () {
417 const attributes = { 417 const attributes = {
418 magnetUri: getMagnetURI(), 418 magnetUri: ImportsCommand.getMagnetURI(),
419 name: 'Torrent import', 419 name: 'Torrent import',
420 channelId: channelOfUserWithoutFlag 420 channelId: channelOfUserWithoutFlag
421 } 421 }
422 await importVideo(servers[0].url, userWithoutFlag, attributes) 422 await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes })
423 423
424 const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) 424 const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
425 expect(body.total).to.equal(3) 425 expect(body.total).to.equal(3)
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts
index 15be983f2..a9315c818 100644
--- a/server/tests/api/notifications/user-notifications.ts
+++ b/server/tests/api/notifications/user-notifications.ts
@@ -11,6 +11,7 @@ import {
11 checkVideoIsPublished, 11 checkVideoIsPublished,
12 cleanupTests, 12 cleanupTests,
13 getLastNotification, 13 getLastNotification,
14 ImportsCommand,
14 MockSmtpServer, 15 MockSmtpServer,
15 prepareNotificationsTest, 16 prepareNotificationsTest,
16 ServerInfo, 17 ServerInfo,
@@ -21,7 +22,6 @@ import {
21 wait, 22 wait,
22 waitJobs 23 waitJobs
23} from '@shared/extra-utils' 24} from '@shared/extra-utils'
24import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '@shared/extra-utils/videos/video-imports'
25import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models' 25import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models'
26 26
27const expect = chai.expect 27const expect = chai.expect
@@ -209,14 +209,13 @@ describe('Test user notifications', function () {
209 name, 209 name,
210 channelId, 210 channelId,
211 privacy: VideoPrivacy.PUBLIC, 211 privacy: VideoPrivacy.PUBLIC,
212 targetUrl: getGoodVideoUrl() 212 targetUrl: ImportsCommand.getGoodVideoUrl()
213 } 213 }
214 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 214 const { video } = await servers[0].importsCommand.importVideo({ attributes })
215 const uuid = res.body.video.uuid
216 215
217 await waitJobs(servers) 216 await waitJobs(servers)
218 217
219 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 218 await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence')
220 }) 219 })
221 }) 220 })
222 221
@@ -280,14 +279,13 @@ describe('Test user notifications', function () {
280 name, 279 name,
281 channelId, 280 channelId,
282 privacy: VideoPrivacy.PUBLIC, 281 privacy: VideoPrivacy.PUBLIC,
283 targetUrl: getGoodVideoUrl(), 282 targetUrl: ImportsCommand.getGoodVideoUrl(),
284 waitTranscoding: true 283 waitTranscoding: true
285 } 284 }
286 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) 285 const { video } = await servers[1].importsCommand.importVideo({ attributes })
287 const uuid = res.body.video.uuid
288 286
289 await waitJobs(servers) 287 await waitJobs(servers)
290 await checkVideoIsPublished(baseParams, name, uuid, 'presence') 288 await checkVideoIsPublished(baseParams, name, video.uuid, 'presence')
291 }) 289 })
292 290
293 it('Should send a notification when the scheduled update has been proceeded', async function () { 291 it('Should send a notification when the scheduled update has been proceeded', async function () {
@@ -349,13 +347,12 @@ describe('Test user notifications', function () {
349 name, 347 name,
350 channelId, 348 channelId,
351 privacy: VideoPrivacy.PRIVATE, 349 privacy: VideoPrivacy.PRIVATE,
352 targetUrl: getBadVideoUrl() 350 targetUrl: ImportsCommand.getBadVideoUrl()
353 } 351 }
354 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 352 const { video } = await servers[0].importsCommand.importVideo({ attributes })
355 const uuid = res.body.video.uuid
356 353
357 await waitJobs(servers) 354 await waitJobs(servers)
358 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence') 355 await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getBadVideoUrl(), false, 'presence')
359 }) 356 })
360 357
361 it('Should send a notification when the video import succeeded', async function () { 358 it('Should send a notification when the video import succeeded', async function () {
@@ -367,13 +364,12 @@ describe('Test user notifications', function () {
367 name, 364 name,
368 channelId, 365 channelId,
369 privacy: VideoPrivacy.PRIVATE, 366 privacy: VideoPrivacy.PRIVATE,
370 targetUrl: getGoodVideoUrl() 367 targetUrl: ImportsCommand.getGoodVideoUrl()
371 } 368 }
372 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 369 const { video } = await servers[0].importsCommand.importVideo({ attributes })
373 const uuid = res.body.video.uuid
374 370
375 await waitJobs(servers) 371 await waitJobs(servers)
376 await checkMyVideoImportIsFinished(baseParams, name, uuid, getGoodVideoUrl(), true, 'presence') 372 await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getGoodVideoUrl(), true, 'presence')
377 }) 373 })
378 }) 374 })
379 375
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts
index 14aed604f..4f9ecbe8e 100644
--- a/server/tests/api/videos/video-imports.ts
+++ b/server/tests/api/videos/video-imports.ts
@@ -3,6 +3,7 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 areHttpImportTestsDisabled,
6 cleanupTests, 7 cleanupTests,
7 doubleFollow, 8 doubleFollow,
8 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
@@ -11,20 +12,14 @@ import {
11 getVideo, 12 getVideo,
12 getVideosList, 13 getVideosList,
13 immutableAssign, 14 immutableAssign,
15 ImportsCommand,
14 ServerInfo, 16 ServerInfo,
15 setAccessTokensToServers, 17 setAccessTokensToServers,
16 testCaptionFile 18 testCaptionFile,
17} from '../../../../shared/extra-utils' 19 testImage,
18import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs' 20 waitJobs
19import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 21} from '@shared/extra-utils'
20import { 22import { VideoDetails, VideoPrivacy, VideoResolution } from '@shared/models'
21 getMagnetURI,
22 getMyVideoImports,
23 getYoutubeHDRVideoUrl,
24 getYoutubeVideoUrl,
25 importVideo
26} from '../../../../shared/extra-utils/videos/video-imports'
27import { VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos'
28 23
29const expect = chai.expect 24const expect = chai.expect
30 25
@@ -124,17 +119,17 @@ describe('Test video imports', function () {
124 } 119 }
125 120
126 { 121 {
127 const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }) 122 const attributes = immutableAssign(baseAttributes, { targetUrl: ImportsCommand.getYoutubeVideoUrl() })
128 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 123 const { video } = await servers[0].importsCommand.importVideo({ attributes })
129 expect(res.body.video.name).to.equal('small video - youtube') 124 expect(video.name).to.equal('small video - youtube')
130 125
131 expect(res.body.video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) 126 expect(video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`))
132 expect(res.body.video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`)) 127 expect(video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`))
133 128
134 await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath) 129 await testImage(servers[0].url, 'video_import_thumbnail', video.thumbnailPath)
135 await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath) 130 await testImage(servers[0].url, 'video_import_preview', video.previewPath)
136 131
137 const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: res.body.video.id }) 132 const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: video.id })
138 const videoCaptions = bodyCaptions.data 133 const videoCaptions = bodyCaptions.data
139 expect(videoCaptions).to.have.lengthOf(2) 134 expect(videoCaptions).to.have.lengthOf(2)
140 135
@@ -175,12 +170,12 @@ Ajouter un sous-titre est vraiment facile`)
175 170
176 { 171 {
177 const attributes = immutableAssign(baseAttributes, { 172 const attributes = immutableAssign(baseAttributes, {
178 magnetUri: getMagnetURI(), 173 magnetUri: ImportsCommand.getMagnetURI(),
179 description: 'this is a super torrent description', 174 description: 'this is a super torrent description',
180 tags: [ 'tag_torrent1', 'tag_torrent2' ] 175 tags: [ 'tag_torrent1', 'tag_torrent2' ]
181 }) 176 })
182 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 177 const { video } = await servers[0].importsCommand.importVideo({ attributes })
183 expect(res.body.video.name).to.equal('super peertube2 video') 178 expect(video.name).to.equal('super peertube2 video')
184 } 179 }
185 180
186 { 181 {
@@ -189,8 +184,8 @@ Ajouter un sous-titre est vraiment facile`)
189 description: 'this is a super torrent description', 184 description: 'this is a super torrent description',
190 tags: [ 'tag_torrent1', 'tag_torrent2' ] 185 tags: [ 'tag_torrent1', 'tag_torrent2' ]
191 }) 186 })
192 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 187 const { video } = await servers[0].importsCommand.importVideo({ attributes })
193 expect(res.body.video.name).to.equal('你好 世界 720p.mp4') 188 expect(video.name).to.equal('你好 世界 720p.mp4')
194 } 189 }
195 }) 190 })
196 191
@@ -207,19 +202,18 @@ Ajouter un sous-titre est vraiment facile`)
207 }) 202 })
208 203
209 it('Should list the videos to import in my imports on server 1', async function () { 204 it('Should list the videos to import in my imports on server 1', async function () {
210 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt') 205 const { total, data: videoImports } = await servers[0].importsCommand.getMyVideoImports({ sort: '-createdAt' })
206 expect(total).to.equal(3)
211 207
212 expect(res.body.total).to.equal(3)
213 const videoImports: VideoImport[] = res.body.data
214 expect(videoImports).to.have.lengthOf(3) 208 expect(videoImports).to.have.lengthOf(3)
215 209
216 expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl()) 210 expect(videoImports[2].targetUrl).to.equal(ImportsCommand.getYoutubeVideoUrl())
217 expect(videoImports[2].magnetUri).to.be.null 211 expect(videoImports[2].magnetUri).to.be.null
218 expect(videoImports[2].torrentName).to.be.null 212 expect(videoImports[2].torrentName).to.be.null
219 expect(videoImports[2].video.name).to.equal('small video - youtube') 213 expect(videoImports[2].video.name).to.equal('small video - youtube')
220 214
221 expect(videoImports[1].targetUrl).to.be.null 215 expect(videoImports[1].targetUrl).to.be.null
222 expect(videoImports[1].magnetUri).to.equal(getMagnetURI()) 216 expect(videoImports[1].magnetUri).to.equal(ImportsCommand.getMagnetURI())
223 expect(videoImports[1].torrentName).to.be.null 217 expect(videoImports[1].torrentName).to.be.null
224 expect(videoImports[1].video.name).to.equal('super peertube2 video') 218 expect(videoImports[1].video.name).to.equal('super peertube2 video')
225 219
@@ -248,7 +242,7 @@ Ajouter un sous-titre est vraiment facile`)
248 this.timeout(60_000) 242 this.timeout(60_000)
249 243
250 const attributes = { 244 const attributes = {
251 targetUrl: getYoutubeVideoUrl(), 245 targetUrl: ImportsCommand.getYoutubeVideoUrl(),
252 channelId: channelIdServer2, 246 channelId: channelIdServer2,
253 privacy: VideoPrivacy.PUBLIC, 247 privacy: VideoPrivacy.PUBLIC,
254 category: 10, 248 category: 10,
@@ -258,8 +252,8 @@ Ajouter un sous-titre est vraiment facile`)
258 description: 'my super description', 252 description: 'my super description',
259 tags: [ 'supertag1', 'supertag2' ] 253 tags: [ 'supertag1', 'supertag2' ]
260 } 254 }
261 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) 255 const { video } = await servers[1].importsCommand.importVideo({ attributes })
262 expect(res.body.video.name).to.equal('my super name') 256 expect(video.name).to.equal('my super name')
263 }) 257 })
264 258
265 it('Should have the videos listed on the two instances', async function () { 259 it('Should have the videos listed on the two instances', async function () {
@@ -284,12 +278,12 @@ Ajouter un sous-titre est vraiment facile`)
284 278
285 const attributes = { 279 const attributes = {
286 name: 'transcoded video', 280 name: 'transcoded video',
287 magnetUri: getMagnetURI(), 281 magnetUri: ImportsCommand.getMagnetURI(),
288 channelId: channelIdServer2, 282 channelId: channelIdServer2,
289 privacy: VideoPrivacy.PUBLIC 283 privacy: VideoPrivacy.PUBLIC
290 } 284 }
291 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) 285 const { video } = await servers[1].importsCommand.importVideo({ attributes })
292 const videoUUID = res.body.video.uuid 286 const videoUUID = video.uuid
293 287
294 await waitJobs(servers) 288 await waitJobs(servers)
295 289
@@ -335,12 +329,12 @@ Ajouter un sous-titre est vraiment facile`)
335 329
336 const attributes = { 330 const attributes = {
337 name: 'hdr video', 331 name: 'hdr video',
338 targetUrl: getYoutubeHDRVideoUrl(), 332 targetUrl: ImportsCommand.getYoutubeHDRVideoUrl(),
339 channelId: channelIdServer1, 333 channelId: channelIdServer1,
340 privacy: VideoPrivacy.PUBLIC 334 privacy: VideoPrivacy.PUBLIC
341 } 335 }
342 const res1 = await importVideo(servers[0].url, servers[0].accessToken, attributes) 336 const { video: videoImported } = await servers[0].importsCommand.importVideo({ attributes })
343 const videoUUID = res1.body.video.uuid 337 const videoUUID = videoImported.uuid
344 338
345 await waitJobs(servers) 339 await waitJobs(servers)
346 340
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts
index 0a4f54ffa..64a93ebb5 100644
--- a/server/tests/cli/peertube.ts
+++ b/server/tests/cli/peertube.ts
@@ -15,6 +15,7 @@ import {
15 getLocalIdByUUID, 15 getLocalIdByUUID,
16 getVideo, 16 getVideo,
17 getVideosList, 17 getVideosList,
18 ImportsCommand,
18 removeVideo, 19 removeVideo,
19 ServerInfo, 20 ServerInfo,
20 setAccessTokensToServers, 21 setAccessTokensToServers,
@@ -23,7 +24,6 @@ import {
23 userLogin, 24 userLogin,
24 waitJobs 25 waitJobs
25} from '../../../shared/extra-utils' 26} from '../../../shared/extra-utils'
26import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
27 27
28describe('Test CLI wrapper', function () { 28describe('Test CLI wrapper', function () {
29 let server: ServerInfo 29 let server: ServerInfo
@@ -122,7 +122,7 @@ describe('Test CLI wrapper', function () {
122 122
123 this.timeout(60000) 123 this.timeout(60000)
124 124
125 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel` 125 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} --channel-name user_channel`
126 await cliCommand.execWithEnv(`${cmd} import ${params}`) 126 await cliCommand.execWithEnv(`${cmd} import ${params}`)
127 }) 127 })
128 128
@@ -155,7 +155,8 @@ describe('Test CLI wrapper', function () {
155 155
156 this.timeout(60000) 156 this.timeout(60000)
157 157
158 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support` 158 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} ` +
159 `--channel-name user_channel --video-name toto --nsfw --support support`
159 await cliCommand.execWithEnv(`${cmd} import ${params}`) 160 await cliCommand.execWithEnv(`${cmd} import ${params}`)
160 161
161 await waitJobs([ server ]) 162 await waitJobs([ server ])
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'
33import { getGoodVideoUrl, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports' 34import { VideoCommentThreadTree, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
34import {
35 VideoCommentThreadTree,
36 VideoDetails,
37 VideoImport,
38 VideoImportState,
39 VideoPlaylist,
40 VideoPlaylistPrivacy,
41 VideoPrivacy
42} from '@shared/models'
43 35
44const expect = chai.expect 36const 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