aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/video-comments.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils/video-comments.ts')
-rw-r--r--server/tests/utils/video-comments.ts64
1 files changed, 64 insertions, 0 deletions
diff --git a/server/tests/utils/video-comments.ts b/server/tests/utils/video-comments.ts
new file mode 100644
index 000000000..be062f815
--- /dev/null
+++ b/server/tests/utils/video-comments.ts
@@ -0,0 +1,64 @@
1import * as request from 'supertest'
2
3function getVideoCommentThreads (url: string, videoId: number, start: number, count: number, sort?: string) {
4 const path = '/api/v1/videos/' + videoId + '/comment-threads'
5
6 const req = request(url)
7 .get(path)
8 .query({ start: start })
9 .query({ count: count })
10
11 if (sort) req.query({ sort })
12
13 return req.set('Accept', 'application/json')
14 .expect(200)
15 .expect('Content-Type', /json/)
16}
17
18function getVideoThreadComments (url: string, videoId: number, threadId: number) {
19 const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
20
21 return request(url)
22 .get(path)
23 .set('Accept', 'application/json')
24 .expect(200)
25 .expect('Content-Type', /json/)
26}
27
28function addVideoCommentThread (url: string, token: string, videoId: number, text: string, expectedStatus = 200) {
29 const path = '/api/v1/videos/' + videoId + '/comment-threads'
30
31 return request(url)
32 .post(path)
33 .send({ text })
34 .set('Accept', 'application/json')
35 .set('Authorization', 'Bearer ' + token)
36 .expect(expectedStatus)
37}
38
39function addVideoCommentReply (
40 url: string,
41 token: string,
42 videoId: number,
43 inReplyToCommentId: number,
44 text: string,
45 expectedStatus = 200
46) {
47 const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId
48
49 return request(url)
50 .post(path)
51 .send({ text })
52 .set('Accept', 'application/json')
53 .set('Authorization', 'Bearer ' + token)
54 .expect(expectedStatus)
55}
56
57// ---------------------------------------------------------------------------
58
59export {
60 getVideoCommentThreads,
61 getVideoThreadComments,
62 addVideoCommentThread,
63 addVideoCommentReply
64}