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
34 // ---------------------------------------------------------------
36 before(async function () {
39 server = await flushAndRunServer(1)
41 await setAccessTokensToServers([ server ])
44 const res = await uploadVideo(server.url, server.accessToken, {})
45 videoUUID = res.body.video.uuid
46 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
50 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, 'coucou')
51 commentId = res.body.comment.id
52 pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId
58 password: 'my super password'
60 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
61 userAccessToken = await userLogin(server, user)
65 describe('When listing video comment threads', function () {
66 it('Should fail with a bad start pagination', async function () {
67 await checkBadStartPagination(server.url, pathThread, server.accessToken)
70 it('Should fail with a bad count pagination', async function () {
71 await checkBadCountPagination(server.url, pathThread, server.accessToken)
74 it('Should fail with an incorrect sort', async function () {
75 await checkBadSortPagination(server.url, pathThread, server.accessToken)
78 it('Should fail with an incorrect video', async function () {
79 await makeGetRequest({
81 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
82 statusCodeExpected: 404
87 describe('When listing comments of a thread', function () {
88 it('Should fail with an incorrect video', async function () {
89 await makeGetRequest({
91 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
92 statusCodeExpected: 404
96 it('Should fail with an incorrect thread id', async function () {
97 await makeGetRequest({
99 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
100 statusCodeExpected: 404
104 it('Should success with the correct params', async function () {
105 await makeGetRequest({
107 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
108 statusCodeExpected: 200
113 describe('When adding a video thread', function () {
115 it('Should fail with a non authenticated user', async function () {
119 await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 })
122 it('Should fail with nothing', async function () {
124 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
127 it('Should fail with a short comment', async function () {
131 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
134 it('Should fail with a long comment', async function () {
136 text: 'h'.repeat(3001)
138 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
141 it('Should fail with an incorrect video', async function () {
142 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads'
144 text: 'super comment'
146 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
149 it('Should succeed with the correct parameters', async function () {
151 text: 'super comment'
153 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 })
157 describe('When adding a comment to a thread', function () {
158 it('Should fail with a non authenticated user', async function () {
162 await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 })
165 it('Should fail with nothing', async function () {
167 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
170 it('Should fail with a short comment', async function () {
174 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
177 it('Should fail with a long comment', async function () {
179 text: 'h'.repeat(3001)
181 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
184 it('Should fail with an incorrect video', async function () {
185 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
187 text: 'super comment'
189 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
192 it('Should fail with an incorrect comment', async function () {
193 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
195 text: 'super comment'
197 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
200 it('Should succeed with the correct parameters', async function () {
202 text: 'super comment'
204 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 })
208 describe('When removing video comments', function () {
209 it('Should fail with a non authenticated user', async function () {
210 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: 401 })
213 it('Should fail with another user', async function () {
214 await makeDeleteRequest({ url: server.url, path: pathComment, token: userAccessToken, statusCodeExpected: 403 })
217 it('Should fail with an incorrect video', async function () {
218 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
219 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
222 it('Should fail with an incorrect comment', async function () {
223 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
224 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
227 it('Should succeed with the correct parameters', async function () {
228 await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 })
232 describe('When a video has comments disabled', function () {
233 before(async function () {
234 const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false })
235 videoUUID = res.body.video.uuid
236 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
239 it('Should return an empty thread list', async function () {
240 const res = await makeGetRequest({
243 statusCodeExpected: 200
245 expect(res.body.total).to.equal(0)
246 expect(res.body.data).to.have.lengthOf(0)
249 it('Should return an thread comments list')
251 it('Should return conflict on thread add', async function () {
253 text: 'super comment'
255 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 409 })
258 it('Should return conflict on comment thread add')
261 after(async function () {
262 await cleanupTests([ server ])