aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-10 11:51:13 +0200
committerChocobozzz <me@florianbigard.com>2022-08-10 14:32:00 +0200
commita3b472a12ec6e57dbe2f650419f8064864686eab (patch)
treef36559488e34493c029b686772e986902150a647 /server/tests
parent0567049a9819d67070aa6d548a75a7e632a4aaa4 (diff)
downloadPeerTube-a3b472a12ec6e57dbe2f650419f8064864686eab.tar.gz
PeerTube-a3b472a12ec6e57dbe2f650419f8064864686eab.tar.zst
PeerTube-a3b472a12ec6e57dbe2f650419f8064864686eab.zip
Add ability to list imports of a channel sync
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/channel-import-videos.ts172
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/video-channels.ts113
-rw-r--r--server/tests/api/check-params/video-imports.ts9
-rw-r--r--server/tests/api/videos/channel-import-videos.ts72
-rw-r--r--server/tests/api/videos/video-channel-syncs.ts12
-rw-r--r--server/tests/api/videos/video-imports.ts9
7 files changed, 276 insertions, 112 deletions
diff --git a/server/tests/api/check-params/channel-import-videos.ts b/server/tests/api/check-params/channel-import-videos.ts
new file mode 100644
index 000000000..90d61f20a
--- /dev/null
+++ b/server/tests/api/check-params/channel-import-videos.ts
@@ -0,0 +1,172 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { FIXTURE_URLS } from '@server/tests/shared'
5import { areHttpImportTestsDisabled } from '@shared/core-utils'
6import { HttpStatusCode } from '@shared/models'
7import { ChannelsCommand, cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
8
9describe('Test videos import in a channel API validator', function () {
10 let server: PeerTubeServer
11 const userInfo = {
12 accessToken: '',
13 channelName: 'fake_channel',
14 id: -1,
15 videoQuota: -1,
16 videoQuotaDaily: -1
17 }
18 let command: ChannelsCommand
19
20 // ---------------------------------------------------------------
21
22 before(async function () {
23 this.timeout(30000)
24
25 server = await createSingleServer(1)
26
27 await setAccessTokensToServers([ server ])
28
29 const userCreds = {
30 username: 'fake',
31 password: 'fake_password'
32 }
33
34 {
35 const user = await server.users.create({ username: userCreds.username, password: userCreds.password })
36 userInfo.id = user.id
37 userInfo.accessToken = await server.login.getAccessToken(userCreds)
38 }
39
40 command = server.channels
41 })
42
43 it('Should fail when HTTP upload is disabled', async function () {
44 await server.config.disableImports()
45
46 await command.importVideos({
47 channelName: 'super_channel',
48 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
49 token: server.accessToken,
50 expectedStatus: HttpStatusCode.FORBIDDEN_403
51 })
52
53 await server.config.enableImports()
54 })
55
56 it('Should fail when externalChannelUrl is not provided', async function () {
57 await command.importVideos({
58 channelName: 'super_channel',
59 externalChannelUrl: null,
60 token: server.accessToken,
61 expectedStatus: HttpStatusCode.BAD_REQUEST_400
62 })
63 })
64
65 it('Should fail when externalChannelUrl is malformed', async function () {
66 await command.importVideos({
67 channelName: 'super_channel',
68 externalChannelUrl: 'not-a-url',
69 token: server.accessToken,
70 expectedStatus: HttpStatusCode.BAD_REQUEST_400
71 })
72 })
73
74 it('Should fail with a bad sync id', async function () {
75 await command.importVideos({
76 channelName: 'super_channel',
77 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
78 videoChannelSyncId: 'toto' as any,
79 token: server.accessToken,
80 expectedStatus: HttpStatusCode.BAD_REQUEST_400
81 })
82 })
83
84 it('Should fail with a unknown sync id', async function () {
85 await command.importVideos({
86 channelName: 'super_channel',
87 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
88 videoChannelSyncId: 42,
89 token: server.accessToken,
90 expectedStatus: HttpStatusCode.NOT_FOUND_404
91 })
92 })
93
94 it('Should fail with no authentication', async function () {
95 await command.importVideos({
96 channelName: 'super_channel',
97 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
98 token: null,
99 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
100 })
101 })
102
103 it('Should fail when sync is not owned by the user', async function () {
104 await command.importVideos({
105 channelName: 'super_channel',
106 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
107 token: userInfo.accessToken,
108 expectedStatus: HttpStatusCode.FORBIDDEN_403
109 })
110 })
111
112 it('Should fail when the user has no quota', async function () {
113 await server.users.update({
114 userId: userInfo.id,
115 videoQuota: 0
116 })
117
118 await command.importVideos({
119 channelName: 'fake_channel',
120 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
121 token: userInfo.accessToken,
122 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
123 })
124
125 await server.users.update({
126 userId: userInfo.id,
127 videoQuota: userInfo.videoQuota
128 })
129 })
130
131 it('Should fail when the user has no daily quota', async function () {
132 await server.users.update({
133 userId: userInfo.id,
134 videoQuotaDaily: 0
135 })
136
137 await command.importVideos({
138 channelName: 'fake_channel',
139 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
140 token: userInfo.accessToken,
141 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
142 })
143
144 await server.users.update({
145 userId: userInfo.id,
146 videoQuotaDaily: userInfo.videoQuotaDaily
147 })
148 })
149
150 it('Should succeed when sync is run by its owner', async function () {
151 if (!areHttpImportTestsDisabled()) return
152
153 await command.importVideos({
154 channelName: 'fake_channel',
155 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
156 token: userInfo.accessToken
157 })
158 })
159
160 it('Should succeed when sync is run with root and for another user\'s channel', async function () {
161 if (!areHttpImportTestsDisabled()) return
162
163 await command.importVideos({
164 channelName: 'fake_channel',
165 externalChannelUrl: FIXTURE_URLS.youtubeChannel
166 })
167 })
168
169 after(async function () {
170 await cleanupTests([ server ])
171 })
172})
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index 5f1168b53..149305f49 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -28,6 +28,7 @@ import './video-comments'
28import './video-files' 28import './video-files'
29import './video-imports' 29import './video-imports'
30import './video-channel-syncs' 30import './video-channel-syncs'
31import './channel-import-videos'
31import './video-playlists' 32import './video-playlists'
32import './video-source' 33import './video-source'
33import './video-studio' 34import './video-studio'
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index 337ea1dd4..9024126c0 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -3,8 +3,8 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, FIXTURE_URLS } from '@server/tests/shared' 6import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
7import { areHttpImportTestsDisabled, buildAbsoluteFixturePath } from '@shared/core-utils' 7import { buildAbsoluteFixturePath } from '@shared/core-utils'
8import { HttpStatusCode, VideoChannelUpdate } from '@shared/models' 8import { HttpStatusCode, VideoChannelUpdate } from '@shared/models'
9import { 9import {
10 ChannelsCommand, 10 ChannelsCommand,
@@ -354,115 +354,6 @@ describe('Test video channels API validator', function () {
354 }) 354 })
355 }) 355 })
356 356
357 describe('When triggering full synchronization', function () {
358
359 it('Should fail when HTTP upload is disabled', async function () {
360 await server.config.disableImports()
361
362 await command.importVideos({
363 channelName: 'super_channel',
364 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
365 token: server.accessToken,
366 expectedStatus: HttpStatusCode.FORBIDDEN_403
367 })
368
369 await server.config.enableImports()
370 })
371
372 it('Should fail when externalChannelUrl is not provided', async function () {
373 await command.importVideos({
374 channelName: 'super_channel',
375 externalChannelUrl: null,
376 token: server.accessToken,
377 expectedStatus: HttpStatusCode.BAD_REQUEST_400
378 })
379 })
380
381 it('Should fail when externalChannelUrl is malformed', async function () {
382 await command.importVideos({
383 channelName: 'super_channel',
384 externalChannelUrl: 'not-a-url',
385 token: server.accessToken,
386 expectedStatus: HttpStatusCode.BAD_REQUEST_400
387 })
388 })
389
390 it('Should fail with no authentication', async function () {
391 await command.importVideos({
392 channelName: 'super_channel',
393 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
394 token: null,
395 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
396 })
397 })
398
399 it('Should fail when sync is not owned by the user', async function () {
400 await command.importVideos({
401 channelName: 'super_channel',
402 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
403 token: userInfo.accessToken,
404 expectedStatus: HttpStatusCode.FORBIDDEN_403
405 })
406 })
407
408 it('Should fail when the user has no quota', async function () {
409 await server.users.update({
410 userId: userInfo.id,
411 videoQuota: 0
412 })
413
414 await command.importVideos({
415 channelName: 'fake_channel',
416 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
417 token: userInfo.accessToken,
418 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
419 })
420
421 await server.users.update({
422 userId: userInfo.id,
423 videoQuota: userInfo.videoQuota
424 })
425 })
426
427 it('Should fail when the user has no daily quota', async function () {
428 await server.users.update({
429 userId: userInfo.id,
430 videoQuotaDaily: 0
431 })
432
433 await command.importVideos({
434 channelName: 'fake_channel',
435 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
436 token: userInfo.accessToken,
437 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
438 })
439
440 await server.users.update({
441 userId: userInfo.id,
442 videoQuotaDaily: userInfo.videoQuotaDaily
443 })
444 })
445
446 it('Should succeed when sync is run by its owner', async function () {
447 if (!areHttpImportTestsDisabled()) return
448
449 await command.importVideos({
450 channelName: 'fake_channel',
451 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
452 token: userInfo.accessToken
453 })
454 })
455
456 it('Should succeed when sync is run with root and for another user\'s channel', async function () {
457 if (!areHttpImportTestsDisabled()) return
458
459 await command.importVideos({
460 channelName: 'fake_channel',
461 externalChannelUrl: FIXTURE_URLS.youtubeChannel
462 })
463 })
464 })
465
466 describe('When deleting a video channel', function () { 357 describe('When deleting a video channel', function () {
467 it('Should fail with a non authenticated user', async function () { 358 it('Should fail with a non authenticated user', async function () {
468 await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 359 await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index 5cdd0d925..85382b261 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -59,6 +59,15 @@ describe('Test video imports API validator', function () {
59 await checkBadSortPagination(server.url, myPath, server.accessToken) 59 await checkBadSortPagination(server.url, myPath, server.accessToken)
60 }) 60 })
61 61
62 it('Should fail with a bad videoChannelSyncId param', async function () {
63 await makeGetRequest({
64 url: server.url,
65 path: myPath,
66 query: { videoChannelSyncId: 'toto' },
67 token: server.accessToken
68 })
69 })
70
62 it('Should success with the correct parameters', async function () { 71 it('Should success with the correct parameters', async function () {
63 await makeGetRequest({ url: server.url, path: myPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken }) 72 await makeGetRequest({ url: server.url, path: myPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken })
64 }) 73 })
diff --git a/server/tests/api/videos/channel-import-videos.ts b/server/tests/api/videos/channel-import-videos.ts
index f7540e1ba..7cfd02fbb 100644
--- a/server/tests/api/videos/channel-import-videos.ts
+++ b/server/tests/api/videos/channel-import-videos.ts
@@ -1,3 +1,5 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
1import { expect } from 'chai' 3import { expect } from 'chai'
2import { FIXTURE_URLS } from '@server/tests/shared' 4import { FIXTURE_URLS } from '@server/tests/shared'
3import { areHttpImportTestsDisabled } from '@shared/core-utils' 5import { areHttpImportTestsDisabled } from '@shared/core-utils'
@@ -29,7 +31,7 @@ describe('Test videos import in a channel', function () {
29 await server.config.enableChannelSync() 31 await server.config.enableChannelSync()
30 }) 32 })
31 33
32 it('Should import a whole channel', async function () { 34 it('Should import a whole channel without specifying the sync id', async function () {
33 this.timeout(240_000) 35 this.timeout(240_000)
34 36
35 await server.channels.importVideos({ channelName: server.store.channel.name, externalChannelUrl: FIXTURE_URLS.youtubeChannel }) 37 await server.channels.importVideos({ channelName: server.store.channel.name, externalChannelUrl: FIXTURE_URLS.youtubeChannel })
@@ -39,6 +41,74 @@ describe('Test videos import in a channel', function () {
39 expect(videos.total).to.equal(2) 41 expect(videos.total).to.equal(2)
40 }) 42 })
41 43
44 it('These imports should not have a sync id', async function () {
45 const { total, data } = await server.imports.getMyVideoImports()
46
47 expect(total).to.equal(2)
48 expect(data).to.have.lengthOf(2)
49
50 for (const videoImport of data) {
51 expect(videoImport.videoChannelSync).to.not.exist
52 }
53 })
54
55 it('Should import a whole channel and specifying the sync id', async function () {
56 this.timeout(240_000)
57
58 {
59 server.store.channel.name = 'channel2'
60 const { id } = await server.channels.create({ attributes: { name: server.store.channel.name } })
61 server.store.channel.id = id
62 }
63
64 {
65 const attributes = {
66 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
67 videoChannelId: server.store.channel.id
68 }
69
70 const { videoChannelSync } = await server.channelSyncs.create({ attributes })
71 server.store.videoChannelSync = videoChannelSync
72
73 await waitJobs(server)
74 }
75
76 await server.channels.importVideos({
77 channelName: server.store.channel.name,
78 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
79 videoChannelSyncId: server.store.videoChannelSync.id
80 })
81
82 await waitJobs(server)
83 })
84
85 it('These imports should have a sync id', async function () {
86 const { total, data } = await server.imports.getMyVideoImports()
87
88 expect(total).to.equal(4)
89 expect(data).to.have.lengthOf(4)
90
91 const importsWithSyncId = data.filter(i => !!i.videoChannelSync)
92 expect(importsWithSyncId).to.have.lengthOf(2)
93
94 for (const videoImport of importsWithSyncId) {
95 expect(videoImport.videoChannelSync).to.exist
96 expect(videoImport.videoChannelSync.id).to.equal(server.store.videoChannelSync.id)
97 }
98 })
99
100 it('Should be able to filter imports by this sync id', async function () {
101 const { total, data } = await server.imports.getMyVideoImports({ videoChannelSyncId: server.store.videoChannelSync.id })
102
103 expect(total).to.equal(2)
104 expect(data).to.have.lengthOf(2)
105
106 for (const videoImport of data) {
107 expect(videoImport.videoChannelSync).to.exist
108 expect(videoImport.videoChannelSync.id).to.equal(server.store.videoChannelSync.id)
109 }
110 })
111
42 after(async function () { 112 after(async function () {
43 await server?.kill() 113 await server?.kill()
44 }) 114 })
diff --git a/server/tests/api/videos/video-channel-syncs.ts b/server/tests/api/videos/video-channel-syncs.ts
index 229c01f68..835d3cb09 100644
--- a/server/tests/api/videos/video-channel-syncs.ts
+++ b/server/tests/api/videos/video-channel-syncs.ts
@@ -23,7 +23,10 @@ describe('Test channel synchronizations', function () {
23 describe('Sync using ' + mode, function () { 23 describe('Sync using ' + mode, function () {
24 let server: PeerTubeServer 24 let server: PeerTubeServer
25 let command: ChannelSyncsCommand 25 let command: ChannelSyncsCommand
26
26 let startTestDate: Date 27 let startTestDate: Date
28
29 let rootChannelSyncId: number
27 const userInfo = { 30 const userInfo = {
28 accessToken: '', 31 accessToken: '',
29 username: 'user1', 32 username: 'user1',
@@ -90,6 +93,7 @@ describe('Test channel synchronizations', function () {
90 token: server.accessToken, 93 token: server.accessToken,
91 expectedStatus: HttpStatusCode.OK_200 94 expectedStatus: HttpStatusCode.OK_200
92 }) 95 })
96 rootChannelSyncId = videoChannelSync.id
93 97
94 // Ensure any missing video not already fetched will be considered as new 98 // Ensure any missing video not already fetched will be considered as new
95 await changeDateForSync(videoChannelSync.id, '1970-01-01') 99 await changeDateForSync(videoChannelSync.id, '1970-01-01')
@@ -208,6 +212,14 @@ describe('Test channel synchronizations', function () {
208 } 212 }
209 }) 213 })
210 214
215 it('Should list imports of a channel synchronization', async function () {
216 const { total, data } = await server.imports.getMyVideoImports({ videoChannelSyncId: rootChannelSyncId })
217
218 expect(total).to.equal(1)
219 expect(data).to.have.lengthOf(1)
220 expect(data[0].video.name).to.equal('test')
221 })
222
211 it('Should remove user\'s channel synchronizations', async function () { 223 it('Should remove user\'s channel synchronizations', async function () {
212 await command.delete({ channelSyncId: userInfo.syncId }) 224 await command.delete({ channelSyncId: userInfo.syncId })
213 225
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts
index a487062a2..f082d4bd7 100644
--- a/server/tests/api/videos/video-imports.ts
+++ b/server/tests/api/videos/video-imports.ts
@@ -228,6 +228,15 @@ describe('Test video imports', function () {
228 expect(videoImports[0].targetUrl).to.equal(FIXTURE_URLS.youtube) 228 expect(videoImports[0].targetUrl).to.equal(FIXTURE_URLS.youtube)
229 }) 229 })
230 230
231 it('Should search in my imports', async function () {
232 const { total, data: videoImports } = await servers[0].imports.getMyVideoImports({ search: 'peertube2' })
233 expect(total).to.equal(1)
234 expect(videoImports).to.have.lengthOf(1)
235
236 expect(videoImports[0].magnetUri).to.equal(FIXTURE_URLS.magnet)
237 expect(videoImports[0].video.name).to.equal('super peertube2 video')
238 })
239
231 it('Should have the video listed on the two instances', async function () { 240 it('Should have the video listed on the two instances', async function () {
232 this.timeout(120_000) 241 this.timeout(120_000)
233 242