1 /* eslint-disable @typescript-eslint/no-floating-promises */
3 import * as request from 'supertest'
4 import { makeDeleteRequest, makeGetRequest } from '../requests/requests'
5 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
7 function getAdminVideoComments (options: {
15 searchAccount?: string
18 const { url, token, start, count, sort, isLocal, search, searchAccount, searchVideo } = options
19 const path = '/api/v1/videos/comments'
24 sort: sort || '-createdAt'
27 if (isLocal !== undefined) Object.assign(query, { isLocal })
28 if (search !== undefined) Object.assign(query, { search })
29 if (searchAccount !== undefined) Object.assign(query, { searchAccount })
30 if (searchVideo !== undefined) Object.assign(query, { searchVideo })
32 return makeGetRequest({
37 statusCodeExpected: HttpStatusCode.OK_200
41 function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) {
42 const path = '/api/v1/videos/' + videoId + '/comment-threads'
44 const req = request(url)
46 .query({ start: start })
47 .query({ count: count })
49 if (sort) req.query({ sort })
50 if (token) req.set('Authorization', 'Bearer ' + token)
52 return req.set('Accept', 'application/json')
53 .expect(HttpStatusCode.OK_200)
54 .expect('Content-Type', /json/)
57 function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) {
58 const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
60 const req = request(url)
62 .set('Accept', 'application/json')
64 if (token) req.set('Authorization', 'Bearer ' + token)
66 return req.expect(HttpStatusCode.OK_200)
67 .expect('Content-Type', /json/)
70 function addVideoCommentThread (
73 videoId: number | string,
75 expectedStatus = HttpStatusCode.OK_200
77 const path = '/api/v1/videos/' + videoId + '/comment-threads'
82 .set('Accept', 'application/json')
83 .set('Authorization', 'Bearer ' + token)
84 .expect(expectedStatus)
87 function addVideoCommentReply (
90 videoId: number | string,
91 inReplyToCommentId: number,
93 expectedStatus = HttpStatusCode.OK_200
95 const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId
100 .set('Accept', 'application/json')
101 .set('Authorization', 'Bearer ' + token)
102 .expect(expectedStatus)
105 async function findCommentId (url: string, videoId: number | string, text: string) {
106 const res = await getVideoCommentThreads(url, videoId, 0, 25, '-createdAt')
108 return res.body.data.find(c => c.text === text).id as number
111 function deleteVideoComment (
114 videoId: number | string,
116 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
118 const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
120 return makeDeleteRequest({
128 // ---------------------------------------------------------------------------
131 getVideoCommentThreads,
132 getAdminVideoComments,
133 getVideoThreadComments,
134 addVideoCommentThread,
135 addVideoCommentReply,