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