diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-22 12:10:40 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-22 12:12:33 +0100 |
commit | d3ea89759104e6c14b00443526f2c2a0a13aeb97 (patch) | |
tree | e30dc7025f284c163a450cb08f7060875e368e6c /server/tests/utils | |
parent | bf1f650817dadfd5eeee9e5e0b6b6938c136e25d (diff) | |
download | PeerTube-d3ea89759104e6c14b00443526f2c2a0a13aeb97.tar.gz PeerTube-d3ea89759104e6c14b00443526f2c2a0a13aeb97.tar.zst PeerTube-d3ea89759104e6c14b00443526f2c2a0a13aeb97.zip |
Begin unit tests
Diffstat (limited to 'server/tests/utils')
-rw-r--r-- | server/tests/utils/video-comments.ts | 64 |
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 @@ | |||
1 | import * as request from 'supertest' | ||
2 | |||
3 | function 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 | |||
18 | function 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 | |||
28 | function 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 | |||
39 | function 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 | |||
59 | export { | ||
60 | getVideoCommentThreads, | ||
61 | getVideoThreadComments, | ||
62 | addVideoCommentThread, | ||
63 | addVideoCommentReply | ||
64 | } | ||