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