1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
15 } from '@shared/server-commands'
17 describe('Test plugin action hooks', function () {
18 let servers: PeerTubeServer[]
22 function checkHook (hook: ServerHookName, strictCount = true, count = 1) {
23 return servers[0].servers.waitUntilLog('Run hook ' + hook, count, strictCount)
26 before(async function () {
29 servers = await createMultipleServers(2)
30 await setAccessTokensToServers(servers)
31 await setDefaultVideoChannel(servers)
33 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() })
35 await killallServers([ servers[0] ])
37 await servers[0].run({
43 await doubleFollow(servers[0], servers[1])
46 describe('Application hooks', function () {
47 it('Should run action:application.listening', async function () {
48 await checkHook('action:application.listening')
52 describe('Videos hooks', function () {
54 it('Should run action:api.video.uploaded', async function () {
55 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } })
58 await checkHook('action:api.video.uploaded')
61 it('Should run action:api.video.updated', async function () {
62 await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video updated' } })
64 await checkHook('action:api.video.updated')
67 it('Should run action:api.video.viewed', async function () {
68 await servers[0].views.simulateView({ id: videoUUID })
70 await checkHook('action:api.video.viewed')
73 it('Should run action:api.video.deleted', async function () {
74 await servers[0].videos.remove({ id: videoUUID })
76 await checkHook('action:api.video.deleted')
79 after(async function () {
80 const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
85 describe('Video channel hooks', function () {
86 const channelName = 'my_super_channel'
88 it('Should run action:api.video-channel.created', async function () {
89 await servers[0].channels.create({ attributes: { name: channelName } })
91 await checkHook('action:api.video-channel.created')
94 it('Should run action:api.video-channel.updated', async function () {
95 await servers[0].channels.update({ channelName, attributes: { displayName: 'my display name' } })
97 await checkHook('action:api.video-channel.updated')
100 it('Should run action:api.video-channel.deleted', async function () {
101 await servers[0].channels.delete({ channelName })
103 await checkHook('action:api.video-channel.deleted')
107 describe('Live hooks', function () {
109 it('Should run action:api.live-video.created', async function () {
112 privacy: VideoPrivacy.PUBLIC,
113 channelId: servers[0].store.channel.id
116 await servers[0].live.create({ fields: attributes })
118 await checkHook('action:api.live-video.created')
121 it('Should run action:live.video.state.updated', async function () {
126 privacy: VideoPrivacy.PUBLIC,
127 channelId: servers[0].store.channel.id
130 const { uuid: liveVideoId } = await servers[0].live.create({ fields: attributes })
131 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId })
132 await servers[0].live.waitUntilPublished({ videoId: liveVideoId })
133 await waitJobs(servers)
135 await checkHook('action:live.video.state.updated', true, 1)
137 await stopFfmpeg(ffmpegCommand)
138 await servers[0].live.waitUntilEnded({ videoId: liveVideoId })
139 await waitJobs(servers)
141 await checkHook('action:live.video.state.updated', true, 2)
145 describe('Comments hooks', function () {
146 it('Should run action:api.video-thread.created', async function () {
147 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
148 threadId = created.id
150 await checkHook('action:api.video-thread.created')
153 it('Should run action:api.video-comment-reply.created', async function () {
154 await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
156 await checkHook('action:api.video-comment-reply.created')
159 it('Should run action:api.video-comment.deleted', async function () {
160 await servers[0].comments.delete({ videoId: videoUUID, commentId: threadId })
162 await checkHook('action:api.video-comment.deleted')
166 describe('Captions hooks', function () {
167 it('Should run action:api.video-caption.created', async function () {
168 await servers[0].captions.add({ videoId: videoUUID, language: 'en', fixture: 'subtitle-good.srt' })
170 await checkHook('action:api.video-caption.created')
173 it('Should run action:api.video-caption.deleted', async function () {
174 await servers[0].captions.delete({ videoId: videoUUID, language: 'en' })
176 await checkHook('action:api.video-caption.deleted')
180 describe('Users hooks', function () {
183 it('Should run action:api.user.registered', async function () {
184 await servers[0].registrations.register({ username: 'registered_user' })
186 await checkHook('action:api.user.registered')
189 it('Should run action:api.user.created', async function () {
190 const user = await servers[0].users.create({ username: 'created_user' })
193 await checkHook('action:api.user.created')
196 it('Should run action:api.user.oauth2-got-token', async function () {
197 await servers[0].login.login({ user: { username: 'created_user' } })
199 await checkHook('action:api.user.oauth2-got-token')
202 it('Should run action:api.user.blocked', async function () {
203 await servers[0].users.banUser({ userId })
205 await checkHook('action:api.user.blocked')
208 it('Should run action:api.user.unblocked', async function () {
209 await servers[0].users.unbanUser({ userId })
211 await checkHook('action:api.user.unblocked')
214 it('Should run action:api.user.updated', async function () {
215 await servers[0].users.update({ userId, videoQuota: 50 })
217 await checkHook('action:api.user.updated')
220 it('Should run action:api.user.deleted', async function () {
221 await servers[0].users.remove({ userId })
223 await checkHook('action:api.user.deleted')
227 describe('Playlist hooks', function () {
228 let playlistId: number
231 before(async function () {
233 const { id } = await servers[0].playlists.create({
235 displayName: 'My playlist',
236 privacy: VideoPlaylistPrivacy.PRIVATE
243 const { id } = await servers[0].videos.upload({ attributes: { name: 'my super name' } })
248 it('Should run action:api.video-playlist-element.created', async function () {
249 await servers[0].playlists.addElement({ playlistId, attributes: { videoId } })
251 await checkHook('action:api.video-playlist-element.created')
255 describe('Notification hook', function () {
257 it('Should run action:notifier.notification.created', async function () {
258 await checkHook('action:notifier.notification.created', false)
262 describe('Activity Pub hooks', function () {
263 let videoUUID: string
265 it('Should run action:activity-pub.remote-video.created', async function () {
268 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
271 await servers[0].servers.waitUntilLog('action:activity-pub.remote-video.created - AP remote video - video remote video')
274 it('Should run action:activity-pub.remote-video.updated', async function () {
277 await servers[1].videos.update({ id: videoUUID, attributes: { name: 'remote video updated' } })
279 await servers[0].servers.waitUntilLog(
280 'action:activity-pub.remote-video.updated - AP remote video updated - video remote video updated',
287 after(async function () {
288 await cleanupTests(servers)