]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/utils/videos/video-comments.ts
Check video exists before extending its expiration
[github/Chocobozzz/PeerTube.git] / server / tests / utils / videos / video-comments.ts
CommitLineData
d3ea8975 1import * as request from 'supertest'
4cb6d457 2import { makeDeleteRequest } from '../'
d3ea8975 3
d50acfab 4function 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 19function 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 29function 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
40function 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
58function 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
77export {
78 getVideoCommentThreads,
79 getVideoThreadComments,
80 addVideoCommentThread,
4cb6d457
C
81 addVideoCommentReply,
82 deleteVideoComment
d3ea8975 83}