]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/videos/video-comments.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / video-comments.ts
CommitLineData
a1587156
C
1/* eslint-disable @typescript-eslint/no-floating-promises */
2
d3ea8975 3import * as request from 'supertest'
d175a6f7 4import { makeDeleteRequest } from '../requests/requests'
d3ea8975 5
7ad9b984 6function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) {
d3ea8975
C
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 })
7ad9b984 15 if (token) req.set('Authorization', 'Bearer ' + token)
d3ea8975
C
16
17 return req.set('Accept', 'application/json')
18 .expect(200)
19 .expect('Content-Type', /json/)
20}
21
7ad9b984 22function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) {
d3ea8975
C
23 const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
24
7ad9b984 25 const req = request(url)
d3ea8975
C
26 .get(path)
27 .set('Accept', 'application/json')
7ad9b984
C
28
29 if (token) req.set('Authorization', 'Bearer ' + token)
30
31 return req.expect(200)
32 .expect('Content-Type', /json/)
d3ea8975
C
33}
34
e2e22e40 35function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) {
d3ea8975
C
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
46function addVideoCommentReply (
47 url: string,
48 token: string,
d50acfab 49 videoId: number | string,
d3ea8975
C
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
4cb6d457
C
64function 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
d3ea8975
C
81// ---------------------------------------------------------------------------
82
83export {
84 getVideoCommentThreads,
85 getVideoThreadComments,
86 addVideoCommentThread,
4cb6d457
C
87 addVideoCommentReply,
88 deleteVideoComment
d3ea8975 89}