]>
Commit | Line | Data |
---|---|---|
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 | userLogin | |
17 | } from '@shared/extra-utils' | |
18 | import { VideoCreateResult } from '@shared/models' | |
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 video: VideoCreateResult | |
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 | video = res.body.video | |
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: buildAbsoluteFixturePath('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 + video.uuid + '/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 + video.uuid + '/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 + video.uuid + '/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 + video.uuid + '/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': buildAbsoluteFixturePath('subtitle-bad.txt') | |
133 | // } | |
134 | // | |
135 | // const captionPath = path + video.uuid + '/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: video.uuid, | |
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 server.captionsCommand.createVideoCaption({ | |
162 | language: 'zh', | |
163 | videoId: video.uuid, | |
164 | fixture: 'subtitle-good.srt', | |
165 | mimeType: 'application/octet-stream' | |
166 | }) | |
167 | }) | |
168 | ||
169 | // We don't check the file validity yet | |
170 | // it('Should fail with an invalid captionfile srt', async function () { | |
171 | // const attaches = { | |
172 | // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt') | |
173 | // } | |
174 | // | |
175 | // const captionPath = path + video.uuid + '/captions/fr' | |
176 | // await makeUploadRequest({ | |
177 | // method: 'PUT', | |
178 | // url: server.url, | |
179 | // path: captionPath, | |
180 | // token: server.accessToken, | |
181 | // fields, | |
182 | // attaches, | |
183 | // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500 | |
184 | // }) | |
185 | // }) | |
186 | ||
187 | it('Should success with the correct parameters', async function () { | |
188 | const captionPath = path + video.uuid + '/captions/fr' | |
189 | await makeUploadRequest({ | |
190 | method: 'PUT', | |
191 | url: server.url, | |
192 | path: captionPath, | |
193 | token: server.accessToken, | |
194 | fields, | |
195 | attaches, | |
196 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
197 | }) | |
198 | }) | |
199 | }) | |
200 | ||
201 | describe('When listing video captions', function () { | |
202 | it('Should fail without a valid uuid', async function () { | |
203 | await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' }) | |
204 | }) | |
205 | ||
206 | it('Should fail with an unknown id', async function () { | |
207 | await makeGetRequest({ | |
208 | url: server.url, | |
209 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', | |
210 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
211 | }) | |
212 | }) | |
213 | ||
214 | it('Should success with the correct parameters', async function () { | |
215 | await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 }) | |
216 | }) | |
217 | }) | |
218 | ||
219 | describe('When deleting video caption', function () { | |
220 | it('Should fail without a valid uuid', async function () { | |
221 | await makeDeleteRequest({ | |
222 | url: server.url, | |
223 | path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr', | |
224 | token: server.accessToken | |
225 | }) | |
226 | }) | |
227 | ||
228 | it('Should fail with an unknown id', async function () { | |
229 | await makeDeleteRequest({ | |
230 | url: server.url, | |
231 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr', | |
232 | token: server.accessToken, | |
233 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
234 | }) | |
235 | }) | |
236 | ||
237 | it('Should fail with an invalid language', async function () { | |
238 | await makeDeleteRequest({ | |
239 | url: server.url, | |
240 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16', | |
241 | token: server.accessToken | |
242 | }) | |
243 | }) | |
244 | ||
245 | it('Should fail with a missing language', async function () { | |
246 | const captionPath = path + video.shortUUID + '/captions' | |
247 | await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken }) | |
248 | }) | |
249 | ||
250 | it('Should fail with an unknown language', async function () { | |
251 | const captionPath = path + video.shortUUID + '/captions/15' | |
252 | await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken }) | |
253 | }) | |
254 | ||
255 | it('Should fail without access token', async function () { | |
256 | const captionPath = path + video.shortUUID + '/captions/fr' | |
257 | await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) | |
258 | }) | |
259 | ||
260 | it('Should fail with a bad access token', async function () { | |
261 | const captionPath = path + video.shortUUID + '/captions/fr' | |
262 | await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) | |
263 | }) | |
264 | ||
265 | it('Should fail with another user', async function () { | |
266 | const captionPath = path + video.shortUUID + '/captions/fr' | |
267 | await makeDeleteRequest({ | |
268 | url: server.url, | |
269 | path: captionPath, | |
270 | token: userAccessToken, | |
271 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | |
272 | }) | |
273 | }) | |
274 | ||
275 | it('Should success with the correct parameters', async function () { | |
276 | const captionPath = path + video.shortUUID + '/captions/fr' | |
277 | await makeDeleteRequest({ | |
278 | url: server.url, | |
279 | path: captionPath, | |
280 | token: server.accessToken, | |
281 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
282 | }) | |
283 | }) | |
284 | }) | |
285 | ||
286 | after(async function () { | |
287 | await cleanupTests([ server ]) | |
288 | }) | |
289 | }) |