1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { ServerHookName, VideoPrivacy } from '@shared/models'
16 setAccessTokensToServers,
17 setDefaultVideoChannel,
24 } from '../../../shared/extra-utils'
27 flushAndRunMultipleServers,
32 } from '../../../shared/extra-utils/server/servers'
34 describe('Test plugin action hooks', function () {
35 let servers: ServerInfo[]
39 function checkHook (hook: ServerHookName) {
40 return waitUntilLog(servers[0], 'Run hook ' + hook)
43 before(async function () {
46 servers = await flushAndRunMultipleServers(2)
47 await setAccessTokensToServers(servers)
48 await setDefaultVideoChannel(servers)
52 accessToken: servers[0].accessToken,
53 path: getPluginTestPath()
56 killallServers([ servers[0] ])
58 await reRunServer(servers[0], {
65 describe('Application hooks', function () {
66 it('Should run action:application.listening', async function () {
67 await checkHook('action:application.listening')
71 describe('Videos hooks', function () {
72 it('Should run action:api.video.uploaded', async function () {
73 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
74 videoUUID = res.body.video.uuid
76 await checkHook('action:api.video.uploaded')
79 it('Should run action:api.video.updated', async function () {
80 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
82 await checkHook('action:api.video.updated')
85 it('Should run action:api.video.viewed', async function () {
86 await viewVideo(servers[0].url, videoUUID)
88 await checkHook('action:api.video.viewed')
92 describe('Live hooks', function () {
94 it('Should run action:api.live-video.created', async function () {
97 privacy: VideoPrivacy.PUBLIC,
98 channelId: servers[0].videoChannel.id
101 await createLive(servers[0].url, servers[0].accessToken, attributes)
103 await checkHook('action:api.live-video.created')
107 describe('Comments hooks', function () {
108 it('Should run action:api.video-thread.created', async function () {
109 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
110 threadId = res.body.comment.id
112 await checkHook('action:api.video-thread.created')
115 it('Should run action:api.video-comment-reply.created', async function () {
116 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply')
118 await checkHook('action:api.video-comment-reply.created')
121 it('Should run action:api.video-comment.deleted', async function () {
122 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
124 await checkHook('action:api.video-comment.deleted')
128 describe('Users hooks', function () {
131 it('Should run action:api.user.registered', async function () {
132 await registerUser(servers[0].url, 'registered_user', 'super_password')
134 await checkHook('action:api.user.registered')
137 it('Should run action:api.user.created', async function () {
138 const res = await createUser({
140 accessToken: servers[0].accessToken,
141 username: 'created_user',
142 password: 'super_password'
144 userId = res.body.user.id
146 await checkHook('action:api.user.created')
149 it('Should run action:api.user.oauth2-got-token', async function () {
150 await userLogin(servers[0], { username: 'created_user', password: 'super_password' })
152 await checkHook('action:api.user.oauth2-got-token')
155 it('Should run action:api.user.blocked', async function () {
156 await blockUser(servers[0].url, userId, servers[0].accessToken)
158 await checkHook('action:api.user.blocked')
161 it('Should run action:api.user.unblocked', async function () {
162 await unblockUser(servers[0].url, userId, servers[0].accessToken)
164 await checkHook('action:api.user.unblocked')
167 it('Should run action:api.user.updated', async function () {
168 await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 })
170 await checkHook('action:api.user.updated')
173 it('Should run action:api.user.deleted', async function () {
174 await removeUser(servers[0].url, userId, servers[0].accessToken)
176 await checkHook('action:api.user.deleted')
180 after(async function () {
181 await cleanupTests(servers)