1 /* tslint:disable:no-unused-expression */
4 import * as request from 'supertest'
6 createUser, flushTests, getUserAccessToken, killallServers, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
9 import { addVideoCommentThread } from '../../utils/video-comments'
11 describe('Test video comments API validator', function () {
12 let pathThread: string
13 let pathComment: string
14 let server: ServerInfo
15 let accessTokenUser: string
19 // ---------------------------------------------------------------
21 before(async function () {
26 server = await runServer(1)
28 await setAccessTokensToServers([ server ])
33 password: 'fake_password'
35 await createUser(server.url, server.accessToken, user.username, user.password)
37 accessTokenUser = await getUserAccessToken(server, user)
41 const res = await uploadVideo(server.url, server.accessToken, {})
42 videoUUID = res.body.video.uuid
43 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
47 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, 'coucou')
48 commentId = res.body.comment.id
49 pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId
53 describe('When listing video comment threads', function () {
54 it('Should fail with a bad start pagination', async function () {
55 await request(server.url)
57 .query({ start: 'hello' })
58 .set('Accept', 'application/json')
62 it('Should fail with a bad count pagination', async function () {
63 await request(server.url)
65 .query({ count: 'hello' })
66 .set('Accept', 'application/json')
70 it('Should fail with an incorrect sort', async function () {
71 await request(server.url)
73 .query({ sort: 'hello' })
74 .set('Accept', 'application/json')
78 it('Should fail with an incorrect video', async function () {
79 await request(server.url)
80 .get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads')
81 .set('Accept', 'application/json')
86 describe('When listing comments of a thread', function () {
87 it('Should fail with an incorrect video', async function () {
88 await request(server.url)
89 .get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId)
90 .set('Accept', 'application/json')
94 it('Should fail with an incorrect thread id', async function () {
95 await request(server.url)
96 .get('/api/v1/videos/' + videoUUID + '/comment-threads/156')
97 .set('Accept', 'application/json')
101 it('Should success with the correct params', async function () {
102 await request(server.url)
103 .get('/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId)
104 .set('Accept', 'application/json')
109 describe('When adding a video thread', function () {
111 it('Should fail with a non authenticated user', async function () {
115 await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 })
118 it('Should fail with nothing', async function () {
120 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
123 it('Should fail with a short comment', async function () {
125 text: 'h'.repeat(3001)
127 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
130 it('Should fail with a long comment', async function () {
132 text: 'h'.repeat(3001)
134 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
137 it('Should fail with an incorrect video', async function () {
138 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads'
140 text: 'super comment'
142 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
145 it('Should succeed with the correct parameters', async function () {
147 text: 'super comment'
149 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 })
153 describe('When adding a comment to a thread', function () {
154 it('Should fail with a non authenticated user', async function () {
158 await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 })
161 it('Should fail with nothing', async function () {
163 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
166 it('Should fail with a short comment', async function () {
168 text: 'h'.repeat(3001)
170 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
173 it('Should fail with a long comment', async function () {
175 text: 'h'.repeat(3001)
177 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
180 it('Should fail with an incorrect video', async function () {
181 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
183 text: 'super comment'
185 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
188 it('Should fail with an incorrect comment', async function () {
189 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
191 text: 'super comment'
193 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
196 it('Should succeed with the correct parameters', async function () {
198 text: 'super comment'
200 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 })
204 after(async function () {
205 killallServers([ server ])
207 // Keep the logs if the test failed