1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { HttpStatusCode } from '@shared/core-utils'
6 buildAbsoluteFixturePath,
14 setAccessTokensToServers,
16 } from '@shared/extra-utils'
17 import { VideoCreateResult } from '@shared/models'
19 describe('Test video captions API validator', function () {
20 const path = '/api/v1/videos/'
22 let server: ServerInfo
23 let userAccessToken: string
24 let video: VideoCreateResult
26 // ---------------------------------------------------------------
28 before(async function () {
31 server = await flushAndRunServer(1)
33 await setAccessTokensToServers([ server ])
36 const res = await uploadVideo(server.url, server.accessToken, {})
37 video = res.body.video
43 password: 'my super password'
45 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
46 userAccessToken = await server.loginCommand.getAccessToken(user)
50 describe('When adding video caption', function () {
53 captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt')
56 it('Should fail without a valid uuid', async function () {
57 await makeUploadRequest({
60 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
61 token: server.accessToken,
67 it('Should fail with an unknown id', async function () {
68 await makeUploadRequest({
71 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
72 token: server.accessToken,
75 statusCodeExpected: 404
79 it('Should fail with a missing language in path', async function () {
80 const captionPath = path + video.uuid + '/captions'
81 await makeUploadRequest({
85 token: server.accessToken,
91 it('Should fail with an unknown language', async function () {
92 const captionPath = path + video.uuid + '/captions/15'
93 await makeUploadRequest({
97 token: server.accessToken,
103 it('Should fail without access token', async function () {
104 const captionPath = path + video.uuid + '/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 + video.uuid + '/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': buildAbsoluteFixturePath('subtitle-bad.txt')
134 // const captionPath = path + video.uuid + '/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: video.uuid,
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 server.captionsCommand.createVideoCaption({
163 fixture: 'subtitle-good.srt',
164 mimeType: 'application/octet-stream'
168 // We don't check the file validity yet
169 // it('Should fail with an invalid captionfile srt', async function () {
170 // const attaches = {
171 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt')
174 // const captionPath = path + video.uuid + '/captions/fr'
175 // await makeUploadRequest({
178 // path: captionPath,
179 // token: server.accessToken,
182 // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500
186 it('Should success with the correct parameters', async function () {
187 const captionPath = path + video.uuid + '/captions/fr'
188 await makeUploadRequest({
192 token: server.accessToken,
195 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
200 describe('When listing video captions', function () {
201 it('Should fail without a valid uuid', async function () {
202 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
205 it('Should fail with an unknown id', async function () {
206 await makeGetRequest({
208 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
209 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
213 it('Should success with the correct parameters', async function () {
214 await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 })
218 describe('When deleting video caption', function () {
219 it('Should fail without a valid uuid', async function () {
220 await makeDeleteRequest({
222 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
223 token: server.accessToken
227 it('Should fail with an unknown id', async function () {
228 await makeDeleteRequest({
230 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
231 token: server.accessToken,
232 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
236 it('Should fail with an invalid language', async function () {
237 await makeDeleteRequest({
239 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
240 token: server.accessToken
244 it('Should fail with a missing language', async function () {
245 const captionPath = path + video.shortUUID + '/captions'
246 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
249 it('Should fail with an unknown language', async function () {
250 const captionPath = path + video.shortUUID + '/captions/15'
251 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
254 it('Should fail without access token', async function () {
255 const captionPath = path + video.shortUUID + '/captions/fr'
256 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
259 it('Should fail with a bad access token', async function () {
260 const captionPath = path + video.shortUUID + '/captions/fr'
261 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
264 it('Should fail with another user', async function () {
265 const captionPath = path + video.shortUUID + '/captions/fr'
266 await makeDeleteRequest({
269 token: userAccessToken,
270 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
274 it('Should success with the correct parameters', async function () {
275 const captionPath = path + video.shortUUID + '/captions/fr'
276 await makeDeleteRequest({
279 token: server.accessToken,
280 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
285 after(async function () {
286 await cleanupTests([ server ])