1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
7 flushAndRunMultipleServers,
12 } from '../../../shared/extra-utils/server/servers'
15 addVideoCommentThread,
21 registerUser, removeUser,
22 setAccessTokensToServers,
23 unblockUser, updateUser,
28 } from '../../../shared/extra-utils'
30 const expect = chai.expect
32 describe('Test plugin action hooks', function () {
33 let servers: ServerInfo[]
37 function checkHook (hook: string) {
38 return waitUntilLog(servers[0], 'Run hook ' + hook)
41 before(async function () {
44 servers = await flushAndRunMultipleServers(2)
45 await setAccessTokensToServers(servers)
49 accessToken: servers[0].accessToken,
50 path: getPluginTestPath()
53 killallServers([ servers[0] ])
55 await reRunServer(servers[0])
58 describe('Application hooks', function () {
59 it('Should run action:application.listening', async function () {
60 await checkHook('action:application.listening')
64 describe('Videos hooks', function () {
65 it('Should run action:api.video.uploaded', async function () {
66 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
67 videoUUID = res.body.video.uuid
69 await checkHook('action:api.video.uploaded')
72 it('Should run action:api.video.updated', async function () {
73 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
75 await checkHook('action:api.video.updated')
78 it('Should run action:api.video.viewed', async function () {
79 await viewVideo(servers[0].url, videoUUID)
81 await checkHook('action:api.video.viewed')
85 describe('Comments hooks', function () {
86 it('Should run action:api.video-thread.created', async function () {
87 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
88 threadId = res.body.comment.id
90 await checkHook('action:api.video-thread.created')
93 it('Should run action:api.video-comment-reply.created', async function () {
94 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply')
96 await checkHook('action:api.video-comment-reply.created')
99 it('Should run action:api.video-comment.deleted', async function () {
100 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
102 await checkHook('action:api.video-comment.deleted')
106 describe('Users hooks', function () {
109 it('Should run action:api.user.registered', async function () {
110 await registerUser(servers[0].url, 'registered_user', 'super_password')
112 await checkHook('action:api.user.registered')
115 it('Should run action:api.user.created', async function () {
116 const res = await createUser({
118 accessToken: servers[0].accessToken,
119 username: 'created_user',
120 password: 'super_password'
122 userId = res.body.user.id
124 await checkHook('action:api.user.created')
127 it('Should run action:api.user.oauth2-got-token', async function () {
128 await userLogin(servers[0], { username: 'created_user', password: 'super_password' })
130 await checkHook('action:api.user.oauth2-got-token')
133 it('Should run action:api.user.blocked', async function () {
134 await blockUser(servers[0].url, userId, servers[0].accessToken)
136 await checkHook('action:api.user.blocked')
139 it('Should run action:api.user.unblocked', async function () {
140 await unblockUser(servers[0].url, userId, servers[0].accessToken)
142 await checkHook('action:api.user.unblocked')
145 it('Should run action:api.user.updated', async function () {
146 await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 })
148 await checkHook('action:api.user.updated')
151 it('Should run action:api.user.deleted', async function () {
152 await removeUser(servers[0].url, userId, servers[0].accessToken)
154 await checkHook('action:api.user.deleted')
158 after(async function () {
159 await cleanupTests(servers)