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'
24 const expect = chai.expect
26 describe('Test video comments API validator', function () {
27 let pathThread: string
28 let pathComment: string
29 let server: ServerInfo
31 let userAccessToken: string
32 let userAccessToken2: string
35 // ---------------------------------------------------------------
37 before(async function () {
40 server = await flushAndRunServer(1)
42 await setAccessTokensToServers([ server ])
45 const res = await uploadVideo(server.url, server.accessToken, {})
46 videoUUID = res.body.video.uuid
47 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
51 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, 'coucou')
52 commentId = res.body.comment.id
53 pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId
57 const user = { username: 'user1', password: 'my super password' }
58 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
59 userAccessToken = await userLogin(server, user)
63 const user = { username: 'user2', password: 'my super password' }
64 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
65 userAccessToken2 = await userLogin(server, user)
69 describe('When listing video comment threads', function () {
70 it('Should fail with a bad start pagination', async function () {
71 await checkBadStartPagination(server.url, pathThread, server.accessToken)
74 it('Should fail with a bad count pagination', async function () {
75 await checkBadCountPagination(server.url, pathThread, server.accessToken)
78 it('Should fail with an incorrect sort', async function () {
79 await checkBadSortPagination(server.url, pathThread, server.accessToken)
82 it('Should fail with an incorrect video', async function () {
83 await makeGetRequest({
85 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
86 statusCodeExpected: 404
91 describe('When listing comments of a thread', function () {
92 it('Should fail with an incorrect video', async function () {
93 await makeGetRequest({
95 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
96 statusCodeExpected: 404
100 it('Should fail with an incorrect thread id', async function () {
101 await makeGetRequest({
103 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
104 statusCodeExpected: 404
108 it('Should success with the correct params', async function () {
109 await makeGetRequest({
111 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
112 statusCodeExpected: 200
117 describe('When adding a video thread', function () {
119 it('Should fail with a non authenticated user', async function () {
123 await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 })
126 it('Should fail with nothing', async function () {
128 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
131 it('Should fail with a short comment', async function () {
135 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
138 it('Should fail with a long comment', async function () {
140 text: 'h'.repeat(10001)
142 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
145 it('Should fail with an incorrect video', async function () {
146 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads'
148 text: 'super comment'
150 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
153 it('Should succeed with the correct parameters', async function () {
155 text: 'super comment'
157 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 })
161 describe('When adding a comment to a thread', function () {
162 it('Should fail with a non authenticated user', async function () {
166 await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 })
169 it('Should fail with nothing', async function () {
171 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
174 it('Should fail with a short comment', async function () {
178 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
181 it('Should fail with a long comment', async function () {
183 text: 'h'.repeat(10001)
185 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
188 it('Should fail with an incorrect video', async function () {
189 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
191 text: 'super comment'
193 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
196 it('Should fail with an incorrect comment', async function () {
197 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
199 text: 'super comment'
201 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
204 it('Should succeed with the correct parameters', async function () {
206 text: 'super comment'
208 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 })
212 describe('When removing video comments', function () {
213 it('Should fail with a non authenticated user', async function () {
214 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: 401 })
217 it('Should fail with another user', async function () {
218 await makeDeleteRequest({ url: server.url, path: pathComment, token: userAccessToken, statusCodeExpected: 403 })
221 it('Should fail with an incorrect video', async function () {
222 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
223 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
226 it('Should fail with an incorrect comment', async function () {
227 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
228 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
231 it('Should succeed with the same user', async function () {
232 let commentToDelete: number
235 const res = await addVideoCommentThread(server.url, userAccessToken, videoUUID, 'hello')
236 commentToDelete = res.body.comment.id
239 const path = '/api/v1/videos/' + videoUUID + '/comments/' + commentToDelete
241 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: 403 })
242 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 204 })
245 it('Should succeed with the owner of the video', async function () {
246 let commentToDelete: number
247 let anotherVideoUUID: string
250 const res = await uploadVideo(server.url, userAccessToken, { name: 'video' })
251 anotherVideoUUID = res.body.video.uuid
255 const res = await addVideoCommentThread(server.url, server.accessToken, anotherVideoUUID, 'hello')
256 commentToDelete = res.body.comment.id
259 const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete
261 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: 403 })
262 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 204 })
265 it('Should succeed with the correct parameters', async function () {
266 await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 })
270 describe('When a video has comments disabled', function () {
271 before(async function () {
272 const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false })
273 videoUUID = res.body.video.uuid
274 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
277 it('Should return an empty thread list', async function () {
278 const res = await makeGetRequest({
281 statusCodeExpected: 200
283 expect(res.body.total).to.equal(0)
284 expect(res.body.data).to.have.lengthOf(0)
287 it('Should return an thread comments list')
289 it('Should return conflict on thread add', async function () {
291 text: 'super comment'
293 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 409 })
296 it('Should return conflict on comment thread add')
299 after(async function () {
300 await cleanupTests([ server ])