1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
6 flushAndRunMultipleServers,
11 } from '../../../shared/extra-utils/server/servers'
14 addVideoCommentThread,
22 setAccessTokensToServers,
29 } from '../../../shared/extra-utils'
31 describe('Test plugin action hooks', function () {
32 let servers: ServerInfo[]
36 function checkHook (hook: string) {
37 return waitUntilLog(servers[0], 'Run hook ' + hook)
40 before(async function () {
43 servers = await flushAndRunMultipleServers(2)
44 await setAccessTokensToServers(servers)
48 accessToken: servers[0].accessToken,
49 path: getPluginTestPath()
52 killallServers([ servers[0] ])
54 await reRunServer(servers[0])
57 describe('Application hooks', function () {
58 it('Should run action:application.listening', async function () {
59 await checkHook('action:application.listening')
63 describe('Videos hooks', function () {
64 it('Should run action:api.video.uploaded', async function () {
65 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
66 videoUUID = res.body.video.uuid
68 await checkHook('action:api.video.uploaded')
71 it('Should run action:api.video.updated', async function () {
72 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
74 await checkHook('action:api.video.updated')
77 it('Should run action:api.video.viewed', async function () {
78 await viewVideo(servers[0].url, videoUUID)
80 await checkHook('action:api.video.viewed')
84 describe('Comments hooks', function () {
85 it('Should run action:api.video-thread.created', async function () {
86 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
87 threadId = res.body.comment.id
89 await checkHook('action:api.video-thread.created')
92 it('Should run action:api.video-comment-reply.created', async function () {
93 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply')
95 await checkHook('action:api.video-comment-reply.created')
98 it('Should run action:api.video-comment.deleted', async function () {
99 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
101 await checkHook('action:api.video-comment.deleted')
105 describe('Users hooks', function () {
108 it('Should run action:api.user.registered', async function () {
109 await registerUser(servers[0].url, 'registered_user', 'super_password')
111 await checkHook('action:api.user.registered')
114 it('Should run action:api.user.created', async function () {
115 const res = await createUser({
117 accessToken: servers[0].accessToken,
118 username: 'created_user',
119 password: 'super_password'
121 userId = res.body.user.id
123 await checkHook('action:api.user.created')
126 it('Should run action:api.user.oauth2-got-token', async function () {
127 await userLogin(servers[0], { username: 'created_user', password: 'super_password' })
129 await checkHook('action:api.user.oauth2-got-token')
132 it('Should run action:api.user.blocked', async function () {
133 await blockUser(servers[0].url, userId, servers[0].accessToken)
135 await checkHook('action:api.user.blocked')
138 it('Should run action:api.user.unblocked', async function () {
139 await unblockUser(servers[0].url, userId, servers[0].accessToken)
141 await checkHook('action:api.user.unblocked')
144 it('Should run action:api.user.updated', async function () {
145 await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 })
147 await checkHook('action:api.user.updated')
150 it('Should run action:api.user.deleted', async function () {
151 await removeUser(servers[0].url, userId, servers[0].accessToken)
153 await checkHook('action:api.user.deleted')
157 after(async function () {
158 await cleanupTests(servers)