1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { VideoCreateResult } from '@shared/models'
5 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7 buildAbsoluteFixturePath,
15 setAccessTokensToServers,
18 } from '../../../../shared/extra-utils'
19 import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
21 describe('Test video captions API validator', function () {
22 const path = '/api/v1/videos/'
24 let server: ServerInfo
25 let userAccessToken: string
26 let video: VideoCreateResult
28 // ---------------------------------------------------------------
30 before(async function () {
33 server = await flushAndRunServer(1)
35 await setAccessTokensToServers([ server ])
38 const res = await uploadVideo(server.url, server.accessToken, {})
39 video = res.body.video
45 password: 'my super password'
47 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
48 userAccessToken = await userLogin(server, user)
52 describe('When adding video caption', function () {
55 captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt')
58 it('Should fail without a valid uuid', async function () {
59 await makeUploadRequest({
62 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
63 token: server.accessToken,
69 it('Should fail with an unknown id', async function () {
70 await makeUploadRequest({
73 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
74 token: server.accessToken,
77 statusCodeExpected: 404
81 it('Should fail with a missing language in path', async function () {
82 const captionPath = path + video.uuid + '/captions'
83 await makeUploadRequest({
87 token: server.accessToken,
93 it('Should fail with an unknown language', async function () {
94 const captionPath = path + video.uuid + '/captions/15'
95 await makeUploadRequest({
99 token: server.accessToken,
105 it('Should fail without access token', async function () {
106 const captionPath = path + video.uuid + '/captions/fr'
107 await makeUploadRequest({
113 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
117 it('Should fail with a bad access token', async function () {
118 const captionPath = path + video.uuid + '/captions/fr'
119 await makeUploadRequest({
126 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
130 // We accept any file now
131 // it('Should fail with an invalid captionfile extension', async function () {
132 // const attaches = {
133 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt')
136 // const captionPath = path + video.uuid + '/captions/fr'
137 // await makeUploadRequest({
140 // path: captionPath,
141 // token: server.accessToken,
144 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
148 // We don't check the extension yet
149 // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
150 // await createVideoCaption({
152 // accessToken: server.accessToken,
154 // videoId: video.uuid,
155 // fixture: 'subtitle-bad.txt',
156 // mimeType: 'application/octet-stream',
157 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
161 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
162 await createVideoCaption({
164 accessToken: server.accessToken,
167 fixture: 'subtitle-good.srt',
168 mimeType: 'application/octet-stream'
172 // We don't check the file validity yet
173 // it('Should fail with an invalid captionfile srt', async function () {
174 // const attaches = {
175 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt')
178 // const captionPath = path + video.uuid + '/captions/fr'
179 // await makeUploadRequest({
182 // path: captionPath,
183 // token: server.accessToken,
186 // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500
190 it('Should success with the correct parameters', async function () {
191 const captionPath = path + video.uuid + '/captions/fr'
192 await makeUploadRequest({
196 token: server.accessToken,
199 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
204 describe('When listing video captions', function () {
205 it('Should fail without a valid uuid', async function () {
206 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
209 it('Should fail with an unknown id', async function () {
210 await makeGetRequest({
212 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
213 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
217 it('Should success with the correct parameters', async function () {
218 await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 })
222 describe('When deleting video caption', function () {
223 it('Should fail without a valid uuid', async function () {
224 await makeDeleteRequest({
226 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
227 token: server.accessToken
231 it('Should fail with an unknown id', async function () {
232 await makeDeleteRequest({
234 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
235 token: server.accessToken,
236 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
240 it('Should fail with an invalid language', async function () {
241 await makeDeleteRequest({
243 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
244 token: server.accessToken
248 it('Should fail with a missing language', async function () {
249 const captionPath = path + video.shortUUID + '/captions'
250 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
253 it('Should fail with an unknown language', async function () {
254 const captionPath = path + video.shortUUID + '/captions/15'
255 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
258 it('Should fail without access token', async function () {
259 const captionPath = path + video.shortUUID + '/captions/fr'
260 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
263 it('Should fail with a bad access token', async function () {
264 const captionPath = path + video.shortUUID + '/captions/fr'
265 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
268 it('Should fail with another user', async function () {
269 const captionPath = path + video.shortUUID + '/captions/fr'
270 await makeDeleteRequest({
273 token: userAccessToken,
274 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
278 it('Should success with the correct parameters', async function () {
279 const captionPath = path + video.shortUUID + '/captions/fr'
280 await makeDeleteRequest({
283 token: server.accessToken,
284 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
289 after(async function () {
290 await cleanupTests([ server ])