PeerTube/server/tests/utils/video-comments.ts

65 lines
1.7 KiB
TypeScript
Raw Normal View History

2017-12-22 12:10:40 +01:00
import * as request from 'supertest'
2017-12-27 20:03:37 +01:00
function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string) {
2017-12-22 12:10:40 +01:00
const path = '/api/v1/videos/' + videoId + '/comment-threads'
const req = request(url)
.get(path)
.query({ start: start })
.query({ count: count })
if (sort) req.query({ sort })
return req.set('Accept', 'application/json')
.expect(200)
.expect('Content-Type', /json/)
}
2017-12-27 20:03:37 +01:00
function getVideoThreadComments (url: string, videoId: number | string, threadId: number) {
2017-12-22 12:10:40 +01:00
const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
return request(url)
.get(path)
.set('Accept', 'application/json')
.expect(200)
.expect('Content-Type', /json/)
}
2017-12-27 10:12:18 +01:00
function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) {
2017-12-22 12:10:40 +01:00
const path = '/api/v1/videos/' + videoId + '/comment-threads'
return request(url)
.post(path)
.send({ text })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + token)
.expect(expectedStatus)
}
function addVideoCommentReply (
url: string,
token: string,
2017-12-27 20:03:37 +01:00
videoId: number | string,
2017-12-22 12:10:40 +01:00
inReplyToCommentId: number,
text: string,
expectedStatus = 200
) {
const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId
return request(url)
.post(path)
.send({ text })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + token)
.expect(expectedStatus)
}
// ---------------------------------------------------------------------------
export {
getVideoCommentThreads,
getVideoThreadComments,
addVideoCommentThread,
addVideoCommentReply
}