Move to eslint
[oweals/peertube.git] / shared / extra-utils / videos / video-comments.ts
1 /* eslint-disable @typescript-eslint/no-floating-promises */
2
3 import * as request from 'supertest'
4 import { makeDeleteRequest } from '../requests/requests'
5
6 function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) {
7   const path = '/api/v1/videos/' + videoId + '/comment-threads'
8
9   const req = request(url)
10     .get(path)
11     .query({ start: start })
12     .query({ count: count })
13
14   if (sort) req.query({ sort })
15   if (token) req.set('Authorization', 'Bearer ' + token)
16
17   return req.set('Accept', 'application/json')
18     .expect(200)
19     .expect('Content-Type', /json/)
20 }
21
22 function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) {
23   const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
24
25   const req = request(url)
26     .get(path)
27     .set('Accept', 'application/json')
28
29   if (token) req.set('Authorization', 'Bearer ' + token)
30
31   return req.expect(200)
32             .expect('Content-Type', /json/)
33 }
34
35 function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) {
36   const path = '/api/v1/videos/' + videoId + '/comment-threads'
37
38   return request(url)
39     .post(path)
40     .send({ text })
41     .set('Accept', 'application/json')
42     .set('Authorization', 'Bearer ' + token)
43     .expect(expectedStatus)
44 }
45
46 function addVideoCommentReply (
47   url: string,
48   token: string,
49   videoId: number | string,
50   inReplyToCommentId: number,
51   text: string,
52   expectedStatus = 200
53 ) {
54   const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId
55
56   return request(url)
57     .post(path)
58     .send({ text })
59     .set('Accept', 'application/json')
60     .set('Authorization', 'Bearer ' + token)
61     .expect(expectedStatus)
62 }
63
64 function deleteVideoComment (
65   url: string,
66   token: string,
67   videoId: number | string,
68   commentId: number,
69   statusCodeExpected = 204
70 ) {
71   const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
72
73   return makeDeleteRequest({
74     url,
75     path,
76     token,
77     statusCodeExpected
78   })
79 }
80
81 // ---------------------------------------------------------------------------
82
83 export {
84   getVideoCommentThreads,
85   getVideoThreadComments,
86   addVideoCommentThread,
87   addVideoCommentReply,
88   deleteVideoComment
89 }