1 /* tslint:disable:no-unused-expression */
4 import * as request from 'supertest'
5 import { flushTests, killallServers, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils'
6 import { addVideoCommentThread } from '../../utils/video-comments'
8 describe('Test video comments API validator', function () {
10 let pathComment: string
11 let server: ServerInfo
15 // ---------------------------------------------------------------
17 before(async function () {
22 server = await runServer(1)
24 await setAccessTokensToServers([ server ])
27 const res = await uploadVideo(server.url, server.accessToken, {})
28 videoUUID = res.body.video.uuid
29 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
33 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, 'coucou')
34 commentId = res.body.comment.id
35 pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId
39 describe('When listing video comment threads', function () {
40 it('Should fail with a bad start pagination', async function () {
41 await request(server.url)
43 .query({ start: 'hello' })
44 .set('Accept', 'application/json')
48 it('Should fail with a bad count pagination', async function () {
49 await request(server.url)
51 .query({ count: 'hello' })
52 .set('Accept', 'application/json')
56 it('Should fail with an incorrect sort', async function () {
57 await request(server.url)
59 .query({ sort: 'hello' })
60 .set('Accept', 'application/json')
64 it('Should fail with an incorrect video', async function () {
65 await request(server.url)
66 .get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads')
67 .set('Accept', 'application/json')
72 describe('When listing comments of a thread', function () {
73 it('Should fail with an incorrect video', async function () {
74 await request(server.url)
75 .get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId)
76 .set('Accept', 'application/json')
80 it('Should fail with an incorrect thread id', async function () {
81 await request(server.url)
82 .get('/api/v1/videos/' + videoUUID + '/comment-threads/156')
83 .set('Accept', 'application/json')
87 it('Should success with the correct params', async function () {
88 await request(server.url)
89 .get('/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId)
90 .set('Accept', 'application/json')
95 describe('When adding a video thread', function () {
97 it('Should fail with a non authenticated user', async function () {
101 await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 })
104 it('Should fail with nothing', async function () {
106 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
109 it('Should fail with a short comment', async function () {
111 text: 'h'.repeat(3001)
113 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
116 it('Should fail with a long comment', async function () {
118 text: 'h'.repeat(3001)
120 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
123 it('Should fail with an incorrect video', async function () {
124 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads'
126 text: 'super comment'
128 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
131 it('Should succeed with the correct parameters', async function () {
133 text: 'super comment'
135 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 })
139 describe('When adding a comment to a thread', function () {
140 it('Should fail with a non authenticated user', async function () {
144 await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 })
147 it('Should fail with nothing', async function () {
149 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
152 it('Should fail with a short comment', async function () {
154 text: 'h'.repeat(3001)
156 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
159 it('Should fail with a long comment', async function () {
161 text: 'h'.repeat(3001)
163 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
166 it('Should fail with an incorrect video', async function () {
167 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
169 text: 'super comment'
171 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
174 it('Should fail with an incorrect comment', async function () {
175 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
177 text: 'super comment'
179 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
182 it('Should succeed with the correct parameters', async function () {
184 text: 'super comment'
186 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 })
190 after(async function () {
191 killallServers([ server ])
193 // Keep the logs if the test failed