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