aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-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
5 files changed, 61 insertions, 73 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