1 /* tslint:disable:no-unused-expression */
13 setAccessTokensToServers,
17 import { join } from 'path'
18 import { createVideoCaption } from '../../utils/videos/video-captions'
20 describe('Test video captions API validator', function () {
21 const path = '/api/v1/videos/'
23 let server: ServerInfo
24 let userAccessToken: string
27 // ---------------------------------------------------------------
29 before(async function () {
34 server = await runServer(1)
36 await setAccessTokensToServers([ server ])
39 const res = await uploadVideo(server.url, server.accessToken, {})
40 videoUUID = res.body.video.uuid
46 password: 'my super password'
48 await createUser(server.url, server.accessToken, user.username, user.password)
49 userAccessToken = await userLogin(server, user)
53 describe('When adding video caption', function () {
56 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-good1.vtt')
59 it('Should fail without a valid uuid', async function () {
60 await makeUploadRequest({
63 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions',
64 token: server.accessToken,
70 it('Should fail with an unknown id', async function () {
71 await makeUploadRequest({
74 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
75 token: server.accessToken,
81 it('Should fail with a missing language in path', async function () {
82 const captionPath = path + videoUUID + '/captions'
83 await makeUploadRequest({
87 token: server.accessToken,
93 it('Should fail with an unknown language', async function () {
94 const captionPath = path + videoUUID + '/captions/15'
95 await makeUploadRequest({
99 token: server.accessToken,
105 it('Should fail without access token', async function () {
106 const captionPath = path + videoUUID + '/captions/fr'
107 await makeUploadRequest({
113 statusCodeExpected: 401
117 it('Should fail with a bad access token', async function () {
118 const captionPath = path + videoUUID + '/captions/fr'
119 await makeUploadRequest({
126 statusCodeExpected: 401
130 it('Should fail with an invalid captionfile extension', async function () {
132 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt')
135 const captionPath = path + videoUUID + '/captions/fr'
136 await makeUploadRequest({
140 token: server.accessToken,
143 statusCodeExpected: 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: videoUUID,
154 // fixture: 'subtitle-bad.txt',
155 // mimeType: 'application/octet-stream',
156 // statusCodeExpected: 400
160 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
161 await createVideoCaption({
163 accessToken: server.accessToken,
166 fixture: 'subtitle-good.srt',
167 mimeType: 'application/octet-stream'
171 // We don't check the file validity yet
172 // it('Should fail with an invalid captionfile srt', async function () {
173 // const attaches = {
174 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
177 // const captionPath = path + videoUUID + '/captions/fr'
178 // await makeUploadRequest({
181 // path: captionPath,
182 // token: server.accessToken,
185 // statusCodeExpected: 500
189 it('Should success with the correct parameters', async function () {
190 const captionPath = path + videoUUID + '/captions/fr'
191 await makeUploadRequest({
195 token: server.accessToken,
198 statusCodeExpected: 204
203 describe('When listing video captions', function () {
204 it('Should fail without a valid uuid', async function () {
205 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
208 it('Should fail with an unknown id', async function () {
209 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', statusCodeExpected: 404 })
212 it('Should success with the correct parameters', async function () {
213 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: 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: 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 + videoUUID + '/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 + videoUUID + '/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 + videoUUID + '/captions/fr'
255 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: 401 })
258 it('Should fail with a bad access token', async function () {
259 const captionPath = path + videoUUID + '/captions/fr'
260 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: 401 })
263 it('Should fail with another user', async function () {
264 const captionPath = path + videoUUID + '/captions/fr'
265 await makeDeleteRequest({ url: server.url, path: captionPath, token: userAccessToken, statusCodeExpected: 403 })
268 it('Should success with the correct parameters', async function () {
269 const captionPath = path + videoUUID + '/captions/fr'
270 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken, statusCodeExpected: 204 })
274 after(async function () {
275 killallServers([ server ])
277 // Keep the logs if the test failed