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