]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/videos/video-comments.ts
Update plugin guides toc
[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
696d83fd
C
64async function findCommentId (url: string, videoId: number | string, text: string) {
65 const res = await getVideoCommentThreads(url, videoId, 0, 25, '-createdAt')
66
67 return res.body.data.find(c => c.text === text).id as number
68}
69
4cb6d457
C
70function deleteVideoComment (
71 url: string,
72 token: string,
73 videoId: number | string,
74 commentId: number,
75 statusCodeExpected = 204
76) {
77 const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
78
79 return makeDeleteRequest({
80 url,
81 path,
82 token,
83 statusCodeExpected
84 })
85}
86
d3ea8975
C
87// ---------------------------------------------------------------------------
88
89export {
90 getVideoCommentThreads,
91 getVideoThreadComments,
92 addVideoCommentThread,
4cb6d457 93 addVideoCommentReply,
696d83fd 94 findCommentId,
4cb6d457 95 deleteVideoComment
d3ea8975 96}