2017-12-22 05:10:40 -06:00
|
|
|
import * as request from 'supertest'
|
2018-01-04 04:19:16 -06:00
|
|
|
import { makeDeleteRequest } from '../'
|
2017-12-22 05:10:40 -06:00
|
|
|
|
2018-10-12 08:26:04 -05:00
|
|
|
function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) {
|
2017-12-22 05:10:40 -06: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 })
|
2018-10-12 08:26:04 -05:00
|
|
|
if (token) req.set('Authorization', 'Bearer ' + token)
|
2017-12-22 05:10:40 -06:00
|
|
|
|
|
|
|
return req.set('Accept', 'application/json')
|
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
}
|
|
|
|
|
2018-10-12 08:26:04 -05:00
|
|
|
function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) {
|
2017-12-22 05:10:40 -06:00
|
|
|
const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
|
|
|
|
|
2018-10-12 08:26:04 -05:00
|
|
|
const req = request(url)
|
2017-12-22 05:10:40 -06:00
|
|
|
.get(path)
|
|
|
|
.set('Accept', 'application/json')
|
2018-10-12 08:26:04 -05:00
|
|
|
|
|
|
|
if (token) req.set('Authorization', 'Bearer ' + token)
|
|
|
|
|
|
|
|
return req.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
2017-12-22 05:10:40 -06:00
|
|
|
}
|
|
|
|
|
2017-12-27 03:12:18 -06:00
|
|
|
function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) {
|
2017-12-22 05:10:40 -06: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 13:03:37 -06:00
|
|
|
videoId: number | string,
|
2017-12-22 05:10:40 -06: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)
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:19:16 -06:00
|
|
|
function deleteVideoComment (
|
|
|
|
url: string,
|
|
|
|
token: string,
|
|
|
|
videoId: number | string,
|
|
|
|
commentId: number,
|
|
|
|
statusCodeExpected = 204
|
|
|
|
) {
|
|
|
|
const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
|
|
|
|
|
|
|
|
return makeDeleteRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
token,
|
|
|
|
statusCodeExpected
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-12-22 05:10:40 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
getVideoCommentThreads,
|
|
|
|
getVideoThreadComments,
|
|
|
|
addVideoCommentThread,
|
2018-01-04 04:19:16 -06:00
|
|
|
addVideoCommentReply,
|
|
|
|
deleteVideoComment
|
2017-12-22 05:10:40 -06:00
|
|
|
}
|