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