aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/jobs.ts43
-rw-r--r--server/tests/api/check-params/video-imports.ts66
2 files changed, 107 insertions, 2 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 @@
3import 'mocha' 3import 'mocha'
4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' 4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
5import { HttpStatusCode } from '@shared/models' 5import { HttpStatusCode } from '@shared/models'
6import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' 6import {
7 cleanupTests,
8 createSingleServer,
9 makeGetRequest,
10 makePostBodyRequest,
11 PeerTubeServer,
12 setAccessTokensToServers
13} from '@shared/server-commands'
7 14
8describe('Test jobs API validators', function () { 15describe('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
18describe('Test video imports API validator', function () { 20describe('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 })