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