1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { buildAbsoluteFixturePath } from '@shared/core-utils'
4 import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
12 setAccessTokensToServers
13 } from '@shared/server-commands'
15 describe('Test video captions API validator', function () {
16 const path = '/api/v1/videos/'
18 let server: PeerTubeServer
19 let userAccessToken: string
20 let video: VideoCreateResult
21 let privateVideo: VideoCreateResult
23 // ---------------------------------------------------------------
25 before(async function () {
28 server = await createSingleServer(1)
30 await setAccessTokensToServers([ server ])
32 video = await server.videos.upload()
33 privateVideo = await server.videos.upload({ attributes: { privacy: VideoPrivacy.PRIVATE } })
38 password: 'my super password'
40 await server.users.create({ username: user.username, password: user.password })
41 userAccessToken = await server.login.getAccessToken(user)
45 describe('When adding video caption', function () {
48 captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt')
51 it('Should fail without a valid uuid', async function () {
52 await makeUploadRequest({
55 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
56 token: server.accessToken,
62 it('Should fail with an unknown id', async function () {
63 await makeUploadRequest({
66 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
67 token: server.accessToken,
74 it('Should fail with a missing language in path', async function () {
75 const captionPath = path + video.uuid + '/captions'
76 await makeUploadRequest({
80 token: server.accessToken,
86 it('Should fail with an unknown language', async function () {
87 const captionPath = path + video.uuid + '/captions/15'
88 await makeUploadRequest({
92 token: server.accessToken,
98 it('Should fail without access token', async function () {
99 const captionPath = path + video.uuid + '/captions/fr'
100 await makeUploadRequest({
106 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
110 it('Should fail with a bad access token', async function () {
111 const captionPath = path + video.uuid + '/captions/fr'
112 await makeUploadRequest({
119 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
123 // We accept any file now
124 // it('Should fail with an invalid captionfile extension', async function () {
125 // const attaches = {
126 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt')
129 // const captionPath = path + video.uuid + '/captions/fr'
130 // await makeUploadRequest({
133 // path: captionPath,
134 // token: server.accessToken,
137 // expectedStatus: HttpStatusCode.BAD_REQUEST_400
141 // We don't check the extension yet
142 // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
143 // await createVideoCaption({
145 // accessToken: server.accessToken,
147 // videoId: video.uuid,
148 // fixture: 'subtitle-bad.txt',
149 // mimeType: 'application/octet-stream',
150 // expectedStatus: HttpStatusCode.BAD_REQUEST_400
154 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
155 await server.captions.add({
158 fixture: 'subtitle-good.srt',
159 mimeType: 'application/octet-stream'
163 // We don't check the file validity yet
164 // it('Should fail with an invalid captionfile srt', async function () {
165 // const attaches = {
166 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt')
169 // const captionPath = path + video.uuid + '/captions/fr'
170 // await makeUploadRequest({
173 // path: captionPath,
174 // token: server.accessToken,
177 // expectedStatus: HttpStatusCode.INTERNAL_SERVER_ERROR_500
181 it('Should success with the correct parameters', async function () {
182 const captionPath = path + video.uuid + '/captions/fr'
183 await makeUploadRequest({
187 token: server.accessToken,
190 expectedStatus: HttpStatusCode.NO_CONTENT_204
195 describe('When listing video captions', function () {
196 it('Should fail without a valid uuid', async function () {
197 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
200 it('Should fail with an unknown id', async function () {
201 await makeGetRequest({
203 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
204 expectedStatus: HttpStatusCode.NOT_FOUND_404
208 it('Should fail with a private video without token', async function () {
209 await makeGetRequest({
211 path: path + privateVideo.shortUUID + '/captions',
212 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
216 it('Should fail with another user token', async function () {
217 await makeGetRequest({
219 token: userAccessToken,
220 path: path + privateVideo.shortUUID + '/captions',
221 expectedStatus: HttpStatusCode.FORBIDDEN_403
225 it('Should success with the correct parameters', async function () {
226 await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', expectedStatus: HttpStatusCode.OK_200 })
228 await makeGetRequest({
230 path: path + privateVideo.shortUUID + '/captions',
231 token: server.accessToken,
232 expectedStatus: HttpStatusCode.OK_200
237 describe('When deleting video caption', function () {
238 it('Should fail without a valid uuid', async function () {
239 await makeDeleteRequest({
241 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
242 token: server.accessToken
246 it('Should fail with an unknown id', async function () {
247 await makeDeleteRequest({
249 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
250 token: server.accessToken,
251 expectedStatus: HttpStatusCode.NOT_FOUND_404
255 it('Should fail with an invalid language', async function () {
256 await makeDeleteRequest({
258 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
259 token: server.accessToken
263 it('Should fail with a missing language', async function () {
264 const captionPath = path + video.shortUUID + '/captions'
265 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
268 it('Should fail with an unknown language', async function () {
269 const captionPath = path + video.shortUUID + '/captions/15'
270 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
273 it('Should fail without access token', async function () {
274 const captionPath = path + video.shortUUID + '/captions/fr'
275 await makeDeleteRequest({ url: server.url, path: captionPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
278 it('Should fail with a bad access token', async function () {
279 const captionPath = path + video.shortUUID + '/captions/fr'
280 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
283 it('Should fail with another user', async function () {
284 const captionPath = path + video.shortUUID + '/captions/fr'
285 await makeDeleteRequest({
288 token: userAccessToken,
289 expectedStatus: HttpStatusCode.FORBIDDEN_403
293 it('Should success with the correct parameters', async function () {
294 const captionPath = path + video.shortUUID + '/captions/fr'
295 await makeDeleteRequest({
298 token: server.accessToken,
299 expectedStatus: HttpStatusCode.NO_CONTENT_204
304 after(async function () {
305 await cleanupTests([ server ])