diff options
author | Chocobozzz <me@florianbigard.com> | 2021-11-18 14:35:08 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-11-18 15:20:57 +0100 |
commit | ad5db1044c8599eaaaa2a578b350777ae996b068 (patch) | |
tree | 3e003cccf021152405d49b21c6c91b703c8ae96c /server/tests/api/check-params/transcoding.ts | |
parent | b46cf4b920984492df598c1b61179acfc7f6f22e (diff) | |
download | PeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.tar.gz PeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.tar.zst PeerTube-ad5db1044c8599eaaaa2a578b350777ae996b068.zip |
Add ability to run transcoding jobs
Diffstat (limited to 'server/tests/api/check-params/transcoding.ts')
-rw-r--r-- | server/tests/api/check-params/transcoding.ts | 104 |
1 files changed, 104 insertions, 0 deletions
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 | |||
3 | import 'mocha' | ||
4 | import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' | ||
5 | import { HttpStatusCode, UserRole } from '@shared/models' | ||
6 | |||
7 | describe('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 | }) | ||