1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
5 import { HttpStatusCode, UserRole } from '@shared/models'
7 describe('Test transcoding API validators', function () {
8 let servers: PeerTubeServer[]
11 let moderatorToken: string
16 // ---------------------------------------------------------------
18 before(async function () {
21 servers = await createMultipleServers(2)
22 await setAccessTokensToServers(servers)
24 await doubleFollow(servers[0], servers[1])
26 userToken = await servers[0].users.generateUserAndToken('user', UserRole.USER)
27 moderatorToken = await servers[0].users.generateUserAndToken('moderator', UserRole.MODERATOR)
30 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
35 const { uuid } = await servers[0].videos.quickUpload({ name: 'both 1' })
39 await waitJobs(servers)
41 await servers[0].config.enableTranscoding()
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 })
49 it('Should not run transcoding of a remote video', async function () {
50 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
52 await servers[0].videos.runTranscoding({ videoId: remoteId, transcodingType: 'hls', expectedStatus })
53 await servers[0].videos.runTranscoding({ videoId: remoteId, transcodingType: 'webtorrent', expectedStatus })
56 it('Should not run transcoding by a non admin user', async function () {
57 const expectedStatus = HttpStatusCode.FORBIDDEN_403
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 })
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 })
67 it('Should not run transcoding with an incorrect transcoding type', async function () {
68 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
70 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'toto' as any, expectedStatus })
73 it('Should not run transcoding if the instance disabled it', async function () {
74 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
76 await servers[0].config.disableTranscoding()
78 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls', expectedStatus })
79 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', expectedStatus })
82 it('Should run transcoding', async function () {
85 await servers[0].config.enableTranscoding()
87 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls' })
88 await waitJobs(servers)
90 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent' })
91 await waitJobs(servers)
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' })
97 const expectedStatus = HttpStatusCode.CONFLICT_409
98 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', expectedStatus })
101 after(async function () {
102 await cleanupTests(servers)