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