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