action-hooks.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* tslint:disable:no-unused-expression */
  2. import * as chai from 'chai'
  3. import 'mocha'
  4. import {
  5. cleanupTests,
  6. flushAndRunMultipleServers,
  7. killallServers,
  8. reRunServer,
  9. ServerInfo,
  10. waitUntilLog
  11. } from '../../../shared/extra-utils/server/servers'
  12. import {
  13. addVideoCommentReply,
  14. addVideoCommentThread,
  15. blockUser,
  16. createUser,
  17. deleteVideoComment,
  18. getPluginTestPath,
  19. installPlugin, login,
  20. registerUser, removeUser,
  21. setAccessTokensToServers,
  22. unblockUser, updateUser,
  23. updateVideo,
  24. uploadVideo,
  25. viewVideo,
  26. userLogin
  27. } from '../../../shared/extra-utils'
  28. const expect = chai.expect
  29. describe('Test plugin action hooks', function () {
  30. let servers: ServerInfo[]
  31. let videoUUID: string
  32. let threadId: number
  33. function checkHook (hook: string) {
  34. return waitUntilLog(servers[0], 'Run hook ' + hook)
  35. }
  36. before(async function () {
  37. this.timeout(30000)
  38. servers = await flushAndRunMultipleServers(2)
  39. await setAccessTokensToServers(servers)
  40. await installPlugin({
  41. url: servers[0].url,
  42. accessToken: servers[0].accessToken,
  43. path: getPluginTestPath()
  44. })
  45. killallServers([ servers[0] ])
  46. await reRunServer(servers[0])
  47. })
  48. describe('Application hooks', function () {
  49. it('Should run action:application.listening', async function () {
  50. await checkHook('action:application.listening')
  51. })
  52. })
  53. describe('Videos hooks', function () {
  54. it('Should run action:api.video.uploaded', async function () {
  55. const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
  56. videoUUID = res.body.video.uuid
  57. await checkHook('action:api.video.uploaded')
  58. })
  59. it('Should run action:api.video.updated', async function () {
  60. await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
  61. await checkHook('action:api.video.updated')
  62. })
  63. it('Should run action:api.video.viewed', async function () {
  64. await viewVideo(servers[0].url, videoUUID)
  65. await checkHook('action:api.video.viewed')
  66. })
  67. })
  68. describe('Comments hooks', function () {
  69. it('Should run action:api.video-thread.created', async function () {
  70. const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
  71. threadId = res.body.comment.id
  72. await checkHook('action:api.video-thread.created')
  73. })
  74. it('Should run action:api.video-comment-reply.created', async function () {
  75. await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply')
  76. await checkHook('action:api.video-comment-reply.created')
  77. })
  78. it('Should run action:api.video-comment.deleted', async function () {
  79. await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
  80. await checkHook('action:api.video-comment.deleted')
  81. })
  82. })
  83. describe('Users hooks', function () {
  84. let userId: number
  85. it('Should run action:api.user.registered', async function () {
  86. await registerUser(servers[0].url, 'registered_user', 'super_password')
  87. await checkHook('action:api.user.registered')
  88. })
  89. it('Should run action:api.user.created', async function () {
  90. const res = await createUser({
  91. url: servers[0].url,
  92. accessToken: servers[0].accessToken,
  93. username: 'created_user',
  94. password: 'super_password'
  95. })
  96. userId = res.body.user.id
  97. await checkHook('action:api.user.created')
  98. })
  99. it('Should run action:api.user.oauth2-got-token', async function () {
  100. await userLogin(servers[0], { username: 'created_user', password: 'super_password' })
  101. await checkHook('action:api.user.oauth2-got-token')
  102. })
  103. it('Should run action:api.user.blocked', async function () {
  104. await blockUser(servers[0].url, userId, servers[0].accessToken)
  105. await checkHook('action:api.user.blocked')
  106. })
  107. it('Should run action:api.user.unblocked', async function () {
  108. await unblockUser(servers[0].url, userId, servers[0].accessToken)
  109. await checkHook('action:api.user.unblocked')
  110. })
  111. it('Should run action:api.user.updated', async function () {
  112. await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 })
  113. await checkHook('action:api.user.updated')
  114. })
  115. it('Should run action:api.user.deleted', async function () {
  116. await removeUser(servers[0].url, userId, servers[0].accessToken)
  117. await checkHook('action:api.user.deleted')
  118. })
  119. })
  120. after(async function () {
  121. await cleanupTests(servers)
  122. })
  123. })