video-comments.ts 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* tslint:disable:no-unused-expression */
  2. import * as chai from 'chai'
  3. import 'mocha'
  4. import {
  5. cleanupTests,
  6. createUser,
  7. flushAndRunServer,
  8. makeDeleteRequest,
  9. makeGetRequest,
  10. makePostBodyRequest,
  11. ServerInfo,
  12. setAccessTokensToServers,
  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 { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
  22. const expect = chai.expect
  23. describe('Test video comments API validator', function () {
  24. let pathThread: string
  25. let pathComment: string
  26. let server: ServerInfo
  27. let videoUUID: string
  28. let userAccessToken: string
  29. let commentId: number
  30. // ---------------------------------------------------------------
  31. before(async function () {
  32. this.timeout(30000)
  33. server = await flushAndRunServer(1)
  34. await setAccessTokensToServers([ server ])
  35. {
  36. const res = await uploadVideo(server.url, server.accessToken, {})
  37. videoUUID = res.body.video.uuid
  38. pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
  39. }
  40. {
  41. const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, 'coucou')
  42. commentId = res.body.comment.id
  43. pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId
  44. }
  45. {
  46. const user = {
  47. username: 'user1',
  48. password: 'my super password'
  49. }
  50. await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
  51. userAccessToken = await userLogin(server, user)
  52. }
  53. })
  54. describe('When listing video comment threads', function () {
  55. it('Should fail with a bad start pagination', async function () {
  56. await checkBadStartPagination(server.url, pathThread, server.accessToken)
  57. })
  58. it('Should fail with a bad count pagination', async function () {
  59. await checkBadCountPagination(server.url, pathThread, server.accessToken)
  60. })
  61. it('Should fail with an incorrect sort', async function () {
  62. await checkBadSortPagination(server.url, pathThread, server.accessToken)
  63. })
  64. it('Should fail with an incorrect video', async function () {
  65. await makeGetRequest({
  66. url: server.url,
  67. path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
  68. statusCodeExpected: 404
  69. })
  70. })
  71. })
  72. describe('When listing comments of a thread', function () {
  73. it('Should fail with an incorrect video', async function () {
  74. await makeGetRequest({
  75. url: server.url,
  76. path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
  77. statusCodeExpected: 404
  78. })
  79. })
  80. it('Should fail with an incorrect thread id', async function () {
  81. await makeGetRequest({
  82. url: server.url,
  83. path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
  84. statusCodeExpected: 404
  85. })
  86. })
  87. it('Should success with the correct params', async function () {
  88. await makeGetRequest({
  89. url: server.url,
  90. path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
  91. statusCodeExpected: 200
  92. })
  93. })
  94. })
  95. describe('When adding a video thread', function () {
  96. it('Should fail with a non authenticated user', async function () {
  97. const fields = {
  98. text: 'text'
  99. }
  100. await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 })
  101. })
  102. it('Should fail with nothing', async function () {
  103. const fields = {}
  104. await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
  105. })
  106. it('Should fail with a short comment', async function () {
  107. const fields = {
  108. text: ''
  109. }
  110. await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
  111. })
  112. it('Should fail with a long comment', async function () {
  113. const fields = {
  114. text: 'h'.repeat(3001)
  115. }
  116. await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields })
  117. })
  118. it('Should fail with an incorrect video', async function () {
  119. const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads'
  120. const fields = {
  121. text: 'super comment'
  122. }
  123. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
  124. })
  125. it('Should succeed with the correct parameters', async function () {
  126. const fields = {
  127. text: 'super comment'
  128. }
  129. await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 })
  130. })
  131. })
  132. describe('When adding a comment to a thread', function () {
  133. it('Should fail with a non authenticated user', async function () {
  134. const fields = {
  135. text: 'text'
  136. }
  137. await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 })
  138. })
  139. it('Should fail with nothing', async function () {
  140. const fields = {}
  141. await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
  142. })
  143. it('Should fail with a short comment', async function () {
  144. const fields = {
  145. text: ''
  146. }
  147. await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
  148. })
  149. it('Should fail with a long comment', async function () {
  150. const fields = {
  151. text: 'h'.repeat(3001)
  152. }
  153. await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields })
  154. })
  155. it('Should fail with an incorrect video', async function () {
  156. const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
  157. const fields = {
  158. text: 'super comment'
  159. }
  160. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
  161. })
  162. it('Should fail with an incorrect comment', async function () {
  163. const path = '/api/v1/videos/' + videoUUID + '/comments/124'
  164. const fields = {
  165. text: 'super comment'
  166. }
  167. await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
  168. })
  169. it('Should succeed with the correct parameters', async function () {
  170. const fields = {
  171. text: 'super comment'
  172. }
  173. await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 })
  174. })
  175. })
  176. describe('When removing video comments', function () {
  177. it('Should fail with a non authenticated user', async function () {
  178. await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: 401 })
  179. })
  180. it('Should fail with another user', async function () {
  181. await makeDeleteRequest({ url: server.url, path: pathComment, token: userAccessToken, statusCodeExpected: 403 })
  182. })
  183. it('Should fail with an incorrect video', async function () {
  184. const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
  185. await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
  186. })
  187. it('Should fail with an incorrect comment', async function () {
  188. const path = '/api/v1/videos/' + videoUUID + '/comments/124'
  189. await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
  190. })
  191. it('Should succeed with the correct parameters', async function () {
  192. await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 })
  193. })
  194. })
  195. describe('When a video has comments disabled', function () {
  196. before(async function () {
  197. const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false })
  198. videoUUID = res.body.video.uuid
  199. pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
  200. })
  201. it('Should return an empty thread list', async function () {
  202. const res = await makeGetRequest({
  203. url: server.url,
  204. path: pathThread,
  205. statusCodeExpected: 200
  206. })
  207. expect(res.body.total).to.equal(0)
  208. expect(res.body.data).to.have.lengthOf(0)
  209. })
  210. it('Should return an thread comments list')
  211. it('Should return conflict on thread add', async function () {
  212. const fields = {
  213. text: 'super comment'
  214. }
  215. await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 409 })
  216. })
  217. it('Should return conflict on comment thread add')
  218. })
  219. after(async function () {
  220. await cleanupTests([ server ])
  221. })
  222. })