1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
7 flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePostBodyRequest, flushAndRunServer, ServerInfo, setAccessTokensToServers,
9 } from '../../../../shared/extra-utils'
11 checkBadCountPagination,
12 checkBadSortPagination,
13 checkBadStartPagination
14 } from '../../../../shared/extra-utils/requests/check-api-params'
15 import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
17 const expect = chai.expect
19 describe('Test video comments API validator', function () {
20 let pathThread: string
21 let pathComment: string
22 let server: ServerInfo
24 let userAccessToken: string
27 // ---------------------------------------------------------------
29 before(async function () {
32 server = await flushAndRunServer(1)
34 await setAccessTokensToServers([ server ])
37 const res = await uploadVideo(server.url, server.accessToken, {})
38 videoUUID = res.body.video.uuid
39 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
43 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, 'coucou')
44 commentId = res.body.comment.id
45 pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId
51 password: 'my super password'
53 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
54 userAccessToken = await userLogin(server, user)
58 describe('When listing video comment threads', function () {
59 it('Should fail with a bad start pagination', async function () {
60 await checkBadStartPagination(server.url, pathThread, server.accessToken)
63 it('Should fail with a bad count pagination', async function () {
64 await checkBadCountPagination(server.url, pathThread, server.accessToken)
67 it('Should fail with an incorrect sort', async function () {
68 await checkBadSortPagination(server.url, pathThread, server.accessToken)
71 it('Should fail with an incorrect video', async function () {
72 await makeGetRequest({
74 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
75 statusCodeExpected: 404
80 describe('When listing comments of a thread', function () {
81 it('Should fail with an incorrect video', async function () {
82 await makeGetRequest({
84 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
85 statusCodeExpected: 404
89 it('Should fail with an incorrect thread id', async function () {
90 await makeGetRequest({
92 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
93 statusCodeExpected: 404
97 it('Should success with the correct params', async function () {
98 await makeGetRequest({
100 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
101 statusCodeExpected: 200
106 describe('When adding a video thread', function () {
108 it('Should fail with a non authenticated user', async function () {
112 await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 })
115 it('Should fail with nothing', async function () {
117 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
120 it('Should fail with a short comment', async function () {
124 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
127 it('Should fail with a long comment', async function () {
129 text: 'h'.repeat(3001)
131 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
134 it('Should fail with an incorrect video', async function () {
135 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads'
137 text: 'super comment'
139 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
142 it('Should succeed with the correct parameters', async function () {
144 text: 'super comment'
146 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 })
150 describe('When adding a comment to a thread', function () {
151 it('Should fail with a non authenticated user', async function () {
155 await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 })
158 it('Should fail with nothing', async function () {
160 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
163 it('Should fail with a short comment', async function () {
167 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
170 it('Should fail with a long comment', async function () {
172 text: 'h'.repeat(3001)
174 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
177 it('Should fail with an incorrect video', async function () {
178 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
180 text: 'super comment'
182 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
185 it('Should fail with an incorrect comment', async function () {
186 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
188 text: 'super comment'
190 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
193 it('Should succeed with the correct parameters', async function () {
195 text: 'super comment'
197 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 })
201 describe('When removing video comments', function () {
202 it('Should fail with a non authenticated user', async function () {
203 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: 401 })
206 it('Should fail with another user', async function () {
207 await makeDeleteRequest({ url: server.url, path: pathComment, token: userAccessToken, statusCodeExpected: 403 })
210 it('Should fail with an incorrect video', async function () {
211 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
212 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
215 it('Should fail with an incorrect comment', async function () {
216 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
217 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
220 it('Should succeed with the correct parameters', async function () {
221 await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 })
225 describe('When a video has comments disabled', function () {
226 before(async function () {
227 const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false })
228 videoUUID = res.body.video.uuid
229 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
232 it('Should return an empty thread list', async function () {
233 const res = await makeGetRequest({
236 statusCodeExpected: 200
238 expect(res.body.total).to.equal(0)
239 expect(res.body.data).to.have.lengthOf(0)
242 it('Should return an thread comments list')
244 it('Should return conflict on thread add', async function () {
246 text: 'super comment'
248 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 409 })
251 it('Should return conflict on comment thread add')
255 killallServers([ server ])