1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { buildAbsoluteFixturePath } from '@shared/core-utils'
5 import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
13 setAccessTokensToServers
14 } from '@shared/server-commands'
16 describe('Test video captions API validator', function () {
17 const path = '/api/v1/videos/'
19 let server: PeerTubeServer
20 let userAccessToken: string
21 let video: VideoCreateResult
22 let privateVideo: VideoCreateResult
24 // ---------------------------------------------------------------
26 before(async function () {
29 server = await createSingleServer(1)
31 await setAccessTokensToServers([ server ])
33 video = await server.videos.upload()
34 privateVideo = await server.videos.upload({ attributes: { privacy: VideoPrivacy.PRIVATE } })
39 password: 'my super password'
41 await server.users.create({ username: user.username, password: user.password })
42 userAccessToken = await server.login.getAccessToken(user)
46 describe('When adding video caption', function () {
49 captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt')
52 it('Should fail without a valid uuid', async function () {
53 await makeUploadRequest({
56 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
57 token: server.accessToken,
63 it('Should fail with an unknown id', async function () {
64 await makeUploadRequest({
67 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
68 token: server.accessToken,
75 it('Should fail with a missing language in path', async function () {
76 const captionPath = path + video.uuid + '/captions'
77 await makeUploadRequest({
81 token: server.accessToken,
87 it('Should fail with an unknown language', async function () {
88 const captionPath = path + video.uuid + '/captions/15'
89 await makeUploadRequest({
93 token: server.accessToken,
99 it('Should fail without access token', async function () {
100 const captionPath = path + video.uuid + '/captions/fr'
101 await makeUploadRequest({
107 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
111 it('Should fail with a bad access token', async function () {
112 const captionPath = path + video.uuid + '/captions/fr'
113 await makeUploadRequest({
120 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
124 // We accept any file now
125 // it('Should fail with an invalid captionfile extension', async function () {
126 // const attaches = {
127 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt')
130 // const captionPath = path + video.uuid + '/captions/fr'
131 // await makeUploadRequest({
134 // path: captionPath,
135 // token: server.accessToken,
138 // expectedStatus: HttpStatusCode.BAD_REQUEST_400
142 // We don't check the extension yet
143 // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
144 // await createVideoCaption({
146 // accessToken: server.accessToken,
148 // videoId: video.uuid,
149 // fixture: 'subtitle-bad.txt',
150 // mimeType: 'application/octet-stream',
151 // expectedStatus: HttpStatusCode.BAD_REQUEST_400
155 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
156 await server.captions.add({
159 fixture: 'subtitle-good.srt',
160 mimeType: 'application/octet-stream'
164 // We don't check the file validity yet
165 // it('Should fail with an invalid captionfile srt', async function () {
166 // const attaches = {
167 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt')
170 // const captionPath = path + video.uuid + '/captions/fr'
171 // await makeUploadRequest({
174 // path: captionPath,
175 // token: server.accessToken,
178 // expectedStatus: HttpStatusCode.INTERNAL_SERVER_ERROR_500
182 it('Should success with the correct parameters', async function () {
183 const captionPath = path + video.uuid + '/captions/fr'
184 await makeUploadRequest({
188 token: server.accessToken,
191 expectedStatus: HttpStatusCode.NO_CONTENT_204
196 describe('When listing video captions', function () {
197 it('Should fail without a valid uuid', async function () {
198 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
201 it('Should fail with an unknown id', async function () {
202 await makeGetRequest({
204 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
205 expectedStatus: HttpStatusCode.NOT_FOUND_404
209 it('Should fail with a private video without token', async function () {
210 await makeGetRequest({
212 path: path + privateVideo.shortUUID + '/captions',
213 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
217 it('Should fail with another user token', async function () {
218 await makeGetRequest({
220 token: userAccessToken,
221 path: path + privateVideo.shortUUID + '/captions',
222 expectedStatus: HttpStatusCode.FORBIDDEN_403
226 it('Should success with the correct parameters', async function () {
227 await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', expectedStatus: HttpStatusCode.OK_200 })
229 await makeGetRequest({
231 path: path + privateVideo.shortUUID + '/captions',
232 token: server.accessToken,
233 expectedStatus: HttpStatusCode.OK_200
238 describe('When deleting video caption', function () {
239 it('Should fail without a valid uuid', async function () {
240 await makeDeleteRequest({
242 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
243 token: server.accessToken
247 it('Should fail with an unknown id', async function () {
248 await makeDeleteRequest({
250 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
251 token: server.accessToken,
252 expectedStatus: HttpStatusCode.NOT_FOUND_404
256 it('Should fail with an invalid language', async function () {
257 await makeDeleteRequest({
259 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
260 token: server.accessToken
264 it('Should fail with a missing language', async function () {
265 const captionPath = path + video.shortUUID + '/captions'
266 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
269 it('Should fail with an unknown language', async function () {
270 const captionPath = path + video.shortUUID + '/captions/15'
271 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
274 it('Should fail without access token', async function () {
275 const captionPath = path + video.shortUUID + '/captions/fr'
276 await makeDeleteRequest({ url: server.url, path: captionPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
279 it('Should fail with a bad access token', async function () {
280 const captionPath = path + video.shortUUID + '/captions/fr'
281 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
284 it('Should fail with another user', async function () {
285 const captionPath = path + video.shortUUID + '/captions/fr'
286 await makeDeleteRequest({
289 token: userAccessToken,
290 expectedStatus: HttpStatusCode.FORBIDDEN_403
294 it('Should success with the correct parameters', async function () {
295 const captionPath = path + video.shortUUID + '/captions/fr'
296 await makeDeleteRequest({
299 token: server.accessToken,
300 expectedStatus: HttpStatusCode.NO_CONTENT_204
305 after(async function () {
306 await cleanupTests([ server ])