1 /* tslint:disable:no-unused-expression */
5 flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
8 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
9 import { addVideoCommentThread } from '../../utils/videos/video-comments'
11 describe('Test video comments API validator', function () {
12 let pathThread: string
13 let pathComment: string
14 let server: ServerInfo
18 // ---------------------------------------------------------------
20 before(async function () {
25 server = await runServer(1)
27 await setAccessTokensToServers([ server ])
30 const res = await uploadVideo(server.url, server.accessToken, {})
31 videoUUID = res.body.video.uuid
32 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
36 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, 'coucou')
37 commentId = res.body.comment.id
38 pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId
42 describe('When listing video comment threads', function () {
43 it('Should fail with a bad start pagination', async function () {
44 await checkBadStartPagination(server.url, pathThread, server.accessToken)
48 it('Should fail with a bad count pagination', async function () {
49 await checkBadCountPagination(server.url, pathThread, server.accessToken)
53 it('Should fail with an incorrect sort', async function () {
54 await checkBadSortPagination(server.url, pathThread, server.accessToken)
58 it('Should fail with an incorrect video', async function () {
59 await makeGetRequest({
61 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
62 statusCodeExpected: 404
67 describe('When listing comments of a thread', function () {
68 it('Should fail with an incorrect video', async function () {
69 await makeGetRequest({
71 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
72 statusCodeExpected: 404
76 it('Should fail with an incorrect thread id', async function () {
77 await makeGetRequest({
79 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
80 statusCodeExpected: 404
84 it('Should success with the correct params', async function () {
85 await makeGetRequest({
87 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
88 statusCodeExpected: 200
93 describe('When adding a video thread', function () {
95 it('Should fail with a non authenticated user', async function () {
99 await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 })
102 it('Should fail with nothing', async function () {
104 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
107 it('Should fail with a short comment', async function () {
109 text: 'h'.repeat(3001)
111 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
114 it('Should fail with a long comment', async function () {
116 text: 'h'.repeat(3001)
118 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
121 it('Should fail with an incorrect video', async function () {
122 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads'
124 text: 'super comment'
126 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
129 it('Should succeed with the correct parameters', async function () {
131 text: 'super comment'
133 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 })
137 describe('When adding a comment to a thread', function () {
138 it('Should fail with a non authenticated user', async function () {
142 await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 })
145 it('Should fail with nothing', async function () {
147 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
150 it('Should fail with a short comment', async function () {
152 text: 'h'.repeat(3001)
154 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
157 it('Should fail with a long comment', async function () {
159 text: 'h'.repeat(3001)
161 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
164 it('Should fail with an incorrect video', async function () {
165 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
167 text: 'super comment'
169 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
172 it('Should fail with an incorrect comment', async function () {
173 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
175 text: 'super comment'
177 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
180 it('Should succeed with the correct parameters', async function () {
182 text: 'super comment'
184 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 })
188 after(async function () {
189 killallServers([ server ])
191 // Keep the logs if the test failed