1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { HttpStatusCode, UserRole } from '@shared/models'
10 setAccessTokensToServers,
12 } from '@shared/server-commands'
14 describe('Test transcoding API validators', function () {
15 let servers: PeerTubeServer[]
18 let moderatorToken: string
23 // ---------------------------------------------------------------
25 before(async function () {
28 servers = await createMultipleServers(2)
29 await setAccessTokensToServers(servers)
31 await doubleFollow(servers[0], servers[1])
33 userToken = await servers[0].users.generateUserAndToken('user', UserRole.USER)
34 moderatorToken = await servers[0].users.generateUserAndToken('moderator', UserRole.MODERATOR)
37 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
42 const { uuid } = await servers[0].videos.quickUpload({ name: 'both 1' })
46 await waitJobs(servers)
48 await servers[0].config.enableTranscoding()
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 })
56 it('Should not run transcoding of a remote video', async function () {
57 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
59 await servers[0].videos.runTranscoding({ videoId: remoteId, transcodingType: 'hls', expectedStatus })
60 await servers[0].videos.runTranscoding({ videoId: remoteId, transcodingType: 'webtorrent', expectedStatus })
63 it('Should not run transcoding by a non admin user', async function () {
64 const expectedStatus = HttpStatusCode.FORBIDDEN_403
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 })
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 })
74 it('Should not run transcoding with an incorrect transcoding type', async function () {
75 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
77 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'toto' as any, expectedStatus })
80 it('Should not run transcoding if the instance disabled it', async function () {
81 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
83 await servers[0].config.disableTranscoding()
85 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls', expectedStatus })
86 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', expectedStatus })
89 it('Should run transcoding', async function () {
92 await servers[0].config.enableTranscoding()
94 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls' })
95 await waitJobs(servers)
97 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent' })
98 await waitJobs(servers)
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' })
104 const expectedStatus = HttpStatusCode.CONFLICT_409
105 await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'webtorrent', expectedStatus })
108 after(async function () {
109 await cleanupTests(servers)