]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/transcoding.ts
Merge branch 'release/4.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / transcoding.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import { HttpStatusCode, UserRole } from '@shared/models'
5 import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 PeerTubeServer,
10 setAccessTokensToServers,
11 waitJobs
12 } from '@shared/server-commands'
13
14 describe('Test transcoding API validators', function () {
15 let servers: PeerTubeServer[]
16
17 let userToken: string
18 let moderatorToken: string
19
20 let remoteId: string
21 let validId: string
22
23 // ---------------------------------------------------------------
24
25 before(async function () {
26 this.timeout(120000)
27
28 servers = await createMultipleServers(2)
29 await setAccessTokensToServers(servers)
30
31 await doubleFollow(servers[0], servers[1])
32
33 userToken = await servers[0].users.generateUserAndToken('user', UserRole.USER)
34 moderatorToken = await servers[0].users.generateUserAndToken('moderator', UserRole.MODERATOR)
35
36 {
37 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
38 remoteId = uuid
39 }
40
41 {
42 const { uuid } = await servers[0].videos.quickUpload({ name: 'both 1' })
43 validId = uuid
44 }
45
46 await waitJobs(servers)
47
48 await servers[0].config.enableTranscoding()
49 })
50
51 it('Should not run transcoding of a unknown video', async function () {
52 await servers[0].videos.runTranscoding({ videoId: 404, transcodingType: 'hls', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
53 await servers[0].videos.runTranscoding({ videoId: 404, transcodingType: 'webtorrent', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
54 })
55
56 it('Should not run transcoding of a remote video', async function () {
57 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
58
59 await servers[0].videos.runTranscoding({ videoId: remoteId, transcodingType: 'hls', expectedStatus })
60 await servers[0].videos.runTranscoding({ videoId: remoteId, transcodingType: 'webtorrent', expectedStatus })
61 })
62
63 it('Should not run transcoding by a non admin user', async function () {
64 const expectedStatus = HttpStatusCode.FORBIDDEN_403
65
66 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls', token: userToken, expectedStatus })
67 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', token: moderatorToken, expectedStatus })
68 })
69
70 it('Should not run transcoding without transcoding type', async function () {
71 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
72 })
73
74 it('Should not run transcoding with an incorrect transcoding type', async function () {
75 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
76
77 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'toto' as any, expectedStatus })
78 })
79
80 it('Should not run transcoding if the instance disabled it', async function () {
81 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
82
83 await servers[0].config.disableTranscoding()
84
85 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls', expectedStatus })
86 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', expectedStatus })
87 })
88
89 it('Should run transcoding', async function () {
90 this.timeout(120_000)
91
92 await servers[0].config.enableTranscoding()
93
94 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls' })
95 await waitJobs(servers)
96
97 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent' })
98 await waitJobs(servers)
99 })
100
101 it('Should not run transcoding on a video that is already being transcoded', async function () {
102 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent' })
103
104 const expectedStatus = HttpStatusCode.CONFLICT_409
105 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', expectedStatus })
106 })
107
108 after(async function () {
109 await cleanupTests(servers)
110 })
111 })