]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-captions.ts
Merge branch 'release/3.1.0' into develop
[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 {
7c3b7976 5 cleanupTests,
40e87e9e 6 createUser,
7c3b7976 7 flushAndRunServer,
40e87e9e
C
8 makeDeleteRequest,
9 makeGetRequest,
10 makeUploadRequest,
40e87e9e
C
11 ServerInfo,
12 setAccessTokensToServers,
13 uploadVideo,
14 userLogin
94565d52 15} from '../../../../shared/extra-utils'
40e87e9e 16import { join } from 'path'
94565d52 17import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
2d53be02 18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
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
25 let videoUUID: string
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, {})
38 videoUUID = res.body.video.uuid
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 = {
a1587156 54 captionfile: join(__dirname, '..', '..', 'fixtures', '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 () {
81 const captionPath = path + videoUUID + '/captions'
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 () {
93 const captionPath = path + videoUUID + '/captions/15'
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 () {
105 const captionPath = path + videoUUID + '/captions/fr'
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 () {
117 const captionPath = path + videoUUID + '/captions/fr'
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 = {
132 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt')
133 // }
134 //
135 // const captionPath = path + videoUUID + '/captions/fr'
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',
153 // videoId: videoUUID,
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 () {
161 await createVideoCaption({
162 url: server.url,
163 accessToken: server.accessToken,
164 language: 'zh',
165 videoId: videoUUID,
166 fixture: 'subtitle-good.srt',
167 mimeType: 'application/octet-stream'
168 })
169 })
170
171 // We don't check the file validity yet
f4001cf4
C
172 // it('Should fail with an invalid captionfile srt', async function () {
173 // const attaches = {
174 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
175 // }
176 //
177 // const captionPath = path + videoUUID + '/captions/fr'
178 // await makeUploadRequest({
179 // method: 'PUT',
180 // url: server.url,
181 // path: captionPath,
182 // token: server.accessToken,
183 // fields,
184 // attaches,
2d53be02 185 // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500
f4001cf4
C
186 // })
187 // })
188
40e87e9e
C
189 it('Should success with the correct parameters', async function () {
190 const captionPath = path + videoUUID + '/captions/fr'
191 await makeUploadRequest({
192 method: 'PUT',
193 url: server.url,
194 path: captionPath,
195 token: server.accessToken,
196 fields,
197 attaches,
2d53be02 198 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
40e87e9e
C
199 })
200 })
201 })
202
203 describe('When listing video captions', function () {
204 it('Should fail without a valid uuid', async function () {
205 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
206 })
207
208 it('Should fail with an unknown id', async function () {
2d53be02
RK
209 await makeGetRequest({
210 url: server.url,
211 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
212 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
213 })
40e87e9e
C
214 })
215
216 it('Should success with the correct parameters', async function () {
2d53be02 217 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 })
40e87e9e
C
218 })
219 })
220
221 describe('When deleting video caption', function () {
222 it('Should fail without a valid uuid', async function () {
223 await makeDeleteRequest({
224 url: server.url,
225 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
226 token: server.accessToken
227 })
228 })
229
230 it('Should fail with an unknown id', async function () {
231 await makeDeleteRequest({
232 url: server.url,
233 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
234 token: server.accessToken,
2d53be02 235 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
40e87e9e
C
236 })
237 })
238
239 it('Should fail with an invalid language', async function () {
240 await makeDeleteRequest({
241 url: server.url,
242 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
243 token: server.accessToken
244 })
245 })
246
247 it('Should fail with a missing language', async function () {
248 const captionPath = path + videoUUID + '/captions'
249 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
250 })
251
252 it('Should fail with an unknown language', async function () {
253 const captionPath = path + videoUUID + '/captions/15'
254 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
255 })
256
257 it('Should fail without access token', async function () {
258 const captionPath = path + videoUUID + '/captions/fr'
2d53be02 259 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
40e87e9e
C
260 })
261
262 it('Should fail with a bad access token', async function () {
263 const captionPath = path + videoUUID + '/captions/fr'
2d53be02 264 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
40e87e9e
C
265 })
266
267 it('Should fail with another user', async function () {
268 const captionPath = path + videoUUID + '/captions/fr'
2d53be02
RK
269 await makeDeleteRequest({
270 url: server.url,
271 path: captionPath,
272 token: userAccessToken,
273 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
274 })
40e87e9e
C
275 })
276
277 it('Should success with the correct parameters', async function () {
278 const captionPath = path + videoUUID + '/captions/fr'
2d53be02
RK
279 await makeDeleteRequest({
280 url: server.url,
281 path: captionPath,
282 token: server.accessToken,
283 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
284 })
40e87e9e
C
285 })
286 })
287
7c3b7976
C
288 after(async function () {
289 await cleanupTests([ server ])
40e87e9e
C
290 })
291})