aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-11-18 14:35:08 +0100
committerChocobozzz <me@florianbigard.com>2021-11-18 15:20:57 +0100
commitad5db1044c8599eaaaa2a578b350777ae996b068 (patch)
tree3e003cccf021152405d49b21c6c91b703c8ae96c /server/tests/api/check-params
parentb46cf4b920984492df598c1b61179acfc7f6f22e (diff)
downloadPeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.tar.gz
PeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.tar.zst
PeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.zip
Add ability to run transcoding jobs
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/transcoding.ts104
-rw-r--r--server/tests/api/check-params/video-files.ts17
3 files changed, 121 insertions, 1 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index ff7dc4abb..e052296db 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -15,6 +15,7 @@ import './plugins'
15import './redundancy' 15import './redundancy'
16import './search' 16import './search'
17import './services' 17import './services'
18import './transcoding'
18import './upload-quota' 19import './upload-quota'
19import './user-notifications' 20import './user-notifications'
20import './user-subscriptions' 21import './user-subscriptions'
diff --git a/server/tests/api/check-params/transcoding.ts b/server/tests/api/check-params/transcoding.ts
new file mode 100644
index 000000000..a8daafe3e
--- /dev/null
+++ b/server/tests/api/check-params/transcoding.ts
@@ -0,0 +1,104 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
5import { HttpStatusCode, UserRole } from '@shared/models'
6
7describe('Test transcoding API validators', function () {
8 let servers: PeerTubeServer[]
9
10 let userToken: string
11 let moderatorToken: string
12
13 let remoteId: string
14 let validId: string
15
16 // ---------------------------------------------------------------
17
18 before(async function () {
19 this.timeout(60000)
20
21 servers = await createMultipleServers(2)
22 await setAccessTokensToServers(servers)
23
24 await doubleFollow(servers[0], servers[1])
25
26 userToken = await servers[0].users.generateUserAndToken('user', UserRole.USER)
27 moderatorToken = await servers[0].users.generateUserAndToken('moderator', UserRole.MODERATOR)
28
29 {
30 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
31 remoteId = uuid
32 }
33
34 {
35 const { uuid } = await servers[0].videos.quickUpload({ name: 'both 1' })
36 validId = uuid
37 }
38
39 await waitJobs(servers)
40
41 await servers[0].config.enableTranscoding()
42 })
43
44 it('Should not run transcoding of a unknown video', async function () {
45 await servers[0].videos.runTranscoding({ videoId: 404, transcodingType: 'hls', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
46 await servers[0].videos.runTranscoding({ videoId: 404, transcodingType: 'webtorrent', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
47 })
48
49 it('Should not run transcoding of a remote video', async function () {
50 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
51
52 await servers[0].videos.runTranscoding({ videoId: remoteId, transcodingType: 'hls', expectedStatus })
53 await servers[0].videos.runTranscoding({ videoId: remoteId, transcodingType: 'webtorrent', expectedStatus })
54 })
55
56 it('Should not run transcoding by a non admin user', async function () {
57 const expectedStatus = HttpStatusCode.FORBIDDEN_403
58
59 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls', token: userToken, expectedStatus })
60 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', token: moderatorToken, expectedStatus })
61 })
62
63 it('Should not run transcoding without transcoding type', async function () {
64 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
65 })
66
67 it('Should not run transcoding with an incorrect transcoding type', async function () {
68 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
69
70 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'toto' as any, expectedStatus })
71 })
72
73 it('Should not run transcoding if the instance disabled it', async function () {
74 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
75
76 await servers[0].config.disableTranscoding()
77
78 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls', expectedStatus })
79 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', expectedStatus })
80 })
81
82 it('Should run transcoding', async function () {
83 this.timeout(120_000)
84
85 await servers[0].config.enableTranscoding()
86
87 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls' })
88 await waitJobs(servers)
89
90 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent' })
91 await waitJobs(servers)
92 })
93
94 it('Should not run transcoding on a video that is already being transcoded', async function () {
95 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent' })
96
97 const expectedStatus = HttpStatusCode.CONFLICT_409
98 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', expectedStatus })
99 })
100
101 after(async function () {
102 await cleanupTests(servers)
103 })
104})
diff --git a/server/tests/api/check-params/video-files.ts b/server/tests/api/check-params/video-files.ts
index 48b10d2b5..61936d562 100644
--- a/server/tests/api/check-params/video-files.ts
+++ b/server/tests/api/check-params/video-files.ts
@@ -1,16 +1,19 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { cleanupTests, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' 4import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
5import { HttpStatusCode, UserRole } from '@shared/models' 5import { HttpStatusCode, UserRole } from '@shared/models'
6 6
7describe('Test videos files', function () { 7describe('Test videos files', function () {
8 let servers: PeerTubeServer[] 8 let servers: PeerTubeServer[]
9
9 let webtorrentId: string 10 let webtorrentId: string
10 let hlsId: string 11 let hlsId: string
11 let remoteId: string 12 let remoteId: string
13
12 let userToken: string 14 let userToken: string
13 let moderatorToken: string 15 let moderatorToken: string
16
14 let validId1: string 17 let validId1: string
15 let validId2: string 18 let validId2: string
16 19
@@ -22,10 +25,17 @@ describe('Test videos files', function () {
22 servers = await createMultipleServers(2) 25 servers = await createMultipleServers(2)
23 await setAccessTokensToServers(servers) 26 await setAccessTokensToServers(servers)
24 27
28 await doubleFollow(servers[0], servers[1])
29
25 userToken = await servers[0].users.generateUserAndToken('user', UserRole.USER) 30 userToken = await servers[0].users.generateUserAndToken('user', UserRole.USER)
26 moderatorToken = await servers[0].users.generateUserAndToken('moderator', UserRole.MODERATOR) 31 moderatorToken = await servers[0].users.generateUserAndToken('moderator', UserRole.MODERATOR)
27 32
28 { 33 {
34 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
35 remoteId = uuid
36 }
37
38 {
29 await servers[0].config.enableTranscoding(true, true) 39 await servers[0].config.enableTranscoding(true, true)
30 40
31 { 41 {
@@ -58,6 +68,11 @@ describe('Test videos files', function () {
58 await waitJobs(servers) 68 await waitJobs(servers)
59 }) 69 })
60 70
71 it('Should not delete files of a unknown video', async function () {
72 await servers[0].videos.removeHLSFiles({ videoId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
73 await servers[0].videos.removeWebTorrentFiles({ videoId: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
74 })
75
61 it('Should not delete files of a remote video', async function () { 76 it('Should not delete files of a remote video', async function () {
62 await servers[0].videos.removeHLSFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 77 await servers[0].videos.removeHLSFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
63 await servers[0].videos.removeWebTorrentFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 78 await servers[0].videos.removeWebTorrentFiles({ videoId: remoteId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })