1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
7 flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
9 } from '../../../../shared/utils'
11 checkBadCountPagination,
12 checkBadSortPagination,
13 checkBadStartPagination
14 } from '../../../../shared/utils/requests/check-api-params'
15 import { addVideoCommentThread } from '../../../../shared/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 () {
34 server = await runServer(1)
36 await setAccessTokensToServers([ server ])
39 const res = await uploadVideo(server.url, server.accessToken, {})
40 videoUUID = res.body.video.uuid
41 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
45 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, 'coucou')
46 commentId = res.body.comment.id
47 pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId
53 password: 'my super password'
55 await createUser(server.url, server.accessToken, user.username, user.password)
56 userAccessToken = await userLogin(server, user)
60 describe('When listing video comment threads', function () {
61 it('Should fail with a bad start pagination', async function () {
62 await checkBadStartPagination(server.url, pathThread, server.accessToken)
65 it('Should fail with a bad count pagination', async function () {
66 await checkBadCountPagination(server.url, pathThread, server.accessToken)
69 it('Should fail with an incorrect sort', async function () {
70 await checkBadSortPagination(server.url, pathThread, server.accessToken)
73 it('Should fail with an incorrect video', async function () {
74 await makeGetRequest({
76 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
77 statusCodeExpected: 404
82 describe('When listing comments of a thread', function () {
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/' + commentId,
87 statusCodeExpected: 404
91 it('Should fail with an incorrect thread id', async function () {
92 await makeGetRequest({
94 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
95 statusCodeExpected: 404
99 it('Should success with the correct params', async function () {
100 await makeGetRequest({
102 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
103 statusCodeExpected: 200
108 describe('When adding a video thread', function () {
110 it('Should fail with a non authenticated user', async function () {
114 await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 })
117 it('Should fail with nothing', async function () {
119 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
122 it('Should fail with a short comment', async function () {
126 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
129 it('Should fail with a long comment', async function () {
131 text: 'h'.repeat(3001)
133 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
136 it('Should fail with an incorrect video', async function () {
137 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads'
139 text: 'super comment'
141 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
144 it('Should succeed with the correct parameters', async function () {
146 text: 'super comment'
148 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 })
152 describe('When adding a comment to a thread', function () {
153 it('Should fail with a non authenticated user', async function () {
157 await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 })
160 it('Should fail with nothing', async function () {
162 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
165 it('Should fail with a short comment', async function () {
169 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
172 it('Should fail with a long comment', async function () {
174 text: 'h'.repeat(3001)
176 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
179 it('Should fail with an incorrect video', async function () {
180 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
182 text: 'super comment'
184 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
187 it('Should fail with an incorrect comment', async function () {
188 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
190 text: 'super comment'
192 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
195 it('Should succeed with the correct parameters', async function () {
197 text: 'super comment'
199 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 })
203 describe('When removing video comments', function () {
204 it('Should fail with a non authenticated user', async function () {
205 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: 401 })
208 it('Should fail with another user', async function () {
209 await makeDeleteRequest({ url: server.url, path: pathComment, token: userAccessToken, statusCodeExpected: 403 })
212 it('Should fail with an incorrect video', async function () {
213 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
214 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
217 it('Should fail with an incorrect comment', async function () {
218 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
219 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
222 it('Should succeed with the correct parameters', async function () {
223 await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 })
227 describe('When a video has comments disabled', function () {
228 before(async function () {
229 const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false })
230 videoUUID = res.body.video.uuid
231 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
234 it('Should return an empty thread list', async function () {
235 const res = await makeGetRequest({
238 statusCodeExpected: 200
240 expect(res.body.total).to.equal(0)
241 expect(res.body.data).to.have.lengthOf(0)
244 it('Should return an thread comments list')
246 it('Should return conflict on thread add', async function () {
248 text: 'super comment'
250 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 409 })
253 it('Should return conflict on comment thread add')
256 after(async function () {
257 killallServers([ server ])
259 // Keep the logs if the test failed