video-comments.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import * as request from 'supertest'
  2. import { makeDeleteRequest } from '../requests/requests'
  3. function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) {
  4. const path = '/api/v1/videos/' + videoId + '/comment-threads'
  5. const req = request(url)
  6. .get(path)
  7. .query({ start: start })
  8. .query({ count: count })
  9. if (sort) req.query({ sort })
  10. if (token) req.set('Authorization', 'Bearer ' + token)
  11. return req.set('Accept', 'application/json')
  12. .expect(200)
  13. .expect('Content-Type', /json/)
  14. }
  15. function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) {
  16. const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
  17. const req = request(url)
  18. .get(path)
  19. .set('Accept', 'application/json')
  20. if (token) req.set('Authorization', 'Bearer ' + token)
  21. return req.expect(200)
  22. .expect('Content-Type', /json/)
  23. }
  24. function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) {
  25. const path = '/api/v1/videos/' + videoId + '/comment-threads'
  26. return request(url)
  27. .post(path)
  28. .send({ text })
  29. .set('Accept', 'application/json')
  30. .set('Authorization', 'Bearer ' + token)
  31. .expect(expectedStatus)
  32. }
  33. function addVideoCommentReply (
  34. url: string,
  35. token: string,
  36. videoId: number | string,
  37. inReplyToCommentId: number,
  38. text: string,
  39. expectedStatus = 200
  40. ) {
  41. const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId
  42. return request(url)
  43. .post(path)
  44. .send({ text })
  45. .set('Accept', 'application/json')
  46. .set('Authorization', 'Bearer ' + token)
  47. .expect(expectedStatus)
  48. }
  49. function deleteVideoComment (
  50. url: string,
  51. token: string,
  52. videoId: number | string,
  53. commentId: number,
  54. statusCodeExpected = 204
  55. ) {
  56. const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
  57. return makeDeleteRequest({
  58. url,
  59. path,
  60. token,
  61. statusCodeExpected
  62. })
  63. }
  64. // ---------------------------------------------------------------------------
  65. export {
  66. getVideoCommentThreads,
  67. getVideoThreadComments,
  68. addVideoCommentThread,
  69. addVideoCommentReply,
  70. deleteVideoComment
  71. }