2
1

video-blacklist.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import * as request from 'supertest'
  2. import { VideoBlacklistType } from '../../models/videos'
  3. import { makeGetRequest } from '..'
  4. import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
  5. function addVideoToBlacklist (
  6. url: string,
  7. token: string,
  8. videoId: number | string,
  9. reason?: string,
  10. unfederate?: boolean,
  11. specialStatus = HttpStatusCode.NO_CONTENT_204
  12. ) {
  13. const path = '/api/v1/videos/' + videoId + '/blacklist'
  14. return request(url)
  15. .post(path)
  16. .send({ reason, unfederate })
  17. .set('Accept', 'application/json')
  18. .set('Authorization', 'Bearer ' + token)
  19. .expect(specialStatus)
  20. }
  21. function updateVideoBlacklist (
  22. url: string,
  23. token: string,
  24. videoId: number,
  25. reason?: string,
  26. specialStatus = HttpStatusCode.NO_CONTENT_204
  27. ) {
  28. const path = '/api/v1/videos/' + videoId + '/blacklist'
  29. return request(url)
  30. .put(path)
  31. .send({ reason })
  32. .set('Accept', 'application/json')
  33. .set('Authorization', 'Bearer ' + token)
  34. .expect(specialStatus)
  35. }
  36. function removeVideoFromBlacklist (url: string, token: string, videoId: number | string, specialStatus = HttpStatusCode.NO_CONTENT_204) {
  37. const path = '/api/v1/videos/' + videoId + '/blacklist'
  38. return request(url)
  39. .delete(path)
  40. .set('Accept', 'application/json')
  41. .set('Authorization', 'Bearer ' + token)
  42. .expect(specialStatus)
  43. }
  44. function getBlacklistedVideosList (parameters: {
  45. url: string
  46. token: string
  47. sort?: string
  48. type?: VideoBlacklistType
  49. specialStatus?: HttpStatusCode
  50. }) {
  51. const { url, token, sort, type, specialStatus = HttpStatusCode.OK_200 } = parameters
  52. const path = '/api/v1/videos/blacklist/'
  53. const query = { sort, type }
  54. return makeGetRequest({
  55. url,
  56. path,
  57. query,
  58. token,
  59. statusCodeExpected: specialStatus
  60. })
  61. }
  62. // ---------------------------------------------------------------------------
  63. export {
  64. addVideoToBlacklist,
  65. removeVideoFromBlacklist,
  66. getBlacklistedVideosList,
  67. updateVideoBlacklist
  68. }