]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-comments.ts
Add ability to run transcoding jobs
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-comments.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
e2e22e40
C
2
3import 'mocha'
d4a8e7a6 4import * as chai from 'chai'
11ba2ab3 5import {
12edc149
C
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
7c3b7976 9 cleanupTests,
254d3579 10 createSingleServer,
42e1ec25
C
11 makeDeleteRequest,
12 makeGetRequest,
13 makePostBodyRequest,
254d3579 14 PeerTubeServer,
d23dd9fb 15 setAccessTokensToServers
12edc149 16} from '@shared/extra-utils'
4c7e60bc 17import { HttpStatusCode, VideoCreateResult } from '@shared/models'
e2e22e40 18
47564bbe
C
19const expect = chai.expect
20
e2e22e40
C
21describe('Test video comments API validator', function () {
22 let pathThread: string
23 let pathComment: string
254d3579 24 let server: PeerTubeServer
d4a8e7a6 25 let video: VideoCreateResult
4cb6d457 26 let userAccessToken: string
fde37dc9 27 let userAccessToken2: string
e2e22e40
C
28 let commentId: number
29
30 // ---------------------------------------------------------------
31
32 before(async function () {
e212f887 33 this.timeout(30000)
e2e22e40 34
254d3579 35 server = await createSingleServer(1)
e2e22e40
C
36
37 await setAccessTokensToServers([ server ])
38
e2e22e40 39 {
08642a76 40 video = await server.videos.upload({ attributes: {} })
d4a8e7a6 41 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
e2e22e40
C
42 }
43
44 {
89d241a7 45 const created = await server.comments.createThread({ videoId: video.uuid, text: 'coucou' })
12edc149 46 commentId = created.id
d4a8e7a6 47 pathComment = '/api/v1/videos/' + video.uuid + '/comments/' + commentId
e2e22e40 48 }
4cb6d457
C
49
50 {
fde37dc9 51 const user = { username: 'user1', password: 'my super password' }
89d241a7
C
52 await server.users.create({ username: user.username, password: user.password })
53 userAccessToken = await server.login.getAccessToken(user)
4cb6d457 54 }
fde37dc9
C
55
56 {
57 const user = { username: 'user2', password: 'my super password' }
89d241a7
C
58 await server.users.create({ username: user.username, password: user.password })
59 userAccessToken2 = await server.login.getAccessToken(user)
fde37dc9 60 }
e2e22e40
C
61 })
62
63 describe('When listing video comment threads', function () {
64 it('Should fail with a bad start pagination', async function () {
11ba2ab3 65 await checkBadStartPagination(server.url, pathThread, server.accessToken)
e2e22e40
C
66 })
67
68 it('Should fail with a bad count pagination', async function () {
11ba2ab3 69 await checkBadCountPagination(server.url, pathThread, server.accessToken)
e2e22e40
C
70 })
71
72 it('Should fail with an incorrect sort', async function () {
11ba2ab3 73 await checkBadSortPagination(server.url, pathThread, server.accessToken)
e2e22e40
C
74 })
75
76 it('Should fail with an incorrect video', async function () {
11ba2ab3
C
77 await makeGetRequest({
78 url: server.url,
79 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
c0e8b12e 80 expectedStatus: HttpStatusCode.NOT_FOUND_404
11ba2ab3 81 })
e2e22e40
C
82 })
83 })
84
85 describe('When listing comments of a thread', function () {
86 it('Should fail with an incorrect video', async function () {
11ba2ab3
C
87 await makeGetRequest({
88 url: server.url,
89 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
c0e8b12e 90 expectedStatus: HttpStatusCode.NOT_FOUND_404
11ba2ab3 91 })
e2e22e40
C
92 })
93
94 it('Should fail with an incorrect thread id', async function () {
11ba2ab3
C
95 await makeGetRequest({
96 url: server.url,
d4a8e7a6 97 path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/156',
c0e8b12e 98 expectedStatus: HttpStatusCode.NOT_FOUND_404
11ba2ab3 99 })
e2e22e40
C
100 })
101
102 it('Should success with the correct params', async function () {
11ba2ab3
C
103 await makeGetRequest({
104 url: server.url,
d4a8e7a6 105 path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/' + commentId,
c0e8b12e 106 expectedStatus: HttpStatusCode.OK_200
11ba2ab3 107 })
e2e22e40
C
108 })
109 })
110
111 describe('When adding a video thread', function () {
112
113 it('Should fail with a non authenticated user', async function () {
114 const fields = {
115 text: 'text'
116 }
2d53be02
RK
117 await makePostBodyRequest({
118 url: server.url,
119 path: pathThread,
120 token: 'none',
121 fields,
c0e8b12e 122 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
2d53be02 123 })
e2e22e40
C
124 })
125
126 it('Should fail with nothing', async function () {
127 const fields = {}
128 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
129 })
130
131 it('Should fail with a short comment', async function () {
132 const fields = {
53eb90c0 133 text: ''
e2e22e40
C
134 }
135 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
136 })
137
138 it('Should fail with a long comment', async function () {
139 const fields = {
298b3fd3 140 text: 'h'.repeat(10001)
e2e22e40
C
141 }
142 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
143 })
144
145 it('Should fail with an incorrect video', async function () {
146 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads'
147 const fields = {
148 text: 'super comment'
149 }
2d53be02
RK
150 await makePostBodyRequest({
151 url: server.url,
152 path,
153 token: server.accessToken,
154 fields,
c0e8b12e 155 expectedStatus: HttpStatusCode.NOT_FOUND_404
2d53be02 156 })
e2e22e40
C
157 })
158
159 it('Should succeed with the correct parameters', async function () {
160 const fields = {
161 text: 'super comment'
162 }
2d53be02
RK
163 await makePostBodyRequest({
164 url: server.url,
165 path: pathThread,
166 token: server.accessToken,
167 fields,
c0e8b12e 168 expectedStatus: HttpStatusCode.OK_200
2d53be02 169 })
e2e22e40
C
170 })
171 })
172
173 describe('When adding a comment to a thread', function () {
174 it('Should fail with a non authenticated user', async function () {
175 const fields = {
176 text: 'text'
177 }
2d53be02
RK
178 await makePostBodyRequest({
179 url: server.url,
180 path: pathComment,
181 token: 'none',
182 fields,
c0e8b12e 183 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
2d53be02 184 })
e2e22e40
C
185 })
186
187 it('Should fail with nothing', async function () {
188 const fields = {}
189 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
190 })
191
192 it('Should fail with a short comment', async function () {
193 const fields = {
53eb90c0 194 text: ''
e2e22e40
C
195 }
196 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
197 })
198
199 it('Should fail with a long comment', async function () {
200 const fields = {
298b3fd3 201 text: 'h'.repeat(10001)
e2e22e40
C
202 }
203 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
204 })
205
206 it('Should fail with an incorrect video', async function () {
207 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
208 const fields = {
209 text: 'super comment'
210 }
2d53be02
RK
211 await makePostBodyRequest({
212 url: server.url,
213 path,
214 token: server.accessToken,
215 fields,
c0e8b12e 216 expectedStatus: HttpStatusCode.NOT_FOUND_404
2d53be02 217 })
e2e22e40
C
218 })
219
220 it('Should fail with an incorrect comment', async function () {
d4a8e7a6 221 const path = '/api/v1/videos/' + video.uuid + '/comments/124'
e2e22e40
C
222 const fields = {
223 text: 'super comment'
224 }
2d53be02
RK
225 await makePostBodyRequest({
226 url: server.url,
227 path,
228 token: server.accessToken,
229 fields,
c0e8b12e 230 expectedStatus: HttpStatusCode.NOT_FOUND_404
2d53be02 231 })
e2e22e40
C
232 })
233
234 it('Should succeed with the correct parameters', async function () {
235 const fields = {
236 text: 'super comment'
237 }
2d53be02
RK
238 await makePostBodyRequest({
239 url: server.url,
240 path: pathComment,
241 token: server.accessToken,
242 fields,
c0e8b12e 243 expectedStatus: HttpStatusCode.OK_200
2d53be02 244 })
e2e22e40
C
245 })
246 })
247
4cb6d457
C
248 describe('When removing video comments', function () {
249 it('Should fail with a non authenticated user', async function () {
c0e8b12e 250 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
4cb6d457
C
251 })
252
253 it('Should fail with another user', async function () {
2d53be02
RK
254 await makeDeleteRequest({
255 url: server.url,
256 path: pathComment,
257 token: userAccessToken,
c0e8b12e 258 expectedStatus: HttpStatusCode.FORBIDDEN_403
2d53be02 259 })
4cb6d457
C
260 })
261
262 it('Should fail with an incorrect video', async function () {
263 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
c0e8b12e 264 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
4cb6d457
C
265 })
266
267 it('Should fail with an incorrect comment', async function () {
d4a8e7a6 268 const path = '/api/v1/videos/' + video.uuid + '/comments/124'
c0e8b12e 269 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
4cb6d457
C
270 })
271
fde37dc9
C
272 it('Should succeed with the same user', async function () {
273 let commentToDelete: number
274
275 {
89d241a7 276 const created = await server.comments.createThread({ videoId: video.uuid, token: userAccessToken, text: 'hello' })
12edc149 277 commentToDelete = created.id
fde37dc9
C
278 }
279
d4a8e7a6 280 const path = '/api/v1/videos/' + video.uuid + '/comments/' + commentToDelete
fde37dc9 281
c0e8b12e
C
282 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
283 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, expectedStatus: HttpStatusCode.NO_CONTENT_204 })
fde37dc9
C
284 })
285
286 it('Should succeed with the owner of the video', async function () {
287 let commentToDelete: number
288 let anotherVideoUUID: string
289
290 {
89d241a7 291 const { uuid } = await server.videos.upload({ token: userAccessToken, attributes: { name: 'video' } })
d23dd9fb 292 anotherVideoUUID = uuid
fde37dc9
C
293 }
294
295 {
89d241a7 296 const created = await server.comments.createThread({ videoId: anotherVideoUUID, text: 'hello' })
12edc149 297 commentToDelete = created.id
fde37dc9
C
298 }
299
300 const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete
301
c0e8b12e
C
302 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
303 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, expectedStatus: HttpStatusCode.NO_CONTENT_204 })
fde37dc9
C
304 })
305
4cb6d457 306 it('Should succeed with the correct parameters', async function () {
2d53be02
RK
307 await makeDeleteRequest({
308 url: server.url,
309 path: pathComment,
310 token: server.accessToken,
c0e8b12e 311 expectedStatus: HttpStatusCode.NO_CONTENT_204
2d53be02 312 })
4cb6d457
C
313 })
314 })
315
47564bbe
C
316 describe('When a video has comments disabled', function () {
317 before(async function () {
89d241a7 318 video = await server.videos.upload({ attributes: { commentsEnabled: false } })
d4a8e7a6 319 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
47564bbe
C
320 })
321
322 it('Should return an empty thread list', async function () {
323 const res = await makeGetRequest({
324 url: server.url,
325 path: pathThread,
c0e8b12e 326 expectedStatus: HttpStatusCode.OK_200
47564bbe
C
327 })
328 expect(res.body.total).to.equal(0)
329 expect(res.body.data).to.have.lengthOf(0)
330 })
331
332 it('Should return an thread comments list')
333
334 it('Should return conflict on thread add', async function () {
335 const fields = {
336 text: 'super comment'
337 }
2d53be02
RK
338 await makePostBodyRequest({
339 url: server.url,
340 path: pathThread,
341 token: server.accessToken,
342 fields,
c0e8b12e 343 expectedStatus: HttpStatusCode.CONFLICT_409
2d53be02 344 })
47564bbe
C
345 })
346
347 it('Should return conflict on comment thread add')
348 })
349
f1273314
C
350 describe('When listing admin comments threads', function () {
351 const path = '/api/v1/videos/comments'
352
353 it('Should fail with a bad start pagination', async function () {
354 await checkBadStartPagination(server.url, path, server.accessToken)
355 })
356
357 it('Should fail with a bad count pagination', async function () {
358 await checkBadCountPagination(server.url, path, server.accessToken)
359 })
360
361 it('Should fail with an incorrect sort', async function () {
362 await checkBadSortPagination(server.url, path, server.accessToken)
363 })
364
365 it('Should fail with a non authenticated user', async function () {
366 await makeGetRequest({
367 url: server.url,
368 path,
c0e8b12e 369 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
f1273314
C
370 })
371 })
372
373 it('Should fail with a non admin user', async function () {
374 await makeGetRequest({
375 url: server.url,
376 path,
377 token: userAccessToken,
c0e8b12e 378 expectedStatus: HttpStatusCode.FORBIDDEN_403
f1273314
C
379 })
380 })
381
382 it('Should succeed with the correct params', async function () {
383 await makeGetRequest({
384 url: server.url,
385 path,
386 token: server.accessToken,
387 query: {
388 isLocal: false,
389 search: 'toto',
390 searchAccount: 'toto',
391 searchVideo: 'toto'
392 },
c0e8b12e 393 expectedStatus: HttpStatusCode.OK_200
f1273314
C
394 })
395 })
396 })
397
7c3b7976
C
398 after(async function () {
399 await cleanupTests([ server ])
e2e22e40
C
400 })
401})