video-abuses.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* tslint:disable:no-unused-expression */
  2. import 'mocha'
  3. import {
  4. createUser,
  5. deleteVideoAbuse,
  6. flushTests,
  7. killallServers,
  8. makeGetRequest,
  9. makePostBodyRequest,
  10. flushAndRunServer,
  11. ServerInfo,
  12. setAccessTokensToServers,
  13. updateVideoAbuse,
  14. uploadVideo,
  15. userLogin
  16. } from '../../../../shared/extra-utils'
  17. import {
  18. checkBadCountPagination,
  19. checkBadSortPagination,
  20. checkBadStartPagination
  21. } from '../../../../shared/extra-utils/requests/check-api-params'
  22. import { VideoAbuseState } from '../../../../shared/models/videos'
  23. describe('Test video abuses API validators', function () {
  24. let server: ServerInfo
  25. let userAccessToken = ''
  26. let videoAbuseId: number
  27. // ---------------------------------------------------------------
  28. before(async function () {
  29. this.timeout(30000)
  30. server = await flushAndRunServer(1)
  31. await setAccessTokensToServers([ server ])
  32. const username = 'user1'
  33. const password = 'my super password'
  34. await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
  35. userAccessToken = await userLogin(server, { username, password })
  36. const res = await uploadVideo(server.url, server.accessToken, {})
  37. server.video = res.body.video
  38. })
  39. describe('When listing video abuses', function () {
  40. const path = '/api/v1/videos/abuse'
  41. it('Should fail with a bad start pagination', async function () {
  42. await checkBadStartPagination(server.url, path, server.accessToken)
  43. })
  44. it('Should fail with a bad count pagination', async function () {
  45. await checkBadCountPagination(server.url, path, server.accessToken)
  46. })
  47. it('Should fail with an incorrect sort', async function () {
  48. await checkBadSortPagination(server.url, path, server.accessToken)
  49. })
  50. it('Should fail with a non authenticated user', async function () {
  51. await makeGetRequest({
  52. url: server.url,
  53. path,
  54. statusCodeExpected: 401
  55. })
  56. })
  57. it('Should fail with a non admin user', async function () {
  58. await makeGetRequest({
  59. url: server.url,
  60. path,
  61. token: userAccessToken,
  62. statusCodeExpected: 403
  63. })
  64. })
  65. })
  66. describe('When reporting a video abuse', function () {
  67. const basePath = '/api/v1/videos/'
  68. let path: string
  69. before(() => {
  70. path = basePath + server.video.id + '/abuse'
  71. })
  72. it('Should fail with nothing', async function () {
  73. const fields = {}
  74. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  75. })
  76. it('Should fail with a wrong video', async function () {
  77. const wrongPath = '/api/v1/videos/blabla/abuse'
  78. const fields = { reason: 'my super reason' }
  79. await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
  80. })
  81. it('Should fail with a non authenticated user', async function () {
  82. const fields = { reason: 'my super reason' }
  83. await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
  84. })
  85. it('Should fail with a reason too short', async function () {
  86. const fields = { reason: 'h' }
  87. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  88. })
  89. it('Should fail with a too big reason', async function () {
  90. const fields = { reason: 'super'.repeat(605) }
  91. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
  92. })
  93. it('Should succeed with the correct parameters', async function () {
  94. const fields = { reason: 'super reason' }
  95. const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
  96. videoAbuseId = res.body.videoAbuse.id
  97. })
  98. })
  99. describe('When updating a video abuse', function () {
  100. const basePath = '/api/v1/videos/'
  101. let path: string
  102. before(() => {
  103. path = basePath + server.video.id + '/abuse/' + videoAbuseId
  104. })
  105. it('Should fail with a non authenticated user', async function () {
  106. await updateVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, {}, 401)
  107. })
  108. it('Should fail with a non admin user', async function () {
  109. await updateVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, {}, 403)
  110. })
  111. it('Should fail with a bad video id or bad video abuse id', async function () {
  112. await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, {}, 404)
  113. await updateVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, {}, 404)
  114. })
  115. it('Should fail with a bad state', async function () {
  116. const body = { state: 5 }
  117. await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
  118. })
  119. it('Should fail with a bad moderation comment', async function () {
  120. const body = { moderationComment: 'b'.repeat(3001) }
  121. await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
  122. })
  123. it('Should succeed with the correct params', async function () {
  124. const body = { state: VideoAbuseState.ACCEPTED }
  125. await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body)
  126. })
  127. })
  128. describe('When deleting a video abuse', function () {
  129. const basePath = '/api/v1/videos/'
  130. let path: string
  131. before(() => {
  132. path = basePath + server.video.id + '/abuse/' + videoAbuseId
  133. })
  134. it('Should fail with a non authenticated user', async function () {
  135. await deleteVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, 401)
  136. })
  137. it('Should fail with a non admin user', async function () {
  138. await deleteVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, 403)
  139. })
  140. it('Should fail with a bad video id or bad video abuse id', async function () {
  141. await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, 404)
  142. await deleteVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, 404)
  143. })
  144. it('Should succeed with the correct params', async function () {
  145. await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId)
  146. })
  147. })
  148. after(function () {
  149. killallServers([ server ])
  150. })
  151. })