]>
Commit | Line | Data |
---|---|---|
d3ea8975 | 1 | import * as request from 'supertest' |
4cb6d457 | 2 | import { makeDeleteRequest } from '../' |
d3ea8975 | 3 | |
d50acfab | 4 | function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: 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 }) | |
13 | ||
14 | return req.set('Accept', 'application/json') | |
15 | .expect(200) | |
16 | .expect('Content-Type', /json/) | |
17 | } | |
18 | ||
d50acfab | 19 | function getVideoThreadComments (url: string, videoId: number | string, threadId: number) { |
d3ea8975 C |
20 | const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId |
21 | ||
22 | return request(url) | |
23 | .get(path) | |
24 | .set('Accept', 'application/json') | |
25 | .expect(200) | |
26 | .expect('Content-Type', /json/) | |
27 | } | |
28 | ||
e2e22e40 | 29 | function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) { |
d3ea8975 C |
30 | const path = '/api/v1/videos/' + videoId + '/comment-threads' |
31 | ||
32 | return request(url) | |
33 | .post(path) | |
34 | .send({ text }) | |
35 | .set('Accept', 'application/json') | |
36 | .set('Authorization', 'Bearer ' + token) | |
37 | .expect(expectedStatus) | |
38 | } | |
39 | ||
40 | function addVideoCommentReply ( | |
41 | url: string, | |
42 | token: string, | |
d50acfab | 43 | videoId: number | string, |
d3ea8975 C |
44 | inReplyToCommentId: number, |
45 | text: string, | |
46 | expectedStatus = 200 | |
47 | ) { | |
48 | const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId | |
49 | ||
50 | return request(url) | |
51 | .post(path) | |
52 | .send({ text }) | |
53 | .set('Accept', 'application/json') | |
54 | .set('Authorization', 'Bearer ' + token) | |
55 | .expect(expectedStatus) | |
56 | } | |
57 | ||
4cb6d457 C |
58 | function deleteVideoComment ( |
59 | url: string, | |
60 | token: string, | |
61 | videoId: number | string, | |
62 | commentId: number, | |
63 | statusCodeExpected = 204 | |
64 | ) { | |
65 | const path = '/api/v1/videos/' + videoId + '/comments/' + commentId | |
66 | ||
67 | return makeDeleteRequest({ | |
68 | url, | |
69 | path, | |
70 | token, | |
71 | statusCodeExpected | |
72 | }) | |
73 | } | |
74 | ||
d3ea8975 C |
75 | // --------------------------------------------------------------------------- |
76 | ||
77 | export { | |
78 | getVideoCommentThreads, | |
79 | getVideoThreadComments, | |
80 | addVideoCommentThread, | |
4cb6d457 C |
81 | addVideoCommentReply, |
82 | deleteVideoComment | |
d3ea8975 | 83 | } |