1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
12 setAccessTokensToServers,
15 } from '../../../../shared/extra-utils'
16 import { join } from 'path'
17 import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
18 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
20 describe('Test video captions API validator', function () {
21 const path = '/api/v1/videos/'
23 let server: ServerInfo
24 let userAccessToken: string
27 // ---------------------------------------------------------------
29 before(async function () {
32 server = await flushAndRunServer(1)
34 await setAccessTokensToServers([ server ])
37 const res = await uploadVideo(server.url, server.accessToken, {})
38 videoUUID = res.body.video.uuid
44 password: 'my super password'
46 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
47 userAccessToken = await userLogin(server, user)
51 describe('When adding video caption', function () {
54 captionfile: join(__dirname, '..', '..', 'fixtures', 'subtitle-good1.vtt')
57 it('Should fail without a valid uuid', async function () {
58 await makeUploadRequest({
61 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions',
62 token: server.accessToken,
68 it('Should fail with an unknown id', async function () {
69 await makeUploadRequest({
72 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
73 token: server.accessToken,
79 it('Should fail with a missing language in path', async function () {
80 const captionPath = path + videoUUID + '/captions'
81 await makeUploadRequest({
85 token: server.accessToken,
91 it('Should fail with an unknown language', async function () {
92 const captionPath = path + videoUUID + '/captions/15'
93 await makeUploadRequest({
97 token: server.accessToken,
103 it('Should fail without access token', async function () {
104 const captionPath = path + videoUUID + '/captions/fr'
105 await makeUploadRequest({
111 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
115 it('Should fail with a bad access token', async function () {
116 const captionPath = path + videoUUID + '/captions/fr'
117 await makeUploadRequest({
124 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
128 // We accept any file now
129 // it('Should fail with an invalid captionfile extension', async function () {
130 // const attaches = {
131 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt')
134 // const captionPath = path + videoUUID + '/captions/fr'
135 // await makeUploadRequest({
138 // path: captionPath,
139 // token: server.accessToken,
142 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
146 // We don't check the extension yet
147 // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
148 // await createVideoCaption({
150 // accessToken: server.accessToken,
152 // videoId: videoUUID,
153 // fixture: 'subtitle-bad.txt',
154 // mimeType: 'application/octet-stream',
155 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
159 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
160 await createVideoCaption({
162 accessToken: server.accessToken,
165 fixture: 'subtitle-good.srt',
166 mimeType: 'application/octet-stream'
170 // We don't check the file validity yet
171 // it('Should fail with an invalid captionfile srt', async function () {
172 // const attaches = {
173 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
176 // const captionPath = path + videoUUID + '/captions/fr'
177 // await makeUploadRequest({
180 // path: captionPath,
181 // token: server.accessToken,
184 // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500
188 it('Should success with the correct parameters', async function () {
189 const captionPath = path + videoUUID + '/captions/fr'
190 await makeUploadRequest({
194 token: server.accessToken,
197 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
202 describe('When listing video captions', function () {
203 it('Should fail without a valid uuid', async function () {
204 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
207 it('Should fail with an unknown id', async function () {
208 await makeGetRequest({
210 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
211 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
215 it('Should success with the correct parameters', async function () {
216 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 })
220 describe('When deleting video caption', function () {
221 it('Should fail without a valid uuid', async function () {
222 await makeDeleteRequest({
224 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
225 token: server.accessToken
229 it('Should fail with an unknown id', async function () {
230 await makeDeleteRequest({
232 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
233 token: server.accessToken,
234 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
238 it('Should fail with an invalid language', async function () {
239 await makeDeleteRequest({
241 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
242 token: server.accessToken
246 it('Should fail with a missing language', async function () {
247 const captionPath = path + videoUUID + '/captions'
248 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
251 it('Should fail with an unknown language', async function () {
252 const captionPath = path + videoUUID + '/captions/15'
253 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
256 it('Should fail without access token', async function () {
257 const captionPath = path + videoUUID + '/captions/fr'
258 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
261 it('Should fail with a bad access token', async function () {
262 const captionPath = path + videoUUID + '/captions/fr'
263 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
266 it('Should fail with another user', async function () {
267 const captionPath = path + videoUUID + '/captions/fr'
268 await makeDeleteRequest({
271 token: userAccessToken,
272 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
276 it('Should success with the correct parameters', async function () {
277 const captionPath = path + videoUUID + '/captions/fr'
278 await makeDeleteRequest({
281 token: server.accessToken,
282 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
287 after(async function () {
288 await cleanupTests([ server ])