1 /* eslint-disable @typescript-eslint/no-floating-promises */
3 import * as request from 'supertest'
4 import { makeDeleteRequest, makeGetRequest } from '../requests/requests'
6 function getAdminVideoComments (options: {
14 searchAccount?: string
17 const { url, token, start, count, sort, isLocal, search, searchAccount, searchVideo } = options
18 const path = '/api/v1/videos/comments'
23 sort: sort || '-createdAt'
26 if (isLocal !== undefined) Object.assign(query, { isLocal })
27 if (search !== undefined) Object.assign(query, { search })
28 if (searchAccount !== undefined) Object.assign(query, { searchAccount })
29 if (searchVideo !== undefined) Object.assign(query, { searchVideo })
31 return makeGetRequest({
36 statusCodeExpected: 200
40 function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) {
41 const path = '/api/v1/videos/' + videoId + '/comment-threads'
43 const req = request(url)
45 .query({ start: start })
46 .query({ count: count })
48 if (sort) req.query({ sort })
49 if (token) req.set('Authorization', 'Bearer ' + token)
51 return req.set('Accept', 'application/json')
53 .expect('Content-Type', /json/)
56 function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) {
57 const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
59 const req = request(url)
61 .set('Accept', 'application/json')
63 if (token) req.set('Authorization', 'Bearer ' + token)
65 return req.expect(200)
66 .expect('Content-Type', /json/)
69 function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) {
70 const path = '/api/v1/videos/' + videoId + '/comment-threads'
75 .set('Accept', 'application/json')
76 .set('Authorization', 'Bearer ' + token)
77 .expect(expectedStatus)
80 function addVideoCommentReply (
83 videoId: number | string,
84 inReplyToCommentId: number,
88 const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId
93 .set('Accept', 'application/json')
94 .set('Authorization', 'Bearer ' + token)
95 .expect(expectedStatus)
98 async function findCommentId (url: string, videoId: number | string, text: string) {
99 const res = await getVideoCommentThreads(url, videoId, 0, 25, '-createdAt')
101 return res.body.data.find(c => c.text === text).id as number
104 function deleteVideoComment (
107 videoId: number | string,
109 statusCodeExpected = 204
111 const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
113 return makeDeleteRequest({
121 // ---------------------------------------------------------------------------
124 getVideoCommentThreads,
125 getAdminVideoComments,
126 getVideoThreadComments,
127 addVideoCommentThread,
128 addVideoCommentReply,