1 /* eslint-disable @typescript-eslint/no-floating-promises */
3 import * as request from 'supertest'
4 import { makeDeleteRequest } from '../requests/requests'
6 function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) {
7 const path = '/api/v1/videos/' + videoId + '/comment-threads'
9 const req = request(url)
11 .query({ start: start })
12 .query({ count: count })
14 if (sort) req.query({ sort })
15 if (token) req.set('Authorization', 'Bearer ' + token)
17 return req.set('Accept', 'application/json')
19 .expect('Content-Type', /json/)
22 function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) {
23 const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
25 const req = request(url)
27 .set('Accept', 'application/json')
29 if (token) req.set('Authorization', 'Bearer ' + token)
31 return req.expect(200)
32 .expect('Content-Type', /json/)
35 function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) {
36 const path = '/api/v1/videos/' + videoId + '/comment-threads'
41 .set('Accept', 'application/json')
42 .set('Authorization', 'Bearer ' + token)
43 .expect(expectedStatus)
46 function addVideoCommentReply (
49 videoId: number | string,
50 inReplyToCommentId: number,
54 const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId
59 .set('Accept', 'application/json')
60 .set('Authorization', 'Bearer ' + token)
61 .expect(expectedStatus)
64 async function findCommentId (url: string, videoId: number | string, text: string) {
65 const res = await getVideoCommentThreads(url, videoId, 0, 25, '-createdAt')
67 return res.body.data.find(c => c.text === text).id as number
70 function deleteVideoComment (
73 videoId: number | string,
75 statusCodeExpected = 204
77 const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
79 return makeDeleteRequest({
87 // ---------------------------------------------------------------------------
90 getVideoCommentThreads,
91 getVideoThreadComments,
92 addVideoCommentThread,