diff options
Diffstat (limited to 'shared/extra-utils/videos/video-comments.ts')
-rw-r--r-- | shared/extra-utils/videos/video-comments.ts | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/shared/extra-utils/videos/video-comments.ts b/shared/extra-utils/videos/video-comments.ts new file mode 100644 index 000000000..0ebf69ced --- /dev/null +++ b/shared/extra-utils/videos/video-comments.ts | |||
@@ -0,0 +1,87 @@ | |||
1 | import * as request from 'supertest' | ||
2 | import { makeDeleteRequest } from '../requests/requests' | ||
3 | |||
4 | function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) { | ||
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 }) | ||
13 | if (token) req.set('Authorization', 'Bearer ' + token) | ||
14 | |||
15 | return req.set('Accept', 'application/json') | ||
16 | .expect(200) | ||
17 | .expect('Content-Type', /json/) | ||
18 | } | ||
19 | |||
20 | function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) { | ||
21 | const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId | ||
22 | |||
23 | const req = request(url) | ||
24 | .get(path) | ||
25 | .set('Accept', 'application/json') | ||
26 | |||
27 | if (token) req.set('Authorization', 'Bearer ' + token) | ||
28 | |||
29 | return req.expect(200) | ||
30 | .expect('Content-Type', /json/) | ||
31 | } | ||
32 | |||
33 | function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) { | ||
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 | |||
44 | function addVideoCommentReply ( | ||
45 | url: string, | ||
46 | token: string, | ||
47 | videoId: number | string, | ||
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 | |||
62 | function 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 | |||
79 | // --------------------------------------------------------------------------- | ||
80 | |||
81 | export { | ||
82 | getVideoCommentThreads, | ||
83 | getVideoThreadComments, | ||
84 | addVideoCommentThread, | ||
85 | addVideoCommentReply, | ||
86 | deleteVideoComment | ||
87 | } | ||