]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
40e87e9e | 2 | |
40e87e9e | 3 | import 'mocha' |
a2470c9f | 4 | import { HttpStatusCode } from '@shared/core-utils' |
40e87e9e | 5 | import { |
3d470a53 | 6 | buildAbsoluteFixturePath, |
7c3b7976 | 7 | cleanupTests, |
40e87e9e | 8 | createUser, |
7c3b7976 | 9 | flushAndRunServer, |
40e87e9e C |
10 | makeDeleteRequest, |
11 | makeGetRequest, | |
12 | makeUploadRequest, | |
40e87e9e C |
13 | ServerInfo, |
14 | setAccessTokensToServers, | |
41d1d075 | 15 | uploadVideo |
a2470c9f C |
16 | } from '@shared/extra-utils' |
17 | import { VideoCreateResult } from '@shared/models' | |
40e87e9e C |
18 | |
19 | describe('Test video captions API validator', function () { | |
20 | const path = '/api/v1/videos/' | |
21 | ||
22 | let server: ServerInfo | |
23 | let userAccessToken: string | |
d4a8e7a6 | 24 | let video: VideoCreateResult |
40e87e9e C |
25 | |
26 | // --------------------------------------------------------------- | |
27 | ||
28 | before(async function () { | |
29 | this.timeout(30000) | |
30 | ||
210feb6c | 31 | server = await flushAndRunServer(1) |
40e87e9e C |
32 | |
33 | await setAccessTokensToServers([ server ]) | |
34 | ||
35 | { | |
36 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
d4a8e7a6 | 37 | video = res.body.video |
40e87e9e C |
38 | } |
39 | ||
40 | { | |
41 | const user = { | |
42 | username: 'user1', | |
43 | password: 'my super password' | |
44 | } | |
1eddc9a7 | 45 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
41d1d075 | 46 | userAccessToken = await server.loginCommand.getAccessToken(user) |
40e87e9e C |
47 | } |
48 | }) | |
49 | ||
50 | describe('When adding video caption', function () { | |
51 | const fields = { } | |
52 | const attaches = { | |
3d470a53 | 53 | captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt') |
40e87e9e C |
54 | } |
55 | ||
56 | it('Should fail without a valid uuid', async function () { | |
57 | await makeUploadRequest({ | |
58 | method: 'PUT', | |
59 | url: server.url, | |
59fd824c | 60 | path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr', |
40e87e9e C |
61 | token: server.accessToken, |
62 | fields, | |
63 | attaches | |
64 | }) | |
65 | }) | |
66 | ||
67 | it('Should fail with an unknown id', async function () { | |
68 | await makeUploadRequest({ | |
69 | method: 'PUT', | |
70 | url: server.url, | |
59fd824c | 71 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr', |
40e87e9e C |
72 | token: server.accessToken, |
73 | fields, | |
59fd824c C |
74 | attaches, |
75 | statusCodeExpected: 404 | |
40e87e9e C |
76 | }) |
77 | }) | |
78 | ||
79 | it('Should fail with a missing language in path', async function () { | |
d4a8e7a6 | 80 | const captionPath = path + video.uuid + '/captions' |
40e87e9e C |
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 () { | |
d4a8e7a6 | 92 | const captionPath = path + video.uuid + '/captions/15' |
40e87e9e C |
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 () { | |
d4a8e7a6 | 104 | const captionPath = path + video.uuid + '/captions/fr' |
40e87e9e C |
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 () { | |
d4a8e7a6 | 116 | const captionPath = path + video.uuid + '/captions/fr' |
40e87e9e C |
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 = { | |
3d470a53 | 131 | // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt') |
39a26b2e C |
132 | // } |
133 | // | |
d4a8e7a6 | 134 | // const captionPath = path + video.uuid + '/captions/fr' |
39a26b2e C |
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', | |
d4a8e7a6 | 152 | // videoId: video.uuid, |
2769e297 C |
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 () { | |
a2470c9f | 160 | await server.captionsCommand.createVideoCaption({ |
2769e297 | 161 | language: 'zh', |
d4a8e7a6 | 162 | videoId: video.uuid, |
2769e297 C |
163 | fixture: 'subtitle-good.srt', |
164 | mimeType: 'application/octet-stream' | |
165 | }) | |
166 | }) | |
167 | ||
168 | // We don't check the file validity yet | |
f4001cf4 C |
169 | // it('Should fail with an invalid captionfile srt', async function () { |
170 | // const attaches = { | |
3d470a53 | 171 | // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt') |
f4001cf4 C |
172 | // } |
173 | // | |
d4a8e7a6 | 174 | // const captionPath = path + video.uuid + '/captions/fr' |
f4001cf4 C |
175 | // await makeUploadRequest({ |
176 | // method: 'PUT', | |
177 | // url: server.url, | |
178 | // path: captionPath, | |
179 | // token: server.accessToken, | |
180 | // fields, | |
181 | // attaches, | |
2d53be02 | 182 | // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500 |
f4001cf4 C |
183 | // }) |
184 | // }) | |
185 | ||
40e87e9e | 186 | it('Should success with the correct parameters', async function () { |
d4a8e7a6 | 187 | const captionPath = path + video.uuid + '/captions/fr' |
40e87e9e C |
188 | await makeUploadRequest({ |
189 | method: 'PUT', | |
190 | url: server.url, | |
191 | path: captionPath, | |
192 | token: server.accessToken, | |
193 | fields, | |
194 | attaches, | |
2d53be02 | 195 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
40e87e9e C |
196 | }) |
197 | }) | |
198 | }) | |
199 | ||
200 | describe('When listing video captions', function () { | |
201 | it('Should fail without a valid uuid', async function () { | |
202 | await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' }) | |
203 | }) | |
204 | ||
205 | it('Should fail with an unknown id', async function () { | |
2d53be02 RK |
206 | await makeGetRequest({ |
207 | url: server.url, | |
208 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', | |
209 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
210 | }) | |
40e87e9e C |
211 | }) |
212 | ||
213 | it('Should success with the correct parameters', async function () { | |
d4a8e7a6 | 214 | await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 }) |
40e87e9e C |
215 | }) |
216 | }) | |
217 | ||
218 | describe('When deleting video caption', function () { | |
219 | it('Should fail without a valid uuid', async function () { | |
220 | await makeDeleteRequest({ | |
221 | url: server.url, | |
222 | path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr', | |
223 | token: server.accessToken | |
224 | }) | |
225 | }) | |
226 | ||
227 | it('Should fail with an unknown id', async function () { | |
228 | await makeDeleteRequest({ | |
229 | url: server.url, | |
230 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr', | |
231 | token: server.accessToken, | |
2d53be02 | 232 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 |
40e87e9e C |
233 | }) |
234 | }) | |
235 | ||
236 | it('Should fail with an invalid language', async function () { | |
237 | await makeDeleteRequest({ | |
238 | url: server.url, | |
239 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16', | |
240 | token: server.accessToken | |
241 | }) | |
242 | }) | |
243 | ||
244 | it('Should fail with a missing language', async function () { | |
d4a8e7a6 | 245 | const captionPath = path + video.shortUUID + '/captions' |
40e87e9e C |
246 | await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken }) |
247 | }) | |
248 | ||
249 | it('Should fail with an unknown language', async function () { | |
d4a8e7a6 | 250 | const captionPath = path + video.shortUUID + '/captions/15' |
40e87e9e C |
251 | await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken }) |
252 | }) | |
253 | ||
254 | it('Should fail without access token', async function () { | |
d4a8e7a6 | 255 | const captionPath = path + video.shortUUID + '/captions/fr' |
2d53be02 | 256 | await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) |
40e87e9e C |
257 | }) |
258 | ||
259 | it('Should fail with a bad access token', async function () { | |
d4a8e7a6 | 260 | const captionPath = path + video.shortUUID + '/captions/fr' |
2d53be02 | 261 | await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) |
40e87e9e C |
262 | }) |
263 | ||
264 | it('Should fail with another user', async function () { | |
d4a8e7a6 | 265 | const captionPath = path + video.shortUUID + '/captions/fr' |
2d53be02 RK |
266 | await makeDeleteRequest({ |
267 | url: server.url, | |
268 | path: captionPath, | |
269 | token: userAccessToken, | |
270 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | |
271 | }) | |
40e87e9e C |
272 | }) |
273 | ||
274 | it('Should success with the correct parameters', async function () { | |
d4a8e7a6 | 275 | const captionPath = path + video.shortUUID + '/captions/fr' |
2d53be02 RK |
276 | await makeDeleteRequest({ |
277 | url: server.url, | |
278 | path: captionPath, | |
279 | token: server.accessToken, | |
280 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
281 | }) | |
40e87e9e C |
282 | }) |
283 | }) | |
284 | ||
7c3b7976 C |
285 | after(async function () { |
286 | await cleanupTests([ server ]) | |
40e87e9e C |
287 | }) |
288 | }) |