]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
40e87e9e 2
40e87e9e 3import 'mocha'
c55e3d72 4import { buildAbsoluteFixturePath } from '@shared/core-utils'
c3edc5b0 5import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
40e87e9e 6import {
7c3b7976 7 cleanupTests,
254d3579 8 createSingleServer,
40e87e9e
C
9 makeDeleteRequest,
10 makeGetRequest,
11 makeUploadRequest,
254d3579 12 PeerTubeServer,
d23dd9fb 13 setAccessTokensToServers
bf54587a 14} from '@shared/server-commands'
40e87e9e
C
15
16describe('Test video captions API validator', function () {
17 const path = '/api/v1/videos/'
18
254d3579 19 let server: PeerTubeServer
40e87e9e 20 let userAccessToken: string
d4a8e7a6 21 let video: VideoCreateResult
795212f7 22 let privateVideo: VideoCreateResult
40e87e9e
C
23
24 // ---------------------------------------------------------------
25
26 before(async function () {
27 this.timeout(30000)
28
254d3579 29 server = await createSingleServer(1)
40e87e9e
C
30
31 await setAccessTokensToServers([ server ])
32
89d241a7 33 video = await server.videos.upload()
795212f7 34 privateVideo = await server.videos.upload({ attributes: { privacy: VideoPrivacy.PRIVATE } })
40e87e9e
C
35
36 {
37 const user = {
38 username: 'user1',
39 password: 'my super password'
40 }
89d241a7
C
41 await server.users.create({ username: user.username, password: user.password })
42 userAccessToken = await server.login.getAccessToken(user)
40e87e9e
C
43 }
44 })
45
46 describe('When adding video caption', function () {
47 const fields = { }
48 const attaches = {
3d470a53 49 captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt')
40e87e9e
C
50 }
51
52 it('Should fail without a valid uuid', async function () {
53 await makeUploadRequest({
54 method: 'PUT',
55 url: server.url,
59fd824c 56 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
40e87e9e
C
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,
59fd824c 67 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
40e87e9e
C
68 token: server.accessToken,
69 fields,
59fd824c 70 attaches,
c0e8b12e 71 expectedStatus: 404
40e87e9e
C
72 })
73 })
74
75 it('Should fail with a missing language in path', async function () {
d4a8e7a6 76 const captionPath = path + video.uuid + '/captions'
40e87e9e
C
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 () {
d4a8e7a6 88 const captionPath = path + video.uuid + '/captions/15'
40e87e9e
C
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 () {
d4a8e7a6 100 const captionPath = path + video.uuid + '/captions/fr'
40e87e9e
C
101 await makeUploadRequest({
102 method: 'PUT',
103 url: server.url,
104 path: captionPath,
105 fields,
106 attaches,
c0e8b12e 107 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
40e87e9e
C
108 })
109 })
110
111 it('Should fail with a bad access token', async function () {
d4a8e7a6 112 const captionPath = path + video.uuid + '/captions/fr'
40e87e9e
C
113 await makeUploadRequest({
114 method: 'PUT',
115 url: server.url,
116 path: captionPath,
117 token: 'blabla',
118 fields,
119 attaches,
c0e8b12e 120 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
40e87e9e
C
121 })
122 })
123
39a26b2e
C
124 // We accept any file now
125 // it('Should fail with an invalid captionfile extension', async function () {
126 // const attaches = {
3d470a53 127 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt')
39a26b2e
C
128 // }
129 //
d4a8e7a6 130 // const captionPath = path + video.uuid + '/captions/fr'
39a26b2e
C
131 // await makeUploadRequest({
132 // method: 'PUT',
133 // url: server.url,
134 // path: captionPath,
135 // token: server.accessToken,
136 // fields,
137 // attaches,
c0e8b12e 138 // expectedStatus: HttpStatusCode.BAD_REQUEST_400
39a26b2e
C
139 // })
140 // })
f4001cf4 141
2769e297
C
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',
d4a8e7a6 148 // videoId: video.uuid,
2769e297
C
149 // fixture: 'subtitle-bad.txt',
150 // mimeType: 'application/octet-stream',
c0e8b12e 151 // expectedStatus: HttpStatusCode.BAD_REQUEST_400
2769e297
C
152 // })
153 // })
154
155 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
c63830f1 156 await server.captions.add({
2769e297 157 language: 'zh',
d4a8e7a6 158 videoId: video.uuid,
2769e297
C
159 fixture: 'subtitle-good.srt',
160 mimeType: 'application/octet-stream'
161 })
162 })
163
164 // We don't check the file validity yet
f4001cf4
C
165 // it('Should fail with an invalid captionfile srt', async function () {
166 // const attaches = {
3d470a53 167 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt')
f4001cf4
C
168 // }
169 //
d4a8e7a6 170 // const captionPath = path + video.uuid + '/captions/fr'
f4001cf4
C
171 // await makeUploadRequest({
172 // method: 'PUT',
173 // url: server.url,
174 // path: captionPath,
175 // token: server.accessToken,
176 // fields,
177 // attaches,
c0e8b12e 178 // expectedStatus: HttpStatusCode.INTERNAL_SERVER_ERROR_500
f4001cf4
C
179 // })
180 // })
181
40e87e9e 182 it('Should success with the correct parameters', async function () {
d4a8e7a6 183 const captionPath = path + video.uuid + '/captions/fr'
40e87e9e
C
184 await makeUploadRequest({
185 method: 'PUT',
186 url: server.url,
187 path: captionPath,
188 token: server.accessToken,
189 fields,
190 attaches,
c0e8b12e 191 expectedStatus: HttpStatusCode.NO_CONTENT_204
40e87e9e
C
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 () {
2d53be02
RK
202 await makeGetRequest({
203 url: server.url,
204 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
c0e8b12e 205 expectedStatus: HttpStatusCode.NOT_FOUND_404
2d53be02 206 })
40e87e9e
C
207 })
208
795212f7
C
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
40e87e9e 226 it('Should success with the correct parameters', async function () {
c0e8b12e 227 await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', expectedStatus: HttpStatusCode.OK_200 })
795212f7
C
228
229 await makeGetRequest({
230 url: server.url,
231 path: path + privateVideo.shortUUID + '/captions',
232 token: server.accessToken,
233 expectedStatus: HttpStatusCode.OK_200
234 })
40e87e9e
C
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,
c0e8b12e 252 expectedStatus: HttpStatusCode.NOT_FOUND_404
40e87e9e
C
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 () {
d4a8e7a6 265 const captionPath = path + video.shortUUID + '/captions'
40e87e9e
C
266 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
267 })
268
269 it('Should fail with an unknown language', async function () {
d4a8e7a6 270 const captionPath = path + video.shortUUID + '/captions/15'
40e87e9e
C
271 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
272 })
273
274 it('Should fail without access token', async function () {
d4a8e7a6 275 const captionPath = path + video.shortUUID + '/captions/fr'
c0e8b12e 276 await makeDeleteRequest({ url: server.url, path: captionPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
40e87e9e
C
277 })
278
279 it('Should fail with a bad access token', async function () {
d4a8e7a6 280 const captionPath = path + video.shortUUID + '/captions/fr'
c0e8b12e 281 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
40e87e9e
C
282 })
283
284 it('Should fail with another user', async function () {
d4a8e7a6 285 const captionPath = path + video.shortUUID + '/captions/fr'
2d53be02
RK
286 await makeDeleteRequest({
287 url: server.url,
288 path: captionPath,
289 token: userAccessToken,
c0e8b12e 290 expectedStatus: HttpStatusCode.FORBIDDEN_403
2d53be02 291 })
40e87e9e
C
292 })
293
294 it('Should success with the correct parameters', async function () {
d4a8e7a6 295 const captionPath = path + video.shortUUID + '/captions/fr'
2d53be02
RK
296 await makeDeleteRequest({
297 url: server.url,
298 path: captionPath,
299 token: server.accessToken,
c0e8b12e 300 expectedStatus: HttpStatusCode.NO_CONTENT_204
2d53be02 301 })
40e87e9e
C
302 })
303 })
304
7c3b7976
C
305 after(async function () {
306 await cleanupTests([ server ])
40e87e9e
C
307 })
308})