2020-01-31 16:56:52 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-floating-promises */
|
|
|
|
|
2017-12-22 12:10:40 +01:00
|
|
|
import * as request from 'supertest'
|
2020-11-16 11:55:17 +01:00
|
|
|
import { makeDeleteRequest, makeGetRequest } from '../requests/requests'
|
2020-12-07 14:32:36 +01:00
|
|
|
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
2020-11-16 11:55:17 +01:00
|
|
|
|
|
|
|
function getAdminVideoComments (options: {
|
|
|
|
url: string
|
|
|
|
token: string
|
|
|
|
start: number
|
|
|
|
count: number
|
|
|
|
sort?: string
|
|
|
|
isLocal?: boolean
|
|
|
|
search?: string
|
|
|
|
searchAccount?: string
|
|
|
|
searchVideo?: string
|
|
|
|
}) {
|
|
|
|
const { url, token, start, count, sort, isLocal, search, searchAccount, searchVideo } = options
|
|
|
|
const path = '/api/v1/videos/comments'
|
|
|
|
|
|
|
|
const query = {
|
|
|
|
start,
|
|
|
|
count,
|
|
|
|
sort: sort || '-createdAt'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isLocal !== undefined) Object.assign(query, { isLocal })
|
|
|
|
if (search !== undefined) Object.assign(query, { search })
|
|
|
|
if (searchAccount !== undefined) Object.assign(query, { searchAccount })
|
|
|
|
if (searchVideo !== undefined) Object.assign(query, { searchVideo })
|
|
|
|
|
|
|
|
return makeGetRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
token,
|
|
|
|
query,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.OK_200
|
2020-11-16 11:55:17 +01:00
|
|
|
})
|
|
|
|
}
|
2017-12-22 12:10:40 +01:00
|
|
|
|
2018-10-12 15:26:04 +02:00
|
|
|
function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: 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 })
|
2018-10-12 15:26:04 +02:00
|
|
|
if (token) req.set('Authorization', 'Bearer ' + token)
|
2017-12-22 12:10:40 +01:00
|
|
|
|
|
|
|
return req.set('Accept', 'application/json')
|
2020-12-07 14:32:36 +01:00
|
|
|
.expect(HttpStatusCode.OK_200)
|
2017-12-22 12:10:40 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
}
|
|
|
|
|
2018-10-12 15:26:04 +02:00
|
|
|
function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) {
|
2017-12-22 12:10:40 +01:00
|
|
|
const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
|
|
|
|
|
2018-10-12 15:26:04 +02:00
|
|
|
const req = request(url)
|
2017-12-22 12:10:40 +01:00
|
|
|
.get(path)
|
|
|
|
.set('Accept', 'application/json')
|
2018-10-12 15:26:04 +02:00
|
|
|
|
|
|
|
if (token) req.set('Authorization', 'Bearer ' + token)
|
|
|
|
|
2020-12-07 14:32:36 +01:00
|
|
|
return req.expect(HttpStatusCode.OK_200)
|
2018-10-12 15:26:04 +02:00
|
|
|
.expect('Content-Type', /json/)
|
2017-12-22 12:10:40 +01:00
|
|
|
}
|
|
|
|
|
2020-12-07 14:32:36 +01:00
|
|
|
function addVideoCommentThread (
|
|
|
|
url: string,
|
|
|
|
token: string,
|
|
|
|
videoId: number | string,
|
|
|
|
text: string,
|
|
|
|
expectedStatus = HttpStatusCode.OK_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,
|
2020-12-07 14:32:36 +01:00
|
|
|
expectedStatus = HttpStatusCode.OK_200
|
2017-12-22 12:10:40 +01:00
|
|
|
) {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-05-22 17:06:26 +02:00
|
|
|
async function findCommentId (url: string, videoId: number | string, text: string) {
|
|
|
|
const res = await getVideoCommentThreads(url, videoId, 0, 25, '-createdAt')
|
|
|
|
|
|
|
|
return res.body.data.find(c => c.text === text).id as number
|
|
|
|
}
|
|
|
|
|
2018-01-04 11:19:16 +01:00
|
|
|
function deleteVideoComment (
|
|
|
|
url: string,
|
|
|
|
token: string,
|
|
|
|
videoId: number | string,
|
|
|
|
commentId: number,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected = HttpStatusCode.NO_CONTENT_204
|
2018-01-04 11:19:16 +01:00
|
|
|
) {
|
|
|
|
const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
|
|
|
|
|
|
|
|
return makeDeleteRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
token,
|
|
|
|
statusCodeExpected
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-12-22 12:10:40 +01:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
getVideoCommentThreads,
|
2020-11-16 11:55:17 +01:00
|
|
|
getAdminVideoComments,
|
2017-12-22 12:10:40 +01:00
|
|
|
getVideoThreadComments,
|
|
|
|
addVideoCommentThread,
|
2018-01-04 11:19:16 +01:00
|
|
|
addVideoCommentReply,
|
2020-05-22 17:06:26 +02:00
|
|
|
findCommentId,
|
2018-01-04 11:19:16 +01:00
|
|
|
deleteVideoComment
|
2017-12-22 12:10:40 +01:00
|
|
|
}
|