1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { HttpStatusCode } from '@shared/core-utils'
6 buildAbsoluteFixturePath,
13 setAccessTokensToServers,
15 } from '@shared/extra-utils'
16 import { VideoCreateResult } from '@shared/models'
18 describe('Test video captions API validator', function () {
19 const path = '/api/v1/videos/'
21 let server: ServerInfo
22 let userAccessToken: string
23 let video: VideoCreateResult
25 // ---------------------------------------------------------------
27 before(async function () {
30 server = await flushAndRunServer(1)
32 await setAccessTokensToServers([ server ])
35 const res = await uploadVideo(server.url, server.accessToken, {})
36 video = res.body.video
42 password: 'my super password'
44 await server.usersCommand.create({ username: user.username, password: user.password })
45 userAccessToken = await server.loginCommand.getAccessToken(user)
49 describe('When adding video caption', function () {
52 captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt')
55 it('Should fail without a valid uuid', async function () {
56 await makeUploadRequest({
59 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
60 token: server.accessToken,
66 it('Should fail with an unknown id', async function () {
67 await makeUploadRequest({
70 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
71 token: server.accessToken,
74 statusCodeExpected: 404
78 it('Should fail with a missing language in path', async function () {
79 const captionPath = path + video.uuid + '/captions'
80 await makeUploadRequest({
84 token: server.accessToken,
90 it('Should fail with an unknown language', async function () {
91 const captionPath = path + video.uuid + '/captions/15'
92 await makeUploadRequest({
96 token: server.accessToken,
102 it('Should fail without access token', async function () {
103 const captionPath = path + video.uuid + '/captions/fr'
104 await makeUploadRequest({
110 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
114 it('Should fail with a bad access token', async function () {
115 const captionPath = path + video.uuid + '/captions/fr'
116 await makeUploadRequest({
123 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
127 // We accept any file now
128 // it('Should fail with an invalid captionfile extension', async function () {
129 // const attaches = {
130 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt')
133 // const captionPath = path + video.uuid + '/captions/fr'
134 // await makeUploadRequest({
137 // path: captionPath,
138 // token: server.accessToken,
141 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
145 // We don't check the extension yet
146 // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
147 // await createVideoCaption({
149 // accessToken: server.accessToken,
151 // videoId: video.uuid,
152 // fixture: 'subtitle-bad.txt',
153 // mimeType: 'application/octet-stream',
154 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
158 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
159 await server.captionsCommand.createVideoCaption({
162 fixture: 'subtitle-good.srt',
163 mimeType: 'application/octet-stream'
167 // We don't check the file validity yet
168 // it('Should fail with an invalid captionfile srt', async function () {
169 // const attaches = {
170 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt')
173 // const captionPath = path + video.uuid + '/captions/fr'
174 // await makeUploadRequest({
177 // path: captionPath,
178 // token: server.accessToken,
181 // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500
185 it('Should success with the correct parameters', async function () {
186 const captionPath = path + video.uuid + '/captions/fr'
187 await makeUploadRequest({
191 token: server.accessToken,
194 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
199 describe('When listing video captions', function () {
200 it('Should fail without a valid uuid', async function () {
201 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
204 it('Should fail with an unknown id', async function () {
205 await makeGetRequest({
207 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
208 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
212 it('Should success with the correct parameters', async function () {
213 await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 })
217 describe('When deleting video caption', function () {
218 it('Should fail without a valid uuid', async function () {
219 await makeDeleteRequest({
221 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
222 token: server.accessToken
226 it('Should fail with an unknown id', async function () {
227 await makeDeleteRequest({
229 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
230 token: server.accessToken,
231 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
235 it('Should fail with an invalid language', async function () {
236 await makeDeleteRequest({
238 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
239 token: server.accessToken
243 it('Should fail with a missing language', async function () {
244 const captionPath = path + video.shortUUID + '/captions'
245 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
248 it('Should fail with an unknown language', async function () {
249 const captionPath = path + video.shortUUID + '/captions/15'
250 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
253 it('Should fail without access token', async function () {
254 const captionPath = path + video.shortUUID + '/captions/fr'
255 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
258 it('Should fail with a bad access token', async function () {
259 const captionPath = path + video.shortUUID + '/captions/fr'
260 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
263 it('Should fail with another user', async function () {
264 const captionPath = path + video.shortUUID + '/captions/fr'
265 await makeDeleteRequest({
268 token: userAccessToken,
269 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
273 it('Should success with the correct parameters', async function () {
274 const captionPath = path + video.shortUUID + '/captions/fr'
275 await makeDeleteRequest({
278 token: server.accessToken,
279 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
284 after(async function () {
285 await cleanupTests([ server ])