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'
19 describe('Test video captions API validator', function () {
20 const path = '/api/v1/videos/'
22 let server: ServerInfo
23 let userAccessToken: string
26 // ---------------------------------------------------------------
28 before(async function () {
31 server = await flushAndRunServer(1)
33 await setAccessTokensToServers([ server ])
36 const res = await uploadVideo(server.url, server.accessToken, {})
37 videoUUID = res.body.video.uuid
43 password: 'my super password'
45 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
46 userAccessToken = await userLogin(server, user)
50 describe('When adding video caption', function () {
53 captionfile: join(__dirname, '..', '..', 'fixtures', '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',
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',
72 token: server.accessToken,
78 it('Should fail with a missing language in path', async function () {
79 const captionPath = path + videoUUID + '/captions'
80 await makeUploadRequest({
84 token: server.accessToken,
90 it('Should fail with an unknown language', async function () {
91 const captionPath = path + videoUUID + '/captions/15'
92 await makeUploadRequest({
96 token: server.accessToken,
102 it('Should fail without access token', async function () {
103 const captionPath = path + videoUUID + '/captions/fr'
104 await makeUploadRequest({
110 statusCodeExpected: 401
114 it('Should fail with a bad access token', async function () {
115 const captionPath = path + videoUUID + '/captions/fr'
116 await makeUploadRequest({
123 statusCodeExpected: 401
127 // We accept any file now
128 // it('Should fail with an invalid captionfile extension', async function () {
129 // const attaches = {
130 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt')
133 // const captionPath = path + videoUUID + '/captions/fr'
134 // await makeUploadRequest({
137 // path: captionPath,
138 // token: server.accessToken,
141 // statusCodeExpected: 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: videoUUID,
152 // fixture: 'subtitle-bad.txt',
153 // mimeType: 'application/octet-stream',
154 // statusCodeExpected: 400
158 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
159 await createVideoCaption({
161 accessToken: server.accessToken,
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': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
175 // const captionPath = path + videoUUID + '/captions/fr'
176 // await makeUploadRequest({
179 // path: captionPath,
180 // token: server.accessToken,
183 // statusCodeExpected: 500
187 it('Should success with the correct parameters', async function () {
188 const captionPath = path + videoUUID + '/captions/fr'
189 await makeUploadRequest({
193 token: server.accessToken,
196 statusCodeExpected: 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({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', statusCodeExpected: 404 })
210 it('Should success with the correct parameters', async function () {
211 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: 200 })
215 describe('When deleting video caption', function () {
216 it('Should fail without a valid uuid', async function () {
217 await makeDeleteRequest({
219 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
220 token: server.accessToken
224 it('Should fail with an unknown id', async function () {
225 await makeDeleteRequest({
227 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
228 token: server.accessToken,
229 statusCodeExpected: 404
233 it('Should fail with an invalid language', async function () {
234 await makeDeleteRequest({
236 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
237 token: server.accessToken
241 it('Should fail with a missing language', async function () {
242 const captionPath = path + videoUUID + '/captions'
243 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
246 it('Should fail with an unknown language', async function () {
247 const captionPath = path + videoUUID + '/captions/15'
248 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
251 it('Should fail without access token', async function () {
252 const captionPath = path + videoUUID + '/captions/fr'
253 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: 401 })
256 it('Should fail with a bad access token', async function () {
257 const captionPath = path + videoUUID + '/captions/fr'
258 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: 401 })
261 it('Should fail with another user', async function () {
262 const captionPath = path + videoUUID + '/captions/fr'
263 await makeDeleteRequest({ url: server.url, path: captionPath, token: userAccessToken, statusCodeExpected: 403 })
266 it('Should success with the correct parameters', async function () {
267 const captionPath = path + videoUUID + '/captions/fr'
268 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken, statusCodeExpected: 204 })
272 after(async function () {
273 await cleanupTests([ server ])