]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-captions.ts
Try to fix travis
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-captions.ts
CommitLineData
40e87e9e
C
1/* tslint:disable:no-unused-expression */
2
40e87e9e
C
3import 'mocha'
4import {
5 createUser,
6 flushTests,
7 killallServers,
8 makeDeleteRequest,
9 makeGetRequest,
10 makeUploadRequest,
210feb6c 11 flushAndRunServer,
40e87e9e
C
12 ServerInfo,
13 setAccessTokensToServers,
14 uploadVideo,
15 userLogin
94565d52 16} from '../../../../shared/extra-utils'
40e87e9e 17import { join } from 'path'
94565d52 18import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
40e87e9e
C
19
20describe('Test video captions API validator', function () {
21 const path = '/api/v1/videos/'
22
23 let server: ServerInfo
24 let userAccessToken: string
25 let videoUUID: string
26
27 // ---------------------------------------------------------------
28
29 before(async function () {
30 this.timeout(30000)
31
210feb6c 32 server = await flushAndRunServer(1)
40e87e9e
C
33
34 await setAccessTokensToServers([ server ])
35
36 {
37 const res = await uploadVideo(server.url, server.accessToken, {})
38 videoUUID = res.body.video.uuid
39 }
40
41 {
42 const user = {
43 username: 'user1',
44 password: 'my super password'
45 }
1eddc9a7 46 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
40e87e9e
C
47 userAccessToken = await userLogin(server, user)
48 }
49 })
50
51 describe('When adding video caption', function () {
52 const fields = { }
53 const attaches = {
54 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-good1.vtt')
55 }
56
57 it('Should fail without a valid uuid', async function () {
58 await makeUploadRequest({
59 method: 'PUT',
60 url: server.url,
61 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions',
62 token: server.accessToken,
63 fields,
64 attaches
65 })
66 })
67
68 it('Should fail with an unknown id', async function () {
69 await makeUploadRequest({
70 method: 'PUT',
71 url: server.url,
72 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
73 token: server.accessToken,
74 fields,
75 attaches
76 })
77 })
78
79 it('Should fail with a missing language in path', async function () {
80 const captionPath = path + videoUUID + '/captions'
81 await makeUploadRequest({
82 method: 'PUT',
83 url: server.url,
84 path: captionPath,
85 token: server.accessToken,
86 fields,
87 attaches
88 })
89 })
90
91 it('Should fail with an unknown language', async function () {
92 const captionPath = path + videoUUID + '/captions/15'
93 await makeUploadRequest({
94 method: 'PUT',
95 url: server.url,
96 path: captionPath,
97 token: server.accessToken,
98 fields,
99 attaches
100 })
101 })
102
103 it('Should fail without access token', async function () {
104 const captionPath = path + videoUUID + '/captions/fr'
105 await makeUploadRequest({
106 method: 'PUT',
107 url: server.url,
108 path: captionPath,
109 fields,
110 attaches,
111 statusCodeExpected: 401
112 })
113 })
114
115 it('Should fail with a bad access token', async function () {
116 const captionPath = path + videoUUID + '/captions/fr'
117 await makeUploadRequest({
118 method: 'PUT',
119 url: server.url,
120 path: captionPath,
121 token: 'blabla',
122 fields,
123 attaches,
124 statusCodeExpected: 401
125 })
126 })
127
f4001cf4
C
128 it('Should fail with an invalid captionfile extension', async function () {
129 const attaches = {
130 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt')
131 }
132
133 const captionPath = path + videoUUID + '/captions/fr'
134 await makeUploadRequest({
135 method: 'PUT',
136 url: server.url,
137 path: captionPath,
138 token: server.accessToken,
139 fields,
140 attaches,
141 statusCodeExpected: 400
142 })
143 })
144
2769e297
C
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({
148 // url: server.url,
149 // accessToken: server.accessToken,
150 // language: 'zh',
151 // videoId: videoUUID,
152 // fixture: 'subtitle-bad.txt',
153 // mimeType: 'application/octet-stream',
154 // statusCodeExpected: 400
155 // })
156 // })
157
158 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
159 await createVideoCaption({
160 url: server.url,
161 accessToken: server.accessToken,
162 language: 'zh',
163 videoId: videoUUID,
164 fixture: 'subtitle-good.srt',
165 mimeType: 'application/octet-stream'
166 })
167 })
168
169 // We don't check the file validity yet
f4001cf4
C
170 // it('Should fail with an invalid captionfile srt', async function () {
171 // const attaches = {
172 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
173 // }
174 //
175 // const captionPath = path + videoUUID + '/captions/fr'
176 // await makeUploadRequest({
177 // method: 'PUT',
178 // url: server.url,
179 // path: captionPath,
180 // token: server.accessToken,
181 // fields,
182 // attaches,
183 // statusCodeExpected: 500
184 // })
185 // })
186
40e87e9e
C
187 it('Should success with the correct parameters', async function () {
188 const captionPath = path + videoUUID + '/captions/fr'
189 await makeUploadRequest({
190 method: 'PUT',
191 url: server.url,
192 path: captionPath,
193 token: server.accessToken,
194 fields,
195 attaches,
196 statusCodeExpected: 204
197 })
198 })
199 })
200
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' })
204 })
205
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 })
208 })
209
210 it('Should success with the correct parameters', async function () {
211 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: 200 })
212 })
213 })
214
215 describe('When deleting video caption', function () {
216 it('Should fail without a valid uuid', async function () {
217 await makeDeleteRequest({
218 url: server.url,
219 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
220 token: server.accessToken
221 })
222 })
223
224 it('Should fail with an unknown id', async function () {
225 await makeDeleteRequest({
226 url: server.url,
227 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
228 token: server.accessToken,
229 statusCodeExpected: 404
230 })
231 })
232
233 it('Should fail with an invalid language', async function () {
234 await makeDeleteRequest({
235 url: server.url,
236 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
237 token: server.accessToken
238 })
239 })
240
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 })
244 })
245
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 })
249 })
250
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 })
254 })
255
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 })
259 })
260
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 })
264 })
265
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 })
269 })
270 })
271
210feb6c 272 after(function () {
40e87e9e 273 killallServers([ server ])
40e87e9e
C
274 })
275})