video-abuses.ts 6.3 KB

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