1 /* tslint:disable:no-unused-expression */
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 it('Should fail with an invalid captionfile extension', async function () {
129 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt')
132 const captionPath = path + videoUUID + '/captions/fr'
133 await makeUploadRequest({
137 token: server.accessToken,
140 statusCodeExpected: 400
144 // We don't check the extension yet
145 // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
146 // await createVideoCaption({
148 // accessToken: server.accessToken,
150 // videoId: videoUUID,
151 // fixture: 'subtitle-bad.txt',
152 // mimeType: 'application/octet-stream',
153 // statusCodeExpected: 400
157 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
158 await createVideoCaption({
160 accessToken: server.accessToken,
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': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
174 // const captionPath = path + videoUUID + '/captions/fr'
175 // await makeUploadRequest({
178 // path: captionPath,
179 // token: server.accessToken,
182 // statusCodeExpected: 500
186 it('Should success with the correct parameters', async function () {
187 const captionPath = path + videoUUID + '/captions/fr'
188 await makeUploadRequest({
192 token: server.accessToken,
195 statusCodeExpected: 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({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', statusCodeExpected: 404 })
209 it('Should success with the correct parameters', async function () {
210 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: 200 })
214 describe('When deleting video caption', function () {
215 it('Should fail without a valid uuid', async function () {
216 await makeDeleteRequest({
218 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
219 token: server.accessToken
223 it('Should fail with an unknown id', async function () {
224 await makeDeleteRequest({
226 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
227 token: server.accessToken,
228 statusCodeExpected: 404
232 it('Should fail with an invalid language', async function () {
233 await makeDeleteRequest({
235 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
236 token: server.accessToken
240 it('Should fail with a missing language', async function () {
241 const captionPath = path + videoUUID + '/captions'
242 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
245 it('Should fail with an unknown language', async function () {
246 const captionPath = path + videoUUID + '/captions/15'
247 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
250 it('Should fail without access token', async function () {
251 const captionPath = path + videoUUID + '/captions/fr'
252 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: 401 })
255 it('Should fail with a bad access token', async function () {
256 const captionPath = path + videoUUID + '/captions/fr'
257 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: 401 })
260 it('Should fail with another user', async function () {
261 const captionPath = path + videoUUID + '/captions/fr'
262 await makeDeleteRequest({ url: server.url, path: captionPath, token: userAccessToken, statusCodeExpected: 403 })
265 it('Should success with the correct parameters', async function () {
266 const captionPath = path + videoUUID + '/captions/fr'
267 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken, statusCodeExpected: 204 })
271 after(async function () {
272 await cleanupTests([ server ])