1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
7 flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
10 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
11 import { addVideoCommentThread } from '../../utils/videos/video-comments'
13 const expect = chai.expect
15 describe('Test video comments API validator', function () {
16 let pathThread: string
17 let pathComment: string
18 let server: ServerInfo
20 let userAccessToken: string
23 // ---------------------------------------------------------------
25 before(async function () {
30 server = await runServer(1)
32 await setAccessTokensToServers([ server ])
35 const res = await uploadVideo(server.url, server.accessToken, {})
36 videoUUID = res.body.video.uuid
37 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
41 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, 'coucou')
42 commentId = res.body.comment.id
43 pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId
49 password: 'my super password'
51 await createUser(server.url, server.accessToken, user.username, user.password)
52 userAccessToken = await userLogin(server, user)
56 describe('When listing video comment threads', function () {
57 it('Should fail with a bad start pagination', async function () {
58 await checkBadStartPagination(server.url, pathThread, server.accessToken)
61 it('Should fail with a bad count pagination', async function () {
62 await checkBadCountPagination(server.url, pathThread, server.accessToken)
65 it('Should fail with an incorrect sort', async function () {
66 await checkBadSortPagination(server.url, pathThread, server.accessToken)
69 it('Should fail with an incorrect video', async function () {
70 await makeGetRequest({
72 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
73 statusCodeExpected: 404
78 describe('When listing comments of a thread', function () {
79 it('Should fail with an incorrect video', async function () {
80 await makeGetRequest({
82 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
83 statusCodeExpected: 404
87 it('Should fail with an incorrect thread id', async function () {
88 await makeGetRequest({
90 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
91 statusCodeExpected: 404
95 it('Should success with the correct params', async function () {
96 await makeGetRequest({
98 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
99 statusCodeExpected: 200
104 describe('When adding a video thread', function () {
106 it('Should fail with a non authenticated user', async function () {
110 await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 })
113 it('Should fail with nothing', async function () {
115 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
118 it('Should fail with a short comment', async function () {
122 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
125 it('Should fail with a long comment', async function () {
127 text: 'h'.repeat(3001)
129 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
132 it('Should fail with an incorrect video', async function () {
133 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads'
135 text: 'super comment'
137 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
140 it('Should succeed with the correct parameters', async function () {
142 text: 'super comment'
144 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 })
148 describe('When adding a comment to a thread', function () {
149 it('Should fail with a non authenticated user', async function () {
153 await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 })
156 it('Should fail with nothing', async function () {
158 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
161 it('Should fail with a short comment', async function () {
165 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
168 it('Should fail with a long comment', async function () {
170 text: 'h'.repeat(3001)
172 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
175 it('Should fail with an incorrect video', async function () {
176 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
178 text: 'super comment'
180 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
183 it('Should fail with an incorrect comment', async function () {
184 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
186 text: 'super comment'
188 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
191 it('Should succeed with the correct parameters', async function () {
193 text: 'super comment'
195 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 })
199 describe('When removing video comments', function () {
200 it('Should fail with a non authenticated user', async function () {
201 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: 401 })
204 it('Should fail with another user', async function () {
205 await makeDeleteRequest({ url: server.url, path: pathComment, token: userAccessToken, statusCodeExpected: 403 })
208 it('Should fail with an incorrect video', async function () {
209 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
210 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
213 it('Should fail with an incorrect comment', async function () {
214 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
215 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
218 it('Should succeed with the correct parameters', async function () {
219 await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 })
223 describe('When a video has comments disabled', function () {
224 before(async function () {
225 const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false })
226 videoUUID = res.body.video.uuid
227 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
230 it('Should return an empty thread list', async function () {
231 const res = await makeGetRequest({
234 statusCodeExpected: 200
236 expect(res.body.total).to.equal(0)
237 expect(res.body.data).to.have.lengthOf(0)
240 it('Should return an thread comments list')
242 it('Should return conflict on thread add', async function () {
244 text: 'super comment'
246 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 409 })
249 it('Should return conflict on comment thread add')
252 after(async function () {
253 killallServers([ server ])
255 // Keep the logs if the test failed