aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-comments.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/video-comments.ts')
-rw-r--r--server/tests/api/check-params/video-comments.ts107
1 files changed, 49 insertions, 58 deletions
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index a38420851..2d9ee1e0d 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -2,33 +2,26 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoCreateResult } from '@shared/models'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 5import {
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
8 cleanupTests, 9 cleanupTests,
9 createUser, 10 createSingleServer,
10 flushAndRunServer,
11 makeDeleteRequest, 11 makeDeleteRequest,
12 makeGetRequest, 12 makeGetRequest,
13 makePostBodyRequest, 13 makePostBodyRequest,
14 ServerInfo, 14 PeerTubeServer,
15 setAccessTokensToServers, 15 setAccessTokensToServers
16 uploadVideo, 16} from '@shared/extra-utils'
17 userLogin 17import { HttpStatusCode, VideoCreateResult } from '@shared/models'
18} from '../../../../shared/extra-utils'
19import {
20 checkBadCountPagination,
21 checkBadSortPagination,
22 checkBadStartPagination
23} from '../../../../shared/extra-utils/requests/check-api-params'
24import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
25 18
26const expect = chai.expect 19const expect = chai.expect
27 20
28describe('Test video comments API validator', function () { 21describe('Test video comments API validator', function () {
29 let pathThread: string 22 let pathThread: string
30 let pathComment: string 23 let pathComment: string
31 let server: ServerInfo 24 let server: PeerTubeServer
32 let video: VideoCreateResult 25 let video: VideoCreateResult
33 let userAccessToken: string 26 let userAccessToken: string
34 let userAccessToken2: string 27 let userAccessToken2: string
@@ -39,32 +32,31 @@ describe('Test video comments API validator', function () {
39 before(async function () { 32 before(async function () {
40 this.timeout(30000) 33 this.timeout(30000)
41 34
42 server = await flushAndRunServer(1) 35 server = await createSingleServer(1)
43 36
44 await setAccessTokensToServers([ server ]) 37 await setAccessTokensToServers([ server ])
45 38
46 { 39 {
47 const res = await uploadVideo(server.url, server.accessToken, {}) 40 video = await server.videos.upload({ attributes: {} })
48 video = res.body.video
49 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' 41 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
50 } 42 }
51 43
52 { 44 {
53 const res = await addVideoCommentThread(server.url, server.accessToken, video.uuid, 'coucou') 45 const created = await server.comments.createThread({ videoId: video.uuid, text: 'coucou' })
54 commentId = res.body.comment.id 46 commentId = created.id
55 pathComment = '/api/v1/videos/' + video.uuid + '/comments/' + commentId 47 pathComment = '/api/v1/videos/' + video.uuid + '/comments/' + commentId
56 } 48 }
57 49
58 { 50 {
59 const user = { username: 'user1', password: 'my super password' } 51 const user = { username: 'user1', password: 'my super password' }
60 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 52 await server.users.create({ username: user.username, password: user.password })
61 userAccessToken = await userLogin(server, user) 53 userAccessToken = await server.login.getAccessToken(user)
62 } 54 }
63 55
64 { 56 {
65 const user = { username: 'user2', password: 'my super password' } 57 const user = { username: 'user2', password: 'my super password' }
66 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 58 await server.users.create({ username: user.username, password: user.password })
67 userAccessToken2 = await userLogin(server, user) 59 userAccessToken2 = await server.login.getAccessToken(user)
68 } 60 }
69 }) 61 })
70 62
@@ -85,7 +77,7 @@ describe('Test video comments API validator', function () {
85 await makeGetRequest({ 77 await makeGetRequest({
86 url: server.url, 78 url: server.url,
87 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads', 79 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
88 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 80 expectedStatus: HttpStatusCode.NOT_FOUND_404
89 }) 81 })
90 }) 82 })
91 }) 83 })
@@ -95,7 +87,7 @@ describe('Test video comments API validator', function () {
95 await makeGetRequest({ 87 await makeGetRequest({
96 url: server.url, 88 url: server.url,
97 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId, 89 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
98 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 90 expectedStatus: HttpStatusCode.NOT_FOUND_404
99 }) 91 })
100 }) 92 })
101 93
@@ -103,7 +95,7 @@ describe('Test video comments API validator', function () {
103 await makeGetRequest({ 95 await makeGetRequest({
104 url: server.url, 96 url: server.url,
105 path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/156', 97 path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/156',
106 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 98 expectedStatus: HttpStatusCode.NOT_FOUND_404
107 }) 99 })
108 }) 100 })
109 101
@@ -111,7 +103,7 @@ describe('Test video comments API validator', function () {
111 await makeGetRequest({ 103 await makeGetRequest({
112 url: server.url, 104 url: server.url,
113 path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/' + commentId, 105 path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/' + commentId,
114 statusCodeExpected: HttpStatusCode.OK_200 106 expectedStatus: HttpStatusCode.OK_200
115 }) 107 })
116 }) 108 })
117 }) 109 })
@@ -127,7 +119,7 @@ describe('Test video comments API validator', function () {
127 path: pathThread, 119 path: pathThread,
128 token: 'none', 120 token: 'none',
129 fields, 121 fields,
130 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 122 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
131 }) 123 })
132 }) 124 })
133 125
@@ -160,7 +152,7 @@ describe('Test video comments API validator', function () {
160 path, 152 path,
161 token: server.accessToken, 153 token: server.accessToken,
162 fields, 154 fields,
163 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 155 expectedStatus: HttpStatusCode.NOT_FOUND_404
164 }) 156 })
165 }) 157 })
166 158
@@ -173,7 +165,7 @@ describe('Test video comments API validator', function () {
173 path: pathThread, 165 path: pathThread,
174 token: server.accessToken, 166 token: server.accessToken,
175 fields, 167 fields,
176 statusCodeExpected: HttpStatusCode.OK_200 168 expectedStatus: HttpStatusCode.OK_200
177 }) 169 })
178 }) 170 })
179 }) 171 })
@@ -188,7 +180,7 @@ describe('Test video comments API validator', function () {
188 path: pathComment, 180 path: pathComment,
189 token: 'none', 181 token: 'none',
190 fields, 182 fields,
191 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 183 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
192 }) 184 })
193 }) 185 })
194 186
@@ -221,7 +213,7 @@ describe('Test video comments API validator', function () {
221 path, 213 path,
222 token: server.accessToken, 214 token: server.accessToken,
223 fields, 215 fields,
224 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 216 expectedStatus: HttpStatusCode.NOT_FOUND_404
225 }) 217 })
226 }) 218 })
227 219
@@ -235,7 +227,7 @@ describe('Test video comments API validator', function () {
235 path, 227 path,
236 token: server.accessToken, 228 token: server.accessToken,
237 fields, 229 fields,
238 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 230 expectedStatus: HttpStatusCode.NOT_FOUND_404
239 }) 231 })
240 }) 232 })
241 233
@@ -248,14 +240,14 @@ describe('Test video comments API validator', function () {
248 path: pathComment, 240 path: pathComment,
249 token: server.accessToken, 241 token: server.accessToken,
250 fields, 242 fields,
251 statusCodeExpected: HttpStatusCode.OK_200 243 expectedStatus: HttpStatusCode.OK_200
252 }) 244 })
253 }) 245 })
254 }) 246 })
255 247
256 describe('When removing video comments', function () { 248 describe('When removing video comments', function () {
257 it('Should fail with a non authenticated user', async function () { 249 it('Should fail with a non authenticated user', async function () {
258 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 250 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
259 }) 251 })
260 252
261 it('Should fail with another user', async function () { 253 it('Should fail with another user', async function () {
@@ -263,32 +255,32 @@ describe('Test video comments API validator', function () {
263 url: server.url, 255 url: server.url,
264 path: pathComment, 256 path: pathComment,
265 token: userAccessToken, 257 token: userAccessToken,
266 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 258 expectedStatus: HttpStatusCode.FORBIDDEN_403
267 }) 259 })
268 }) 260 })
269 261
270 it('Should fail with an incorrect video', async function () { 262 it('Should fail with an incorrect video', async function () {
271 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId 263 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
272 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 264 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
273 }) 265 })
274 266
275 it('Should fail with an incorrect comment', async function () { 267 it('Should fail with an incorrect comment', async function () {
276 const path = '/api/v1/videos/' + video.uuid + '/comments/124' 268 const path = '/api/v1/videos/' + video.uuid + '/comments/124'
277 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 269 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
278 }) 270 })
279 271
280 it('Should succeed with the same user', async function () { 272 it('Should succeed with the same user', async function () {
281 let commentToDelete: number 273 let commentToDelete: number
282 274
283 { 275 {
284 const res = await addVideoCommentThread(server.url, userAccessToken, video.uuid, 'hello') 276 const created = await server.comments.createThread({ videoId: video.uuid, token: userAccessToken, text: 'hello' })
285 commentToDelete = res.body.comment.id 277 commentToDelete = created.id
286 } 278 }
287 279
288 const path = '/api/v1/videos/' + video.uuid + '/comments/' + commentToDelete 280 const path = '/api/v1/videos/' + video.uuid + '/comments/' + commentToDelete
289 281
290 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 282 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
291 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) 283 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, expectedStatus: HttpStatusCode.NO_CONTENT_204 })
292 }) 284 })
293 285
294 it('Should succeed with the owner of the video', async function () { 286 it('Should succeed with the owner of the video', async function () {
@@ -296,19 +288,19 @@ describe('Test video comments API validator', function () {
296 let anotherVideoUUID: string 288 let anotherVideoUUID: string
297 289
298 { 290 {
299 const res = await uploadVideo(server.url, userAccessToken, { name: 'video' }) 291 const { uuid } = await server.videos.upload({ token: userAccessToken, attributes: { name: 'video' } })
300 anotherVideoUUID = res.body.video.uuid 292 anotherVideoUUID = uuid
301 } 293 }
302 294
303 { 295 {
304 const res = await addVideoCommentThread(server.url, server.accessToken, anotherVideoUUID, 'hello') 296 const created = await server.comments.createThread({ videoId: anotherVideoUUID, text: 'hello' })
305 commentToDelete = res.body.comment.id 297 commentToDelete = created.id
306 } 298 }
307 299
308 const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete 300 const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete
309 301
310 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 302 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
311 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) 303 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, expectedStatus: HttpStatusCode.NO_CONTENT_204 })
312 }) 304 })
313 305
314 it('Should succeed with the correct parameters', async function () { 306 it('Should succeed with the correct parameters', async function () {
@@ -316,15 +308,14 @@ describe('Test video comments API validator', function () {
316 url: server.url, 308 url: server.url,
317 path: pathComment, 309 path: pathComment,
318 token: server.accessToken, 310 token: server.accessToken,
319 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 311 expectedStatus: HttpStatusCode.NO_CONTENT_204
320 }) 312 })
321 }) 313 })
322 }) 314 })
323 315
324 describe('When a video has comments disabled', function () { 316 describe('When a video has comments disabled', function () {
325 before(async function () { 317 before(async function () {
326 const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false }) 318 video = await server.videos.upload({ attributes: { commentsEnabled: false } })
327 video = res.body.video
328 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' 319 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
329 }) 320 })
330 321
@@ -332,7 +323,7 @@ describe('Test video comments API validator', function () {
332 const res = await makeGetRequest({ 323 const res = await makeGetRequest({
333 url: server.url, 324 url: server.url,
334 path: pathThread, 325 path: pathThread,
335 statusCodeExpected: HttpStatusCode.OK_200 326 expectedStatus: HttpStatusCode.OK_200
336 }) 327 })
337 expect(res.body.total).to.equal(0) 328 expect(res.body.total).to.equal(0)
338 expect(res.body.data).to.have.lengthOf(0) 329 expect(res.body.data).to.have.lengthOf(0)
@@ -349,7 +340,7 @@ describe('Test video comments API validator', function () {
349 path: pathThread, 340 path: pathThread,
350 token: server.accessToken, 341 token: server.accessToken,
351 fields, 342 fields,
352 statusCodeExpected: HttpStatusCode.CONFLICT_409 343 expectedStatus: HttpStatusCode.CONFLICT_409
353 }) 344 })
354 }) 345 })
355 346
@@ -375,7 +366,7 @@ describe('Test video comments API validator', function () {
375 await makeGetRequest({ 366 await makeGetRequest({
376 url: server.url, 367 url: server.url,
377 path, 368 path,
378 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 369 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
379 }) 370 })
380 }) 371 })
381 372
@@ -384,7 +375,7 @@ describe('Test video comments API validator', function () {
384 url: server.url, 375 url: server.url,
385 path, 376 path,
386 token: userAccessToken, 377 token: userAccessToken,
387 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 378 expectedStatus: HttpStatusCode.FORBIDDEN_403
388 }) 379 })
389 }) 380 })
390 381
@@ -399,7 +390,7 @@ describe('Test video comments API validator', function () {
399 searchAccount: 'toto', 390 searchAccount: 'toto',
400 searchVideo: 'toto' 391 searchVideo: 'toto'
401 }, 392 },
402 statusCodeExpected: HttpStatusCode.OK_200 393 expectedStatus: HttpStatusCode.OK_200
403 }) 394 })
404 }) 395 })
405 }) 396 })