1 /* tslint:disable:no-unused-expression */
13 setAccessTokensToServers,
17 import { join } from 'path'
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 () {
33 server = await runServer(1)
35 await setAccessTokensToServers([ server ])
38 const res = await uploadVideo(server.url, server.accessToken, {})
39 videoUUID = res.body.video.uuid
45 password: 'my super password'
47 await createUser(server.url, server.accessToken, user.username, user.password)
48 userAccessToken = await userLogin(server, user)
52 describe('When adding video caption', function () {
55 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-good1.vtt')
58 it('Should fail without a valid uuid', async function () {
59 await makeUploadRequest({
62 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions',
63 token: server.accessToken,
69 it('Should fail with an unknown id', async function () {
70 await makeUploadRequest({
73 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
74 token: server.accessToken,
80 it('Should fail with a missing language in path', async function () {
81 const captionPath = path + videoUUID + '/captions'
82 await makeUploadRequest({
86 token: server.accessToken,
92 it('Should fail with an unknown language', async function () {
93 const captionPath = path + videoUUID + '/captions/15'
94 await makeUploadRequest({
98 token: server.accessToken,
104 it('Should fail without access token', async function () {
105 const captionPath = path + videoUUID + '/captions/fr'
106 await makeUploadRequest({
112 statusCodeExpected: 401
116 it('Should fail with a bad access token', async function () {
117 const captionPath = path + videoUUID + '/captions/fr'
118 await makeUploadRequest({
125 statusCodeExpected: 401
129 it('Should fail with an invalid captionfile extension', async function () {
131 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt')
134 const captionPath = path + videoUUID + '/captions/fr'
135 await makeUploadRequest({
139 token: server.accessToken,
142 statusCodeExpected: 400
146 // it('Should fail with an invalid captionfile srt', async function () {
147 // const attaches = {
148 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
151 // const captionPath = path + videoUUID + '/captions/fr'
152 // await makeUploadRequest({
155 // path: captionPath,
156 // token: server.accessToken,
159 // statusCodeExpected: 500
163 it('Should success with the correct parameters', async function () {
164 const captionPath = path + videoUUID + '/captions/fr'
165 await makeUploadRequest({
169 token: server.accessToken,
172 statusCodeExpected: 204
177 describe('When listing video captions', function () {
178 it('Should fail without a valid uuid', async function () {
179 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
182 it('Should fail with an unknown id', async function () {
183 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', statusCodeExpected: 404 })
186 it('Should success with the correct parameters', async function () {
187 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: 200 })
191 describe('When deleting video caption', function () {
192 it('Should fail without a valid uuid', async function () {
193 await makeDeleteRequest({
195 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
196 token: server.accessToken
200 it('Should fail with an unknown id', async function () {
201 await makeDeleteRequest({
203 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
204 token: server.accessToken,
205 statusCodeExpected: 404
209 it('Should fail with an invalid language', async function () {
210 await makeDeleteRequest({
212 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
213 token: server.accessToken
217 it('Should fail with a missing language', async function () {
218 const captionPath = path + videoUUID + '/captions'
219 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
222 it('Should fail with an unknown language', async function () {
223 const captionPath = path + videoUUID + '/captions/15'
224 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
227 it('Should fail without access token', async function () {
228 const captionPath = path + videoUUID + '/captions/fr'
229 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: 401 })
232 it('Should fail with a bad access token', async function () {
233 const captionPath = path + videoUUID + '/captions/fr'
234 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: 401 })
237 it('Should fail with another user', async function () {
238 const captionPath = path + videoUUID + '/captions/fr'
239 await makeDeleteRequest({ url: server.url, path: captionPath, token: userAccessToken, statusCodeExpected: 403 })
242 it('Should success with the correct parameters', async function () {
243 const captionPath = path + videoUUID + '/captions/fr'
244 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken, statusCodeExpected: 204 })
248 after(async function () {
249 killallServers([ server ])
251 // Keep the logs if the test failed