]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/videos/video-comments.ts
Increase tests waits
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / video-comments.ts
1 /* eslint-disable @typescript-eslint/no-floating-promises */
2
3 import * as request from 'supertest'
4 import { makeDeleteRequest } from '../requests/requests'
5
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'
8
9 const req = request(url)
10 .get(path)
11 .query({ start: start })
12 .query({ count: count })
13
14 if (sort) req.query({ sort })
15 if (token) req.set('Authorization', 'Bearer ' + token)
16
17 return req.set('Accept', 'application/json')
18 .expect(200)
19 .expect('Content-Type', /json/)
20 }
21
22 function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) {
23 const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
24
25 const req = request(url)
26 .get(path)
27 .set('Accept', 'application/json')
28
29 if (token) req.set('Authorization', 'Bearer ' + token)
30
31 return req.expect(200)
32 .expect('Content-Type', /json/)
33 }
34
35 function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) {
36 const path = '/api/v1/videos/' + videoId + '/comment-threads'
37
38 return request(url)
39 .post(path)
40 .send({ text })
41 .set('Accept', 'application/json')
42 .set('Authorization', 'Bearer ' + token)
43 .expect(expectedStatus)
44 }
45
46 function addVideoCommentReply (
47 url: string,
48 token: string,
49 videoId: number | string,
50 inReplyToCommentId: number,
51 text: string,
52 expectedStatus = 200
53 ) {
54 const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId
55
56 return request(url)
57 .post(path)
58 .send({ text })
59 .set('Accept', 'application/json')
60 .set('Authorization', 'Bearer ' + token)
61 .expect(expectedStatus)
62 }
63
64 async function findCommentId (url: string, videoId: number | string, text: string) {
65 const res = await getVideoCommentThreads(url, videoId, 0, 25, '-createdAt')
66
67 return res.body.data.find(c => c.text === text).id as number
68 }
69
70 function deleteVideoComment (
71 url: string,
72 token: string,
73 videoId: number | string,
74 commentId: number,
75 statusCodeExpected = 204
76 ) {
77 const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
78
79 return makeDeleteRequest({
80 url,
81 path,
82 token,
83 statusCodeExpected
84 })
85 }
86
87 // ---------------------------------------------------------------------------
88
89 export {
90 getVideoCommentThreads,
91 getVideoThreadComments,
92 addVideoCommentThread,
93 addVideoCommentReply,
94 findCommentId,
95 deleteVideoComment
96 }