1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
14 setAccessTokensToServers,
18 import { join } from 'path'
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 success with the correct parameters', async function () {
131 const captionPath = path + videoUUID + '/captions/fr'
132 await makeUploadRequest({
136 token: server.accessToken,
139 statusCodeExpected: 204
144 describe('When listing video captions', function () {
145 it('Should fail without a valid uuid', async function () {
146 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
149 it('Should fail with an unknown id', async function () {
150 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', statusCodeExpected: 404 })
153 it('Should success with the correct parameters', async function () {
154 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: 200 })
158 describe('When deleting video caption', function () {
159 it('Should fail without a valid uuid', async function () {
160 await makeDeleteRequest({
162 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
163 token: server.accessToken
167 it('Should fail with an unknown id', async function () {
168 await makeDeleteRequest({
170 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
171 token: server.accessToken,
172 statusCodeExpected: 404
176 it('Should fail with an invalid language', async function () {
177 await makeDeleteRequest({
179 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
180 token: server.accessToken
184 it('Should fail with a missing language', async function () {
185 const captionPath = path + videoUUID + '/captions'
186 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
189 it('Should fail with an unknown language', async function () {
190 const captionPath = path + videoUUID + '/captions/15'
191 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
194 it('Should fail without access token', async function () {
195 const captionPath = path + videoUUID + '/captions/fr'
196 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: 401 })
199 it('Should fail with a bad access token', async function () {
200 const captionPath = path + videoUUID + '/captions/fr'
201 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: 401 })
204 it('Should fail with another user', async function () {
205 const captionPath = path + videoUUID + '/captions/fr'
206 await makeDeleteRequest({ url: server.url, path: captionPath, token: userAccessToken, statusCodeExpected: 403 })
209 it('Should success with the correct parameters', async function () {
210 const captionPath = path + videoUUID + '/captions/fr'
211 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken, statusCodeExpected: 204 })
215 after(async function () {
216 killallServers([ server ])
218 // Keep the logs if the test failed