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