]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/utils/videos/video-comments.ts
Add ability for users to block an account/instance on server side
[github/Chocobozzz/PeerTube.git] / server / tests / utils / videos / video-comments.ts
index 8781470496d6d091267c900cd5ca952c0dc85673..7d4cae3647ec29f7c8c86ec8c7d58f3895cf3e70 100644 (file)
@@ -1,6 +1,7 @@
 import * as request from 'supertest'
+import { makeDeleteRequest } from '../'
 
-function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string) {
+function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) {
   const path = '/api/v1/videos/' + videoId + '/comment-threads'
 
   const req = request(url)
@@ -9,20 +10,24 @@ function getVideoCommentThreads (url: string, videoId: number | string, start: n
     .query({ count: count })
 
   if (sort) req.query({ sort })
+  if (token) req.set('Authorization', 'Bearer ' + token)
 
   return req.set('Accept', 'application/json')
     .expect(200)
     .expect('Content-Type', /json/)
 }
 
-function getVideoThreadComments (url: string, videoId: number | string, threadId: number) {
+function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) {
   const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
 
-  return request(url)
+  const req = request(url)
     .get(path)
     .set('Accept', 'application/json')
-    .expect(200)
-    .expect('Content-Type', /json/)
+
+  if (token) req.set('Authorization', 'Bearer ' + token)
+
+  return req.expect(200)
+            .expect('Content-Type', /json/)
 }
 
 function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) {
@@ -54,11 +59,29 @@ function addVideoCommentReply (
     .expect(expectedStatus)
 }
 
+function deleteVideoComment (
+  url: string,
+  token: string,
+  videoId: number | string,
+  commentId: number,
+  statusCodeExpected = 204
+) {
+  const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
+
+  return makeDeleteRequest({
+    url,
+    path,
+    token,
+    statusCodeExpected
+  })
+}
+
 // ---------------------------------------------------------------------------
 
 export {
   getVideoCommentThreads,
   getVideoThreadComments,
   addVideoCommentThread,
-  addVideoCommentReply
+  addVideoCommentReply,
+  deleteVideoComment
 }