1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { ServerHookName, VideoPlaylistPrivacy, 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)
50 await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() })
52 killallServers([ servers[0] ])
54 await reRunServer(servers[0], {
61 describe('Application hooks', function () {
62 it('Should run action:application.listening', async function () {
63 await checkHook('action:application.listening')
67 describe('Videos hooks', function () {
69 it('Should run action:api.video.uploaded', async function () {
70 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
71 videoUUID = res.body.video.uuid
73 await checkHook('action:api.video.uploaded')
76 it('Should run action:api.video.updated', async function () {
77 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
79 await checkHook('action:api.video.updated')
82 it('Should run action:api.video.viewed', async function () {
83 await viewVideo(servers[0].url, videoUUID)
85 await checkHook('action:api.video.viewed')
89 describe('Live hooks', function () {
91 it('Should run action:api.live-video.created', async function () {
94 privacy: VideoPrivacy.PUBLIC,
95 channelId: servers[0].videoChannel.id
98 await servers[0].liveCommand.createLive({ fields: attributes })
100 await checkHook('action:api.live-video.created')
104 describe('Comments hooks', function () {
105 it('Should run action:api.video-thread.created', async function () {
106 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
107 threadId = res.body.comment.id
109 await checkHook('action:api.video-thread.created')
112 it('Should run action:api.video-comment-reply.created', async function () {
113 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply')
115 await checkHook('action:api.video-comment-reply.created')
118 it('Should run action:api.video-comment.deleted', async function () {
119 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
121 await checkHook('action:api.video-comment.deleted')
125 describe('Users hooks', function () {
128 it('Should run action:api.user.registered', async function () {
129 await registerUser(servers[0].url, 'registered_user', 'super_password')
131 await checkHook('action:api.user.registered')
134 it('Should run action:api.user.created', async function () {
135 const res = await createUser({
137 accessToken: servers[0].accessToken,
138 username: 'created_user',
139 password: 'super_password'
141 userId = res.body.user.id
143 await checkHook('action:api.user.created')
146 it('Should run action:api.user.oauth2-got-token', async function () {
147 await userLogin(servers[0], { username: 'created_user', password: 'super_password' })
149 await checkHook('action:api.user.oauth2-got-token')
152 it('Should run action:api.user.blocked', async function () {
153 await blockUser(servers[0].url, userId, servers[0].accessToken)
155 await checkHook('action:api.user.blocked')
158 it('Should run action:api.user.unblocked', async function () {
159 await unblockUser(servers[0].url, userId, servers[0].accessToken)
161 await checkHook('action:api.user.unblocked')
164 it('Should run action:api.user.updated', async function () {
165 await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 })
167 await checkHook('action:api.user.updated')
170 it('Should run action:api.user.deleted', async function () {
171 await removeUser(servers[0].url, userId, servers[0].accessToken)
173 await checkHook('action:api.user.deleted')
177 describe('Playlist hooks', function () {
178 let playlistId: number
181 before(async function () {
183 const res = await createVideoPlaylist({
185 token: servers[0].accessToken,
187 displayName: 'My playlist',
188 privacy: VideoPlaylistPrivacy.PRIVATE
191 playlistId = res.body.videoPlaylist.id
195 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' })
196 videoId = res.body.video.id
200 it('Should run action:api.video-playlist-element.created', async function () {
201 await addVideoInPlaylist({
203 token: servers[0].accessToken,
205 elementAttrs: { videoId }
208 await checkHook('action:api.video-playlist-element.created')
212 after(async function () {
213 await cleanupTests(servers)