diff options
author | Chocobozzz <me@florianbigard.com> | 2022-01-19 14:23:00 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-01-19 14:31:05 +0100 |
commit | 419b520ca4434d17f3505013174e195c3a316716 (patch) | |
tree | 24dbf663c4e11e970cb780f96e6eb3efe023b222 /server/tests/api | |
parent | 52435e467a0b30175a10af1dd3ae10d7d564d8ae (diff) | |
download | PeerTube-419b520ca4434d17f3505013174e195c3a316716.tar.gz PeerTube-419b520ca4434d17f3505013174e195c3a316716.tar.zst PeerTube-419b520ca4434d17f3505013174e195c3a316716.zip |
Add ability to cancel & delete video imports
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/check-params/jobs.ts | 43 | ||||
-rw-r--r-- | server/tests/api/check-params/video-imports.ts | 66 | ||||
-rw-r--r-- | server/tests/api/server/jobs.ts | 25 | ||||
-rw-r--r-- | server/tests/api/videos/video-imports.ts | 81 |
4 files changed, 212 insertions, 3 deletions
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts index d85961d62..801b13d1e 100644 --- a/server/tests/api/check-params/jobs.ts +++ b/server/tests/api/check-params/jobs.ts | |||
@@ -3,7 +3,14 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' | 4 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' |
5 | import { HttpStatusCode } from '@shared/models' | 5 | import { HttpStatusCode } from '@shared/models' |
6 | import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' | 6 | import { |
7 | cleanupTests, | ||
8 | createSingleServer, | ||
9 | makeGetRequest, | ||
10 | makePostBodyRequest, | ||
11 | PeerTubeServer, | ||
12 | setAccessTokensToServers | ||
13 | } from '@shared/server-commands' | ||
7 | 14 | ||
8 | describe('Test jobs API validators', function () { | 15 | describe('Test jobs API validators', function () { |
9 | const path = '/api/v1/jobs/failed' | 16 | const path = '/api/v1/jobs/failed' |
@@ -76,7 +83,41 @@ describe('Test jobs API validators', function () { | |||
76 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | 83 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
77 | }) | 84 | }) |
78 | }) | 85 | }) |
86 | }) | ||
87 | |||
88 | describe('When pausing/resuming the job queue', async function () { | ||
89 | const commands = [ 'pause', 'resume' ] | ||
90 | |||
91 | it('Should fail with a non authenticated user', async function () { | ||
92 | for (const command of commands) { | ||
93 | await makePostBodyRequest({ | ||
94 | url: server.url, | ||
95 | path: '/api/v1/jobs/' + command, | ||
96 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
97 | }) | ||
98 | } | ||
99 | }) | ||
79 | 100 | ||
101 | it('Should fail with a non admin user', async function () { | ||
102 | for (const command of commands) { | ||
103 | await makePostBodyRequest({ | ||
104 | url: server.url, | ||
105 | path: '/api/v1/jobs/' + command, | ||
106 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
107 | }) | ||
108 | } | ||
109 | }) | ||
110 | |||
111 | it('Should succeed with the correct params', async function () { | ||
112 | for (const command of commands) { | ||
113 | await makePostBodyRequest({ | ||
114 | url: server.url, | ||
115 | path: '/api/v1/jobs/' + command, | ||
116 | token: server.accessToken, | ||
117 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
118 | }) | ||
119 | } | ||
120 | }) | ||
80 | }) | 121 | }) |
81 | 122 | ||
82 | after(async function () { | 123 | after(async function () { |
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index da05793a0..156a612ee 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts | |||
@@ -12,7 +12,9 @@ import { | |||
12 | makePostBodyRequest, | 12 | makePostBodyRequest, |
13 | makeUploadRequest, | 13 | makeUploadRequest, |
14 | PeerTubeServer, | 14 | PeerTubeServer, |
15 | setAccessTokensToServers | 15 | setAccessTokensToServers, |
16 | setDefaultVideoChannel, | ||
17 | waitJobs | ||
16 | } from '@shared/server-commands' | 18 | } from '@shared/server-commands' |
17 | 19 | ||
18 | describe('Test video imports API validator', function () { | 20 | describe('Test video imports API validator', function () { |
@@ -29,6 +31,7 @@ describe('Test video imports API validator', function () { | |||
29 | server = await createSingleServer(1) | 31 | server = await createSingleServer(1) |
30 | 32 | ||
31 | await setAccessTokensToServers([ server ]) | 33 | await setAccessTokensToServers([ server ]) |
34 | await setDefaultVideoChannel([ server ]) | ||
32 | 35 | ||
33 | const username = 'user1' | 36 | const username = 'user1' |
34 | const password = 'my super password' | 37 | const password = 'my super password' |
@@ -347,6 +350,67 @@ describe('Test video imports API validator', function () { | |||
347 | }) | 350 | }) |
348 | }) | 351 | }) |
349 | 352 | ||
353 | describe('Deleting/cancelling a video import', function () { | ||
354 | let importId: number | ||
355 | |||
356 | async function importVideo () { | ||
357 | const attributes = { channelId: server.store.channel.id, targetUrl: FIXTURE_URLS.goodVideo } | ||
358 | const res = await server.imports.importVideo({ attributes }) | ||
359 | |||
360 | return res.id | ||
361 | } | ||
362 | |||
363 | before(async function () { | ||
364 | importId = await importVideo() | ||
365 | }) | ||
366 | |||
367 | it('Should fail with an invalid import id', async function () { | ||
368 | await server.imports.cancel({ importId: 'artyom' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
369 | await server.imports.delete({ importId: 'artyom' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
370 | }) | ||
371 | |||
372 | it('Should fail with an unknown import id', async function () { | ||
373 | await server.imports.cancel({ importId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | ||
374 | await server.imports.delete({ importId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | ||
375 | }) | ||
376 | |||
377 | it('Should fail without token', async function () { | ||
378 | await server.imports.cancel({ importId, token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | ||
379 | await server.imports.delete({ importId, token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | ||
380 | }) | ||
381 | |||
382 | it('Should fail with another user token', async function () { | ||
383 | await server.imports.cancel({ importId, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | ||
384 | await server.imports.delete({ importId, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | ||
385 | }) | ||
386 | |||
387 | it('Should fail to cancel non pending import', async function () { | ||
388 | this.timeout(60000) | ||
389 | |||
390 | await waitJobs([ server ]) | ||
391 | |||
392 | await server.imports.cancel({ importId, expectedStatus: HttpStatusCode.CONFLICT_409 }) | ||
393 | }) | ||
394 | |||
395 | it('Should succeed to delete an import', async function () { | ||
396 | await server.imports.delete({ importId }) | ||
397 | }) | ||
398 | |||
399 | it('Should fail to delete a pending import', async function () { | ||
400 | await server.jobs.pauseJobQueue() | ||
401 | |||
402 | importId = await importVideo() | ||
403 | |||
404 | await server.imports.delete({ importId, expectedStatus: HttpStatusCode.CONFLICT_409 }) | ||
405 | }) | ||
406 | |||
407 | it('Should succeed to cancel an import', async function () { | ||
408 | importId = await importVideo() | ||
409 | |||
410 | await server.imports.cancel({ importId }) | ||
411 | }) | ||
412 | }) | ||
413 | |||
350 | after(async function () { | 414 | after(async function () { |
351 | await cleanupTests([ server ]) | 415 | await cleanupTests([ server ]) |
352 | }) | 416 | }) |
diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index 4294e1fd5..bd8ffe188 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts | |||
@@ -11,6 +11,7 @@ import { | |||
11 | setAccessTokensToServers, | 11 | setAccessTokensToServers, |
12 | waitJobs | 12 | waitJobs |
13 | } from '@shared/server-commands' | 13 | } from '@shared/server-commands' |
14 | import { wait } from '@shared/core-utils' | ||
14 | 15 | ||
15 | const expect = chai.expect | 16 | const expect = chai.expect |
16 | 17 | ||
@@ -91,6 +92,30 @@ describe('Test jobs', function () { | |||
91 | expect(jobs.find(j => j.state === 'completed')).to.not.be.undefined | 92 | expect(jobs.find(j => j.state === 'completed')).to.not.be.undefined |
92 | }) | 93 | }) |
93 | 94 | ||
95 | it('Should pause the job queue', async function () { | ||
96 | this.timeout(120000) | ||
97 | |||
98 | await servers[1].jobs.pauseJobQueue() | ||
99 | |||
100 | await servers[1].videos.upload({ attributes: { name: 'video2' } }) | ||
101 | |||
102 | await wait(5000) | ||
103 | |||
104 | const body = await servers[1].jobs.list({ state: 'waiting', jobType: 'video-transcoding' }) | ||
105 | expect(body.data).to.have.lengthOf(1) | ||
106 | }) | ||
107 | |||
108 | it('Should resume the job queue', async function () { | ||
109 | this.timeout(120000) | ||
110 | |||
111 | await servers[1].jobs.resumeJobQueue() | ||
112 | |||
113 | await waitJobs(servers) | ||
114 | |||
115 | const body = await servers[1].jobs.list({ state: 'waiting', jobType: 'video-transcoding' }) | ||
116 | expect(body.data).to.have.lengthOf(0) | ||
117 | }) | ||
118 | |||
94 | after(async function () { | 119 | after(async function () { |
95 | await cleanupTests(servers) | 120 | await cleanupTests(servers) |
96 | }) | 121 | }) |
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index e8e0f01f1..ba21ab17a 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts | |||
@@ -6,7 +6,7 @@ import { pathExists, readdir, remove } from 'fs-extra' | |||
6 | import { join } from 'path' | 6 | import { join } from 'path' |
7 | import { FIXTURE_URLS, testCaptionFile, testImage } from '@server/tests/shared' | 7 | import { FIXTURE_URLS, testCaptionFile, testImage } from '@server/tests/shared' |
8 | import { areHttpImportTestsDisabled } from '@shared/core-utils' | 8 | import { areHttpImportTestsDisabled } from '@shared/core-utils' |
9 | import { VideoPrivacy, VideoResolution } from '@shared/models' | 9 | import { HttpStatusCode, Video, VideoImportState, VideoPrivacy, VideoResolution, VideoState } from '@shared/models' |
10 | import { | 10 | import { |
11 | cleanupTests, | 11 | cleanupTests, |
12 | createMultipleServers, | 12 | createMultipleServers, |
@@ -382,6 +382,85 @@ describe('Test video imports', function () { | |||
382 | 382 | ||
383 | runSuite('yt-dlp') | 383 | runSuite('yt-dlp') |
384 | 384 | ||
385 | describe('Delete/cancel an import', function () { | ||
386 | let server: PeerTubeServer | ||
387 | |||
388 | let finishedImportId: number | ||
389 | let finishedVideo: Video | ||
390 | let pendingImportId: number | ||
391 | |||
392 | async function importVideo (name: string) { | ||
393 | const attributes = { name, channelId: server.store.channel.id, targetUrl: FIXTURE_URLS.goodVideo } | ||
394 | const res = await server.imports.importVideo({ attributes }) | ||
395 | |||
396 | return res.id | ||
397 | } | ||
398 | |||
399 | before(async function () { | ||
400 | this.timeout(120_000) | ||
401 | |||
402 | server = await createSingleServer(1) | ||
403 | |||
404 | await setAccessTokensToServers([ server ]) | ||
405 | await setDefaultVideoChannel([ server ]) | ||
406 | |||
407 | finishedImportId = await importVideo('finished') | ||
408 | await waitJobs([ server ]) | ||
409 | |||
410 | await server.jobs.pauseJobQueue() | ||
411 | pendingImportId = await importVideo('pending') | ||
412 | |||
413 | const { data } = await server.imports.getMyVideoImports() | ||
414 | expect(data).to.have.lengthOf(2) | ||
415 | |||
416 | finishedVideo = data.find(i => i.id === finishedImportId).video | ||
417 | }) | ||
418 | |||
419 | it('Should delete a video import', async function () { | ||
420 | await server.imports.delete({ importId: finishedImportId }) | ||
421 | |||
422 | const { data } = await server.imports.getMyVideoImports() | ||
423 | expect(data).to.have.lengthOf(1) | ||
424 | expect(data[0].id).to.equal(pendingImportId) | ||
425 | expect(data[0].state.id).to.equal(VideoImportState.PENDING) | ||
426 | }) | ||
427 | |||
428 | it('Should not have deleted the associated video', async function () { | ||
429 | const video = await server.videos.get({ id: finishedVideo.id, token: server.accessToken, expectedStatus: HttpStatusCode.OK_200 }) | ||
430 | expect(video.name).to.equal('finished') | ||
431 | expect(video.state.id).to.equal(VideoState.PUBLISHED) | ||
432 | }) | ||
433 | |||
434 | it('Should cancel a video import', async function () { | ||
435 | await server.imports.cancel({ importId: pendingImportId }) | ||
436 | |||
437 | const { data } = await server.imports.getMyVideoImports() | ||
438 | expect(data).to.have.lengthOf(1) | ||
439 | expect(data[0].id).to.equal(pendingImportId) | ||
440 | expect(data[0].state.id).to.equal(VideoImportState.CANCELLED) | ||
441 | }) | ||
442 | |||
443 | it('Should not have processed the cancelled video import', async function () { | ||
444 | this.timeout(60_000) | ||
445 | |||
446 | await server.jobs.resumeJobQueue() | ||
447 | |||
448 | await waitJobs([ server ]) | ||
449 | |||
450 | const { data } = await server.imports.getMyVideoImports() | ||
451 | expect(data).to.have.lengthOf(1) | ||
452 | expect(data[0].id).to.equal(pendingImportId) | ||
453 | expect(data[0].state.id).to.equal(VideoImportState.CANCELLED) | ||
454 | expect(data[0].video.state.id).to.equal(VideoState.TO_IMPORT) | ||
455 | }) | ||
456 | |||
457 | it('Should delete the cancelled video import', async function () { | ||
458 | await server.imports.delete({ importId: pendingImportId }) | ||
459 | const { data } = await server.imports.getMyVideoImports() | ||
460 | expect(data).to.have.lengthOf(0) | ||
461 | }) | ||
462 | }) | ||
463 | |||
385 | describe('Auto update', function () { | 464 | describe('Auto update', function () { |
386 | let server: PeerTubeServer | 465 | let server: PeerTubeServer |
387 | 466 | ||