1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { HttpStatusCode } from '@shared/core-utils'
6 buildAbsoluteFixturePath,
14 setAccessTokensToServers,
17 } from '@shared/extra-utils'
18 import { VideoCreateResult } from '@shared/models'
20 describe('Test video captions API validator', function () {
21 const path = '/api/v1/videos/'
23 let server: ServerInfo
24 let userAccessToken: string
25 let video: VideoCreateResult
27 // ---------------------------------------------------------------
29 before(async function () {
32 server = await flushAndRunServer(1)
34 await setAccessTokensToServers([ server ])
37 const res = await uploadVideo(server.url, server.accessToken, {})
38 video = res.body.video
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: buildAbsoluteFixturePath('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 + video.uuid + '/captions'
82 await makeUploadRequest({
86 token: server.accessToken,
92 it('Should fail with an unknown language', async function () {
93 const captionPath = path + video.uuid + '/captions/15'
94 await makeUploadRequest({
98 token: server.accessToken,
104 it('Should fail without access token', async function () {
105 const captionPath = path + video.uuid + '/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 + video.uuid + '/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': buildAbsoluteFixturePath('subtitle-bad.txt')
135 // const captionPath = path + video.uuid + '/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: video.uuid,
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 server.captionsCommand.createVideoCaption({
164 fixture: 'subtitle-good.srt',
165 mimeType: 'application/octet-stream'
169 // We don't check the file validity yet
170 // it('Should fail with an invalid captionfile srt', async function () {
171 // const attaches = {
172 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt')
175 // const captionPath = path + video.uuid + '/captions/fr'
176 // await makeUploadRequest({
179 // path: captionPath,
180 // token: server.accessToken,
183 // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500
187 it('Should success with the correct parameters', async function () {
188 const captionPath = path + video.uuid + '/captions/fr'
189 await makeUploadRequest({
193 token: server.accessToken,
196 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
201 describe('When listing video captions', function () {
202 it('Should fail without a valid uuid', async function () {
203 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
206 it('Should fail with an unknown id', async function () {
207 await makeGetRequest({
209 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
210 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
214 it('Should success with the correct parameters', async function () {
215 await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 })
219 describe('When deleting video caption', function () {
220 it('Should fail without a valid uuid', async function () {
221 await makeDeleteRequest({
223 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
224 token: server.accessToken
228 it('Should fail with an unknown id', async function () {
229 await makeDeleteRequest({
231 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
232 token: server.accessToken,
233 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
237 it('Should fail with an invalid language', async function () {
238 await makeDeleteRequest({
240 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
241 token: server.accessToken
245 it('Should fail with a missing language', async function () {
246 const captionPath = path + video.shortUUID + '/captions'
247 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
250 it('Should fail with an unknown language', async function () {
251 const captionPath = path + video.shortUUID + '/captions/15'
252 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
255 it('Should fail without access token', async function () {
256 const captionPath = path + video.shortUUID + '/captions/fr'
257 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
260 it('Should fail with a bad access token', async function () {
261 const captionPath = path + video.shortUUID + '/captions/fr'
262 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
265 it('Should fail with another user', async function () {
266 const captionPath = path + video.shortUUID + '/captions/fr'
267 await makeDeleteRequest({
270 token: userAccessToken,
271 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
275 it('Should success with the correct parameters', async function () {
276 const captionPath = path + video.shortUUID + '/captions/fr'
277 await makeDeleteRequest({
280 token: server.accessToken,
281 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
286 after(async function () {
287 await cleanupTests([ server ])