]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-captions.ts
Fix live tests
[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,
61 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions',
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,
72 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
73 token: server.accessToken,
74 fields,
75 attaches
76 })
77 })
78
79 it('Should fail with a missing language in path', async function () {
80 const captionPath = path + videoUUID + '/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 + videoUUID + '/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 + videoUUID + '/captions/fr'
105 await makeUploadRequest({
106 method: 'PUT',
107 url: server.url,
108 path: captionPath,
109 fields,
110 attaches,
2d53be02 111 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
40e87e9e
C
112 })
113 })
114
115 it('Should fail with a bad access token', async function () {
116 const captionPath = path + videoUUID + '/captions/fr'
117 await makeUploadRequest({
118 method: 'PUT',
119 url: server.url,
120 path: captionPath,
121 token: 'blabla',
122 fields,
123 attaches,
2d53be02 124 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
40e87e9e
C
125 })
126 })
127
39a26b2e
C
128 // We accept any file now
129 // it('Should fail with an invalid captionfile extension', async function () {
130 // const attaches = {
131 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.txt')
132 // }
133 //
134 // const captionPath = path + videoUUID + '/captions/fr'
135 // await makeUploadRequest({
136 // method: 'PUT',
137 // url: server.url,
138 // path: captionPath,
139 // token: server.accessToken,
140 // fields,
141 // attaches,
2d53be02 142 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
39a26b2e
C
143 // })
144 // })
f4001cf4 145
2769e297
C
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: videoUUID,
153 // fixture: 'subtitle-bad.txt',
154 // mimeType: 'application/octet-stream',
2d53be02 155 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
2769e297
C
156 // })
157 // })
158
159 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
160 await createVideoCaption({
161 url: server.url,
162 accessToken: server.accessToken,
163 language: 'zh',
164 videoId: videoUUID,
165 fixture: 'subtitle-good.srt',
166 mimeType: 'application/octet-stream'
167 })
168 })
169
170 // We don't check the file validity yet
f4001cf4
C
171 // it('Should fail with an invalid captionfile srt', async function () {
172 // const attaches = {
173 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
174 // }
175 //
176 // const captionPath = path + videoUUID + '/captions/fr'
177 // await makeUploadRequest({
178 // method: 'PUT',
179 // url: server.url,
180 // path: captionPath,
181 // token: server.accessToken,
182 // fields,
183 // attaches,
2d53be02 184 // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500
f4001cf4
C
185 // })
186 // })
187
40e87e9e
C
188 it('Should success with the correct parameters', async function () {
189 const captionPath = path + videoUUID + '/captions/fr'
190 await makeUploadRequest({
191 method: 'PUT',
192 url: server.url,
193 path: captionPath,
194 token: server.accessToken,
195 fields,
196 attaches,
2d53be02 197 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
40e87e9e
C
198 })
199 })
200 })
201
202 describe('When listing video captions', function () {
203 it('Should fail without a valid uuid', async function () {
204 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
205 })
206
207 it('Should fail with an unknown id', async function () {
2d53be02
RK
208 await makeGetRequest({
209 url: server.url,
210 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
211 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
212 })
40e87e9e
C
213 })
214
215 it('Should success with the correct parameters', async function () {
2d53be02 216 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 })
40e87e9e
C
217 })
218 })
219
220 describe('When deleting video caption', function () {
221 it('Should fail without a valid uuid', async function () {
222 await makeDeleteRequest({
223 url: server.url,
224 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
225 token: server.accessToken
226 })
227 })
228
229 it('Should fail with an unknown id', async function () {
230 await makeDeleteRequest({
231 url: server.url,
232 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
233 token: server.accessToken,
2d53be02 234 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
40e87e9e
C
235 })
236 })
237
238 it('Should fail with an invalid language', async function () {
239 await makeDeleteRequest({
240 url: server.url,
241 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
242 token: server.accessToken
243 })
244 })
245
246 it('Should fail with a missing language', async function () {
247 const captionPath = path + videoUUID + '/captions'
248 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
249 })
250
251 it('Should fail with an unknown language', async function () {
252 const captionPath = path + videoUUID + '/captions/15'
253 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
254 })
255
256 it('Should fail without access token', async function () {
257 const captionPath = path + videoUUID + '/captions/fr'
2d53be02 258 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
40e87e9e
C
259 })
260
261 it('Should fail with a bad access token', async function () {
262 const captionPath = path + videoUUID + '/captions/fr'
2d53be02 263 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
40e87e9e
C
264 })
265
266 it('Should fail with another user', async function () {
267 const captionPath = path + videoUUID + '/captions/fr'
2d53be02
RK
268 await makeDeleteRequest({
269 url: server.url,
270 path: captionPath,
271 token: userAccessToken,
272 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
273 })
40e87e9e
C
274 })
275
276 it('Should success with the correct parameters', async function () {
277 const captionPath = path + videoUUID + '/captions/fr'
2d53be02
RK
278 await makeDeleteRequest({
279 url: server.url,
280 path: captionPath,
281 token: server.accessToken,
282 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
283 })
40e87e9e
C
284 })
285 })
286
7c3b7976
C
287 after(async function () {
288 await cleanupTests([ server ])
40e87e9e
C
289 })
290})