1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
13 setAccessTokensToServers,
16 } from '../../../../shared/extra-utils'
18 checkBadCountPagination,
19 checkBadSortPagination,
20 checkBadStartPagination
21 } from '../../../../shared/extra-utils/requests/check-api-params'
22 import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
23 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
25 const expect = chai.expect
27 describe('Test video comments API validator', function () {
28 let pathThread: string
29 let pathComment: string
30 let server: ServerInfo
32 let userAccessToken: string
33 let userAccessToken2: string
36 // ---------------------------------------------------------------
38 before(async function () {
41 server = await flushAndRunServer(1)
43 await setAccessTokensToServers([ server ])
46 const res = await uploadVideo(server.url, server.accessToken, {})
47 videoUUID = res.body.video.uuid
48 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
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
58 const user = { username: 'user1', password: 'my super password' }
59 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
60 userAccessToken = await userLogin(server, user)
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)
70 describe('When listing video comment threads', function () {
71 it('Should fail with a bad start pagination', async function () {
72 await checkBadStartPagination(server.url, pathThread, server.accessToken)
75 it('Should fail with a bad count pagination', async function () {
76 await checkBadCountPagination(server.url, pathThread, server.accessToken)
79 it('Should fail with an incorrect sort', async function () {
80 await checkBadSortPagination(server.url, pathThread, server.accessToken)
83 it('Should fail with an incorrect video', async function () {
84 await makeGetRequest({
86 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
87 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
92 describe('When listing comments of a thread', function () {
93 it('Should fail with an incorrect video', async function () {
94 await makeGetRequest({
96 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
97 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
101 it('Should fail with an incorrect thread id', async function () {
102 await makeGetRequest({
104 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
105 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
109 it('Should success with the correct params', async function () {
110 await makeGetRequest({
112 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
113 statusCodeExpected: HttpStatusCode.OK_200
118 describe('When adding a video thread', function () {
120 it('Should fail with a non authenticated user', async function () {
124 await makePostBodyRequest({
129 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
133 it('Should fail with nothing', async function () {
135 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
138 it('Should fail with a short comment', async function () {
142 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
145 it('Should fail with a long comment', async function () {
147 text: 'h'.repeat(10001)
149 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
152 it('Should fail with an incorrect video', async function () {
153 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads'
155 text: 'super comment'
157 await makePostBodyRequest({
160 token: server.accessToken,
162 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
166 it('Should succeed with the correct parameters', async function () {
168 text: 'super comment'
170 await makePostBodyRequest({
173 token: server.accessToken,
175 statusCodeExpected: HttpStatusCode.OK_200
180 describe('When adding a comment to a thread', function () {
181 it('Should fail with a non authenticated user', async function () {
185 await makePostBodyRequest({
190 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
194 it('Should fail with nothing', async function () {
196 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
199 it('Should fail with a short comment', async function () {
203 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
206 it('Should fail with a long comment', async function () {
208 text: 'h'.repeat(10001)
210 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
213 it('Should fail with an incorrect video', async function () {
214 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
216 text: 'super comment'
218 await makePostBodyRequest({
221 token: server.accessToken,
223 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
227 it('Should fail with an incorrect comment', async function () {
228 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
230 text: 'super comment'
232 await makePostBodyRequest({
235 token: server.accessToken,
237 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
241 it('Should succeed with the correct parameters', async function () {
243 text: 'super comment'
245 await makePostBodyRequest({
248 token: server.accessToken,
250 statusCodeExpected: HttpStatusCode.OK_200
255 describe('When removing video comments', function () {
256 it('Should fail with a non authenticated user', async function () {
257 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
260 it('Should fail with another user', async function () {
261 await makeDeleteRequest({
264 token: userAccessToken,
265 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
269 it('Should fail with an incorrect video', async function () {
270 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
271 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
274 it('Should fail with an incorrect comment', async function () {
275 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
276 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
279 it('Should succeed with the same user', async function () {
280 let commentToDelete: number
283 const res = await addVideoCommentThread(server.url, userAccessToken, videoUUID, 'hello')
284 commentToDelete = res.body.comment.id
287 const path = '/api/v1/videos/' + videoUUID + '/comments/' + commentToDelete
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 })
293 it('Should succeed with the owner of the video', async function () {
294 let commentToDelete: number
295 let anotherVideoUUID: string
298 const res = await uploadVideo(server.url, userAccessToken, { name: 'video' })
299 anotherVideoUUID = res.body.video.uuid
303 const res = await addVideoCommentThread(server.url, server.accessToken, anotherVideoUUID, 'hello')
304 commentToDelete = res.body.comment.id
307 const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete
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 })
313 it('Should succeed with the correct parameters', async function () {
314 await makeDeleteRequest({
317 token: server.accessToken,
318 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
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'
330 it('Should return an empty thread list', async function () {
331 const res = await makeGetRequest({
334 statusCodeExpected: HttpStatusCode.OK_200
336 expect(res.body.total).to.equal(0)
337 expect(res.body.data).to.have.lengthOf(0)
340 it('Should return an thread comments list')
342 it('Should return conflict on thread add', async function () {
344 text: 'super comment'
346 await makePostBodyRequest({
349 token: server.accessToken,
351 statusCodeExpected: HttpStatusCode.CONFLICT_409
355 it('Should return conflict on comment thread add')
358 describe('When listing admin comments threads', function () {
359 const path = '/api/v1/videos/comments'
361 it('Should fail with a bad start pagination', async function () {
362 await checkBadStartPagination(server.url, path, server.accessToken)
365 it('Should fail with a bad count pagination', async function () {
366 await checkBadCountPagination(server.url, path, server.accessToken)
369 it('Should fail with an incorrect sort', async function () {
370 await checkBadSortPagination(server.url, path, server.accessToken)
373 it('Should fail with a non authenticated user', async function () {
374 await makeGetRequest({
377 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
381 it('Should fail with a non admin user', async function () {
382 await makeGetRequest({
385 token: userAccessToken,
386 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
390 it('Should succeed with the correct params', async function () {
391 await makeGetRequest({
394 token: server.accessToken,
398 searchAccount: 'toto',
401 statusCodeExpected: HttpStatusCode.OK_200
406 after(async function () {
407 await cleanupTests([ server ])