]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
e2e22e40 C |
2 | |
3 | import 'mocha' | |
d4a8e7a6 C |
4 | import * as chai from 'chai' |
5 | import { VideoCreateResult } from '@shared/models' | |
6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
11ba2ab3 | 7 | import { |
7c3b7976 | 8 | cleanupTests, |
4cb6d457 | 9 | createUser, |
42e1ec25 | 10 | flushAndRunServer, |
42e1ec25 C |
11 | makeDeleteRequest, |
12 | makeGetRequest, | |
13 | makePostBodyRequest, | |
14 | ServerInfo, | |
15 | setAccessTokensToServers, | |
16 | uploadVideo, | |
17 | userLogin | |
94565d52 | 18 | } from '../../../../shared/extra-utils' |
9639bd17 | 19 | import { |
20 | checkBadCountPagination, | |
21 | checkBadSortPagination, | |
22 | checkBadStartPagination | |
94565d52 C |
23 | } from '../../../../shared/extra-utils/requests/check-api-params' |
24 | import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' | |
e2e22e40 | 25 | |
47564bbe C |
26 | const expect = chai.expect |
27 | ||
e2e22e40 C |
28 | describe('Test video comments API validator', function () { |
29 | let pathThread: string | |
30 | let pathComment: string | |
31 | let server: ServerInfo | |
d4a8e7a6 | 32 | let video: VideoCreateResult |
4cb6d457 | 33 | let userAccessToken: string |
fde37dc9 | 34 | let userAccessToken2: string |
e2e22e40 C |
35 | let commentId: number |
36 | ||
37 | // --------------------------------------------------------------- | |
38 | ||
39 | before(async function () { | |
e212f887 | 40 | this.timeout(30000) |
e2e22e40 | 41 | |
210feb6c | 42 | server = await flushAndRunServer(1) |
e2e22e40 C |
43 | |
44 | await setAccessTokensToServers([ server ]) | |
45 | ||
e2e22e40 C |
46 | { |
47 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
d4a8e7a6 C |
48 | video = res.body.video |
49 | pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' | |
e2e22e40 C |
50 | } |
51 | ||
52 | { | |
d4a8e7a6 | 53 | const res = await addVideoCommentThread(server.url, server.accessToken, video.uuid, 'coucou') |
e2e22e40 | 54 | commentId = res.body.comment.id |
d4a8e7a6 | 55 | pathComment = '/api/v1/videos/' + video.uuid + '/comments/' + commentId |
e2e22e40 | 56 | } |
4cb6d457 C |
57 | |
58 | { | |
fde37dc9 | 59 | const user = { username: 'user1', password: 'my super password' } |
1eddc9a7 | 60 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
4cb6d457 C |
61 | userAccessToken = await userLogin(server, user) |
62 | } | |
fde37dc9 C |
63 | |
64 | { | |
65 | const user = { username: 'user2', password: 'my super password' } | |
66 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
67 | userAccessToken2 = await userLogin(server, user) | |
68 | } | |
e2e22e40 C |
69 | }) |
70 | ||
71 | describe('When listing video comment threads', function () { | |
72 | it('Should fail with a bad start pagination', async function () { | |
11ba2ab3 | 73 | await checkBadStartPagination(server.url, pathThread, server.accessToken) |
e2e22e40 C |
74 | }) |
75 | ||
76 | it('Should fail with a bad count pagination', async function () { | |
11ba2ab3 | 77 | await checkBadCountPagination(server.url, pathThread, server.accessToken) |
e2e22e40 C |
78 | }) |
79 | ||
80 | it('Should fail with an incorrect sort', async function () { | |
11ba2ab3 | 81 | await checkBadSortPagination(server.url, pathThread, server.accessToken) |
e2e22e40 C |
82 | }) |
83 | ||
84 | it('Should fail with an incorrect video', async function () { | |
11ba2ab3 C |
85 | await makeGetRequest({ |
86 | url: server.url, | |
87 | path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads', | |
2d53be02 | 88 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 |
11ba2ab3 | 89 | }) |
e2e22e40 C |
90 | }) |
91 | }) | |
92 | ||
93 | describe('When listing comments of a thread', function () { | |
94 | it('Should fail with an incorrect video', async function () { | |
11ba2ab3 C |
95 | await makeGetRequest({ |
96 | url: server.url, | |
97 | path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId, | |
2d53be02 | 98 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 |
11ba2ab3 | 99 | }) |
e2e22e40 C |
100 | }) |
101 | ||
102 | it('Should fail with an incorrect thread id', async function () { | |
11ba2ab3 C |
103 | await makeGetRequest({ |
104 | url: server.url, | |
d4a8e7a6 | 105 | path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/156', |
2d53be02 | 106 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 |
11ba2ab3 | 107 | }) |
e2e22e40 C |
108 | }) |
109 | ||
110 | it('Should success with the correct params', async function () { | |
11ba2ab3 C |
111 | await makeGetRequest({ |
112 | url: server.url, | |
d4a8e7a6 | 113 | path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/' + commentId, |
2d53be02 | 114 | statusCodeExpected: HttpStatusCode.OK_200 |
11ba2ab3 | 115 | }) |
e2e22e40 C |
116 | }) |
117 | }) | |
118 | ||
119 | describe('When adding a video thread', function () { | |
120 | ||
121 | it('Should fail with a non authenticated user', async function () { | |
122 | const fields = { | |
123 | text: 'text' | |
124 | } | |
2d53be02 RK |
125 | await makePostBodyRequest({ |
126 | url: server.url, | |
127 | path: pathThread, | |
128 | token: 'none', | |
129 | fields, | |
130 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
131 | }) | |
e2e22e40 C |
132 | }) |
133 | ||
134 | it('Should fail with nothing', async function () { | |
135 | const fields = {} | |
136 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields }) | |
137 | }) | |
138 | ||
139 | it('Should fail with a short comment', async function () { | |
140 | const fields = { | |
53eb90c0 | 141 | text: '' |
e2e22e40 C |
142 | } |
143 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields }) | |
144 | }) | |
145 | ||
146 | it('Should fail with a long comment', async function () { | |
147 | const fields = { | |
298b3fd3 | 148 | text: 'h'.repeat(10001) |
e2e22e40 C |
149 | } |
150 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields }) | |
151 | }) | |
152 | ||
153 | it('Should fail with an incorrect video', async function () { | |
154 | const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads' | |
155 | const fields = { | |
156 | text: 'super comment' | |
157 | } | |
2d53be02 RK |
158 | await makePostBodyRequest({ |
159 | url: server.url, | |
160 | path, | |
161 | token: server.accessToken, | |
162 | fields, | |
163 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
164 | }) | |
e2e22e40 C |
165 | }) |
166 | ||
167 | it('Should succeed with the correct parameters', async function () { | |
168 | const fields = { | |
169 | text: 'super comment' | |
170 | } | |
2d53be02 RK |
171 | await makePostBodyRequest({ |
172 | url: server.url, | |
173 | path: pathThread, | |
174 | token: server.accessToken, | |
175 | fields, | |
176 | statusCodeExpected: HttpStatusCode.OK_200 | |
177 | }) | |
e2e22e40 C |
178 | }) |
179 | }) | |
180 | ||
181 | describe('When adding a comment to a thread', function () { | |
182 | it('Should fail with a non authenticated user', async function () { | |
183 | const fields = { | |
184 | text: 'text' | |
185 | } | |
2d53be02 RK |
186 | await makePostBodyRequest({ |
187 | url: server.url, | |
188 | path: pathComment, | |
189 | token: 'none', | |
190 | fields, | |
191 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
192 | }) | |
e2e22e40 C |
193 | }) |
194 | ||
195 | it('Should fail with nothing', async function () { | |
196 | const fields = {} | |
197 | await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields }) | |
198 | }) | |
199 | ||
200 | it('Should fail with a short comment', async function () { | |
201 | const fields = { | |
53eb90c0 | 202 | text: '' |
e2e22e40 C |
203 | } |
204 | await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields }) | |
205 | }) | |
206 | ||
207 | it('Should fail with a long comment', async function () { | |
208 | const fields = { | |
298b3fd3 | 209 | text: 'h'.repeat(10001) |
e2e22e40 C |
210 | } |
211 | await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields }) | |
212 | }) | |
213 | ||
214 | it('Should fail with an incorrect video', async function () { | |
215 | const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId | |
216 | const fields = { | |
217 | text: 'super comment' | |
218 | } | |
2d53be02 RK |
219 | await makePostBodyRequest({ |
220 | url: server.url, | |
221 | path, | |
222 | token: server.accessToken, | |
223 | fields, | |
224 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
225 | }) | |
e2e22e40 C |
226 | }) |
227 | ||
228 | it('Should fail with an incorrect comment', async function () { | |
d4a8e7a6 | 229 | const path = '/api/v1/videos/' + video.uuid + '/comments/124' |
e2e22e40 C |
230 | const fields = { |
231 | text: 'super comment' | |
232 | } | |
2d53be02 RK |
233 | await makePostBodyRequest({ |
234 | url: server.url, | |
235 | path, | |
236 | token: server.accessToken, | |
237 | fields, | |
238 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
239 | }) | |
e2e22e40 C |
240 | }) |
241 | ||
242 | it('Should succeed with the correct parameters', async function () { | |
243 | const fields = { | |
244 | text: 'super comment' | |
245 | } | |
2d53be02 RK |
246 | await makePostBodyRequest({ |
247 | url: server.url, | |
248 | path: pathComment, | |
249 | token: server.accessToken, | |
250 | fields, | |
251 | statusCodeExpected: HttpStatusCode.OK_200 | |
252 | }) | |
e2e22e40 C |
253 | }) |
254 | }) | |
255 | ||
4cb6d457 C |
256 | describe('When removing video comments', function () { |
257 | it('Should fail with a non authenticated user', async function () { | |
2d53be02 | 258 | await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) |
4cb6d457 C |
259 | }) |
260 | ||
261 | it('Should fail with another user', async function () { | |
2d53be02 RK |
262 | await makeDeleteRequest({ |
263 | url: server.url, | |
264 | path: pathComment, | |
265 | token: userAccessToken, | |
266 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | |
267 | }) | |
4cb6d457 C |
268 | }) |
269 | ||
270 | it('Should fail with an incorrect video', async function () { | |
271 | const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId | |
2d53be02 | 272 | await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) |
4cb6d457 C |
273 | }) |
274 | ||
275 | it('Should fail with an incorrect comment', async function () { | |
d4a8e7a6 | 276 | const path = '/api/v1/videos/' + video.uuid + '/comments/124' |
2d53be02 | 277 | await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) |
4cb6d457 C |
278 | }) |
279 | ||
fde37dc9 C |
280 | it('Should succeed with the same user', async function () { |
281 | let commentToDelete: number | |
282 | ||
283 | { | |
d4a8e7a6 | 284 | const res = await addVideoCommentThread(server.url, userAccessToken, video.uuid, 'hello') |
fde37dc9 C |
285 | commentToDelete = res.body.comment.id |
286 | } | |
287 | ||
d4a8e7a6 | 288 | const path = '/api/v1/videos/' + video.uuid + '/comments/' + commentToDelete |
fde37dc9 | 289 | |
2d53be02 RK |
290 | await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) |
291 | await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) | |
fde37dc9 C |
292 | }) |
293 | ||
294 | it('Should succeed with the owner of the video', async function () { | |
295 | let commentToDelete: number | |
296 | let anotherVideoUUID: string | |
297 | ||
298 | { | |
299 | const res = await uploadVideo(server.url, userAccessToken, { name: 'video' }) | |
300 | anotherVideoUUID = res.body.video.uuid | |
301 | } | |
302 | ||
303 | { | |
304 | const res = await addVideoCommentThread(server.url, server.accessToken, anotherVideoUUID, 'hello') | |
305 | commentToDelete = res.body.comment.id | |
306 | } | |
307 | ||
308 | const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete | |
309 | ||
2d53be02 RK |
310 | await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) |
311 | await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) | |
fde37dc9 C |
312 | }) |
313 | ||
4cb6d457 | 314 | it('Should succeed with the correct parameters', async function () { |
2d53be02 RK |
315 | await makeDeleteRequest({ |
316 | url: server.url, | |
317 | path: pathComment, | |
318 | token: server.accessToken, | |
319 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
320 | }) | |
4cb6d457 C |
321 | }) |
322 | }) | |
323 | ||
47564bbe C |
324 | describe('When a video has comments disabled', function () { |
325 | before(async function () { | |
326 | const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false }) | |
d4a8e7a6 C |
327 | video = res.body.video |
328 | pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' | |
47564bbe C |
329 | }) |
330 | ||
331 | it('Should return an empty thread list', async function () { | |
332 | const res = await makeGetRequest({ | |
333 | url: server.url, | |
334 | path: pathThread, | |
2d53be02 | 335 | statusCodeExpected: HttpStatusCode.OK_200 |
47564bbe C |
336 | }) |
337 | expect(res.body.total).to.equal(0) | |
338 | expect(res.body.data).to.have.lengthOf(0) | |
339 | }) | |
340 | ||
341 | it('Should return an thread comments list') | |
342 | ||
343 | it('Should return conflict on thread add', async function () { | |
344 | const fields = { | |
345 | text: 'super comment' | |
346 | } | |
2d53be02 RK |
347 | await makePostBodyRequest({ |
348 | url: server.url, | |
349 | path: pathThread, | |
350 | token: server.accessToken, | |
351 | fields, | |
352 | statusCodeExpected: HttpStatusCode.CONFLICT_409 | |
353 | }) | |
47564bbe C |
354 | }) |
355 | ||
356 | it('Should return conflict on comment thread add') | |
357 | }) | |
358 | ||
f1273314 C |
359 | describe('When listing admin comments threads', function () { |
360 | const path = '/api/v1/videos/comments' | |
361 | ||
362 | it('Should fail with a bad start pagination', async function () { | |
363 | await checkBadStartPagination(server.url, path, server.accessToken) | |
364 | }) | |
365 | ||
366 | it('Should fail with a bad count pagination', async function () { | |
367 | await checkBadCountPagination(server.url, path, server.accessToken) | |
368 | }) | |
369 | ||
370 | it('Should fail with an incorrect sort', async function () { | |
371 | await checkBadSortPagination(server.url, path, server.accessToken) | |
372 | }) | |
373 | ||
374 | it('Should fail with a non authenticated user', async function () { | |
375 | await makeGetRequest({ | |
376 | url: server.url, | |
377 | path, | |
2d53be02 | 378 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 |
f1273314 C |
379 | }) |
380 | }) | |
381 | ||
382 | it('Should fail with a non admin user', async function () { | |
383 | await makeGetRequest({ | |
384 | url: server.url, | |
385 | path, | |
386 | token: userAccessToken, | |
2d53be02 | 387 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
f1273314 C |
388 | }) |
389 | }) | |
390 | ||
391 | it('Should succeed with the correct params', async function () { | |
392 | await makeGetRequest({ | |
393 | url: server.url, | |
394 | path, | |
395 | token: server.accessToken, | |
396 | query: { | |
397 | isLocal: false, | |
398 | search: 'toto', | |
399 | searchAccount: 'toto', | |
400 | searchVideo: 'toto' | |
401 | }, | |
2d53be02 | 402 | statusCodeExpected: HttpStatusCode.OK_200 |
f1273314 C |
403 | }) |
404 | }) | |
405 | }) | |
406 | ||
7c3b7976 C |
407 | after(async function () { |
408 | await cleanupTests([ server ]) | |
e2e22e40 C |
409 | }) |
410 | }) |