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/fr',
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/fr',
73 token: server.accessToken,
76 statusCodeExpected: 404
80 it('Should fail with a missing language in path', async function () {
81 const captionPath = path + videoUUID + '/captions'
82 await makeUploadRequest({
86 token: server.accessToken,
92 it('Should fail with an unknown language', async function () {
93 const captionPath = path + videoUUID + '/captions/15'
94 await makeUploadRequest({
98 token: server.accessToken,
104 it('Should fail without access token', async function () {
105 const captionPath = path + videoUUID + '/captions/fr'
106 await makeUploadRequest({
112 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
116 it('Should fail with a bad access token', async function () {
117 const captionPath = path + videoUUID + '/captions/fr'
118 await makeUploadRequest({
125 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
129 // We accept any file now
130 // it('Should fail with an invalid captionfile extension', async function () {
131 // const attaches = {
132 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt')
135 // const captionPath = path + videoUUID + '/captions/fr'
136 // await makeUploadRequest({
139 // path: captionPath,
140 // token: server.accessToken,
143 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
147 // We don't check the extension yet
148 // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
149 // await createVideoCaption({
151 // accessToken: server.accessToken,
153 // videoId: videoUUID,
154 // fixture: 'subtitle-bad.txt',
155 // mimeType: 'application/octet-stream',
156 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
160 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
161 await createVideoCaption({
163 accessToken: server.accessToken,
166 fixture: 'subtitle-good.srt',
167 mimeType: 'application/octet-stream'
171 // We don't check the file validity yet
172 // it('Should fail with an invalid captionfile srt', async function () {
173 // const attaches = {
174 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
177 // const captionPath = path + videoUUID + '/captions/fr'
178 // await makeUploadRequest({
181 // path: captionPath,
182 // token: server.accessToken,
185 // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500
189 it('Should success with the correct parameters', async function () {
190 const captionPath = path + videoUUID + '/captions/fr'
191 await makeUploadRequest({
195 token: server.accessToken,
198 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
203 describe('When listing video captions', function () {
204 it('Should fail without a valid uuid', async function () {
205 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
208 it('Should fail with an unknown id', async function () {
209 await makeGetRequest({
211 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
212 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
216 it('Should success with the correct parameters', async function () {
217 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 })
221 describe('When deleting video caption', function () {
222 it('Should fail without a valid uuid', async function () {
223 await makeDeleteRequest({
225 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
226 token: server.accessToken
230 it('Should fail with an unknown id', async function () {
231 await makeDeleteRequest({
233 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
234 token: server.accessToken,
235 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
239 it('Should fail with an invalid language', async function () {
240 await makeDeleteRequest({
242 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
243 token: server.accessToken
247 it('Should fail with a missing language', async function () {
248 const captionPath = path + videoUUID + '/captions'
249 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
252 it('Should fail with an unknown language', async function () {
253 const captionPath = path + videoUUID + '/captions/15'
254 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
257 it('Should fail without access token', async function () {
258 const captionPath = path + videoUUID + '/captions/fr'
259 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
262 it('Should fail with a bad access token', async function () {
263 const captionPath = path + videoUUID + '/captions/fr'
264 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
267 it('Should fail with another user', async function () {
268 const captionPath = path + videoUUID + '/captions/fr'
269 await makeDeleteRequest({
272 token: userAccessToken,
273 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
277 it('Should success with the correct parameters', async function () {
278 const captionPath = path + videoUUID + '/captions/fr'
279 await makeDeleteRequest({
282 token: server.accessToken,
283 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
288 after(async function () {
289 await cleanupTests([ server ])