]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { | |
5 | cleanupTests, | |
6 | createUser, | |
7 | flushAndRunServer, | |
8 | makeDeleteRequest, | |
9 | makeGetRequest, | |
10 | makeUploadRequest, | |
11 | ServerInfo, | |
12 | setAccessTokensToServers, | |
13 | uploadVideo, | |
14 | userLogin | |
15 | } from '../../../../shared/extra-utils' | |
16 | import { join } from 'path' | |
17 | import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions' | |
18 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
19 | ||
20 | describe('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 | ||
32 | server = await flushAndRunServer(1) | |
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 | } | |
46 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
47 | userAccessToken = await userLogin(server, user) | |
48 | } | |
49 | }) | |
50 | ||
51 | describe('When adding video caption', function () { | |
52 | const fields = { } | |
53 | const attaches = { | |
54 | captionfile: join(__dirname, '..', '..', 'fixtures', 'subtitle-good1.vtt') | |
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/fr', | |
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/fr', | |
73 | token: server.accessToken, | |
74 | fields, | |
75 | attaches, | |
76 | statusCodeExpected: 404 | |
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, | |
112 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
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, | |
125 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
126 | }) | |
127 | }) | |
128 | ||
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, | |
143 | // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
144 | // }) | |
145 | // }) | |
146 | ||
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', | |
156 | // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
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 | |
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, | |
185 | // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500 | |
186 | // }) | |
187 | // }) | |
188 | ||
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, | |
198 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
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 () { | |
209 | await makeGetRequest({ | |
210 | url: server.url, | |
211 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', | |
212 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
213 | }) | |
214 | }) | |
215 | ||
216 | it('Should success with the correct parameters', async function () { | |
217 | await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 }) | |
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, | |
235 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
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' | |
259 | await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) | |
260 | }) | |
261 | ||
262 | it('Should fail with a bad access token', async function () { | |
263 | const captionPath = path + videoUUID + '/captions/fr' | |
264 | await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) | |
265 | }) | |
266 | ||
267 | it('Should fail with another user', async function () { | |
268 | const captionPath = path + videoUUID + '/captions/fr' | |
269 | await makeDeleteRequest({ | |
270 | url: server.url, | |
271 | path: captionPath, | |
272 | token: userAccessToken, | |
273 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | |
274 | }) | |
275 | }) | |
276 | ||
277 | it('Should success with the correct parameters', async function () { | |
278 | const captionPath = path + videoUUID + '/captions/fr' | |
279 | await makeDeleteRequest({ | |
280 | url: server.url, | |
281 | path: captionPath, | |
282 | token: server.accessToken, | |
283 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
284 | }) | |
285 | }) | |
286 | }) | |
287 | ||
288 | after(async function () { | |
289 | await cleanupTests([ server ]) | |
290 | }) | |
291 | }) |