1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
17 setAccessTokensToServers,
18 setDefaultVideoChannel,
25 } from '../../../shared/extra-utils'
28 flushAndRunMultipleServers,
33 } from '../../../shared/extra-utils/server/servers'
35 describe('Test plugin action hooks', function () {
36 let servers: ServerInfo[]
40 function checkHook (hook: ServerHookName) {
41 return waitUntilLog(servers[0], 'Run hook ' + hook)
44 before(async function () {
47 servers = await flushAndRunMultipleServers(2)
48 await setAccessTokensToServers(servers)
49 await setDefaultVideoChannel(servers)
51 await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() })
53 killallServers([ servers[0] ])
55 await reRunServer(servers[0], {
62 describe('Application hooks', function () {
63 it('Should run action:application.listening', async function () {
64 await checkHook('action:application.listening')
68 describe('Videos hooks', function () {
70 it('Should run action:api.video.uploaded', async function () {
71 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
72 videoUUID = res.body.video.uuid
74 await checkHook('action:api.video.uploaded')
77 it('Should run action:api.video.updated', async function () {
78 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
80 await checkHook('action:api.video.updated')
83 it('Should run action:api.video.viewed', async function () {
84 await viewVideo(servers[0].url, videoUUID)
86 await checkHook('action:api.video.viewed')
90 describe('Live hooks', function () {
92 it('Should run action:api.live-video.created', async function () {
95 privacy: VideoPrivacy.PUBLIC,
96 channelId: servers[0].videoChannel.id
99 await createLive(servers[0].url, servers[0].accessToken, attributes)
101 await checkHook('action:api.live-video.created')
105 describe('Comments hooks', function () {
106 it('Should run action:api.video-thread.created', async function () {
107 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
108 threadId = res.body.comment.id
110 await checkHook('action:api.video-thread.created')
113 it('Should run action:api.video-comment-reply.created', async function () {
114 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply')
116 await checkHook('action:api.video-comment-reply.created')
119 it('Should run action:api.video-comment.deleted', async function () {
120 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
122 await checkHook('action:api.video-comment.deleted')
126 describe('Users hooks', function () {
129 it('Should run action:api.user.registered', async function () {
130 await registerUser(servers[0].url, 'registered_user', 'super_password')
132 await checkHook('action:api.user.registered')
135 it('Should run action:api.user.created', async function () {
136 const res = await createUser({
138 accessToken: servers[0].accessToken,
139 username: 'created_user',
140 password: 'super_password'
142 userId = res.body.user.id
144 await checkHook('action:api.user.created')
147 it('Should run action:api.user.oauth2-got-token', async function () {
148 await userLogin(servers[0], { username: 'created_user', password: 'super_password' })
150 await checkHook('action:api.user.oauth2-got-token')
153 it('Should run action:api.user.blocked', async function () {
154 await blockUser(servers[0].url, userId, servers[0].accessToken)
156 await checkHook('action:api.user.blocked')
159 it('Should run action:api.user.unblocked', async function () {
160 await unblockUser(servers[0].url, userId, servers[0].accessToken)
162 await checkHook('action:api.user.unblocked')
165 it('Should run action:api.user.updated', async function () {
166 await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 })
168 await checkHook('action:api.user.updated')
171 it('Should run action:api.user.deleted', async function () {
172 await removeUser(servers[0].url, userId, servers[0].accessToken)
174 await checkHook('action:api.user.deleted')
178 describe('Playlist hooks', function () {
179 let playlistId: number
182 before(async function () {
184 const res = await createVideoPlaylist({
186 token: servers[0].accessToken,
188 displayName: 'My playlist',
189 privacy: VideoPlaylistPrivacy.PRIVATE
192 playlistId = res.body.videoPlaylist.id
196 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' })
197 videoId = res.body.video.id
201 it('Should run action:api.video-playlist-element.created', async function () {
202 await addVideoInPlaylist({
204 token: servers[0].accessToken,
206 elementAttrs: { videoId }
209 await checkHook('action:api.video-playlist-element.created')
213 after(async function () {
214 await cleanupTests(servers)