]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-captions.ts
Introduce captions command
[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'
a2470c9f 4import { HttpStatusCode } from '@shared/core-utils'
40e87e9e 5import {
3d470a53 6 buildAbsoluteFixturePath,
7c3b7976 7 cleanupTests,
40e87e9e 8 createUser,
7c3b7976 9 flushAndRunServer,
40e87e9e
C
10 makeDeleteRequest,
11 makeGetRequest,
12 makeUploadRequest,
40e87e9e
C
13 ServerInfo,
14 setAccessTokensToServers,
15 uploadVideo,
16 userLogin
a2470c9f
C
17} from '@shared/extra-utils'
18import { VideoCreateResult } from '@shared/models'
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
d4a8e7a6 25 let video: VideoCreateResult
40e87e9e
C
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, {})
d4a8e7a6 38 video = res.body.video
40e87e9e
C
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 = {
3d470a53 54 captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt')
40e87e9e
C
55 }
56
57 it('Should fail without a valid uuid', async function () {
58 await makeUploadRequest({
59 method: 'PUT',
60 url: server.url,
59fd824c 61 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
40e87e9e
C
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,
59fd824c 72 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
40e87e9e
C
73 token: server.accessToken,
74 fields,
59fd824c
C
75 attaches,
76 statusCodeExpected: 404
40e87e9e
C
77 })
78 })
79
80 it('Should fail with a missing language in path', async function () {
d4a8e7a6 81 const captionPath = path + video.uuid + '/captions'
40e87e9e
C
82 await makeUploadRequest({
83 method: 'PUT',
84 url: server.url,
85 path: captionPath,
86 token: server.accessToken,
87 fields,
88 attaches
89 })
90 })
91
92 it('Should fail with an unknown language', async function () {
d4a8e7a6 93 const captionPath = path + video.uuid + '/captions/15'
40e87e9e
C
94 await makeUploadRequest({
95 method: 'PUT',
96 url: server.url,
97 path: captionPath,
98 token: server.accessToken,
99 fields,
100 attaches
101 })
102 })
103
104 it('Should fail without access token', async function () {
d4a8e7a6 105 const captionPath = path + video.uuid + '/captions/fr'
40e87e9e
C
106 await makeUploadRequest({
107 method: 'PUT',
108 url: server.url,
109 path: captionPath,
110 fields,
111 attaches,
2d53be02 112 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
40e87e9e
C
113 })
114 })
115
116 it('Should fail with a bad access token', async function () {
d4a8e7a6 117 const captionPath = path + video.uuid + '/captions/fr'
40e87e9e
C
118 await makeUploadRequest({
119 method: 'PUT',
120 url: server.url,
121 path: captionPath,
122 token: 'blabla',
123 fields,
124 attaches,
2d53be02 125 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
40e87e9e
C
126 })
127 })
128
39a26b2e
C
129 // We accept any file now
130 // it('Should fail with an invalid captionfile extension', async function () {
131 // const attaches = {
3d470a53 132 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt')
39a26b2e
C
133 // }
134 //
d4a8e7a6 135 // const captionPath = path + video.uuid + '/captions/fr'
39a26b2e
C
136 // await makeUploadRequest({
137 // method: 'PUT',
138 // url: server.url,
139 // path: captionPath,
140 // token: server.accessToken,
141 // fields,
142 // attaches,
2d53be02 143 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
39a26b2e
C
144 // })
145 // })
f4001cf4 146
2769e297
C
147 // We don't check the extension yet
148 // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
149 // await createVideoCaption({
150 // url: server.url,
151 // accessToken: server.accessToken,
152 // language: 'zh',
d4a8e7a6 153 // videoId: video.uuid,
2769e297
C
154 // fixture: 'subtitle-bad.txt',
155 // mimeType: 'application/octet-stream',
2d53be02 156 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
2769e297
C
157 // })
158 // })
159
160 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
a2470c9f 161 await server.captionsCommand.createVideoCaption({
2769e297 162 language: 'zh',
d4a8e7a6 163 videoId: video.uuid,
2769e297
C
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 = {
3d470a53 172 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt')
f4001cf4
C
173 // }
174 //
d4a8e7a6 175 // const captionPath = path + video.uuid + '/captions/fr'
f4001cf4
C
176 // await makeUploadRequest({
177 // method: 'PUT',
178 // url: server.url,
179 // path: captionPath,
180 // token: server.accessToken,
181 // fields,
182 // attaches,
2d53be02 183 // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500
f4001cf4
C
184 // })
185 // })
186
40e87e9e 187 it('Should success with the correct parameters', async function () {
d4a8e7a6 188 const captionPath = path + video.uuid + '/captions/fr'
40e87e9e
C
189 await makeUploadRequest({
190 method: 'PUT',
191 url: server.url,
192 path: captionPath,
193 token: server.accessToken,
194 fields,
195 attaches,
2d53be02 196 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
40e87e9e
C
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 () {
2d53be02
RK
207 await makeGetRequest({
208 url: server.url,
209 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
210 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
211 })
40e87e9e
C
212 })
213
214 it('Should success with the correct parameters', async function () {
d4a8e7a6 215 await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 })
40e87e9e
C
216 })
217 })
218
219 describe('When deleting video caption', function () {
220 it('Should fail without a valid uuid', async function () {
221 await makeDeleteRequest({
222 url: server.url,
223 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
224 token: server.accessToken
225 })
226 })
227
228 it('Should fail with an unknown id', async function () {
229 await makeDeleteRequest({
230 url: server.url,
231 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
232 token: server.accessToken,
2d53be02 233 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
40e87e9e
C
234 })
235 })
236
237 it('Should fail with an invalid language', async function () {
238 await makeDeleteRequest({
239 url: server.url,
240 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
241 token: server.accessToken
242 })
243 })
244
245 it('Should fail with a missing language', async function () {
d4a8e7a6 246 const captionPath = path + video.shortUUID + '/captions'
40e87e9e
C
247 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
248 })
249
250 it('Should fail with an unknown language', async function () {
d4a8e7a6 251 const captionPath = path + video.shortUUID + '/captions/15'
40e87e9e
C
252 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
253 })
254
255 it('Should fail without access token', async function () {
d4a8e7a6 256 const captionPath = path + video.shortUUID + '/captions/fr'
2d53be02 257 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
40e87e9e
C
258 })
259
260 it('Should fail with a bad access token', async function () {
d4a8e7a6 261 const captionPath = path + video.shortUUID + '/captions/fr'
2d53be02 262 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
40e87e9e
C
263 })
264
265 it('Should fail with another user', async function () {
d4a8e7a6 266 const captionPath = path + video.shortUUID + '/captions/fr'
2d53be02
RK
267 await makeDeleteRequest({
268 url: server.url,
269 path: captionPath,
270 token: userAccessToken,
271 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
272 })
40e87e9e
C
273 })
274
275 it('Should success with the correct parameters', async function () {
d4a8e7a6 276 const captionPath = path + video.shortUUID + '/captions/fr'
2d53be02
RK
277 await makeDeleteRequest({
278 url: server.url,
279 path: captionPath,
280 token: server.accessToken,
281 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
282 })
40e87e9e
C
283 })
284 })
285
7c3b7976
C
286 after(async function () {
287 await cleanupTests([ server ])
40e87e9e
C
288 })
289})