1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultVideoChannel
13 } from '@shared/server-commands'
15 describe('Test plugin action hooks', function () {
16 let servers: PeerTubeServer[]
20 function checkHook (hook: ServerHookName, strictCount = true) {
21 return servers[0].servers.waitUntilLog('Run hook ' + hook, 1, strictCount)
24 before(async function () {
27 servers = await createMultipleServers(2)
28 await setAccessTokensToServers(servers)
29 await setDefaultVideoChannel(servers)
31 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() })
33 await killallServers([ servers[0] ])
35 await servers[0].run({
41 await doubleFollow(servers[0], servers[1])
44 describe('Application hooks', function () {
45 it('Should run action:application.listening', async function () {
46 await checkHook('action:application.listening')
50 describe('Videos hooks', function () {
52 it('Should run action:api.video.uploaded', async function () {
53 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } })
56 await checkHook('action:api.video.uploaded')
59 it('Should run action:api.video.updated', async function () {
60 await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video updated' } })
62 await checkHook('action:api.video.updated')
65 it('Should run action:api.video.viewed', async function () {
66 await servers[0].views.simulateView({ id: videoUUID })
68 await checkHook('action:api.video.viewed')
71 it('Should run action:api.video.deleted', async function () {
72 await servers[0].videos.remove({ id: videoUUID })
74 await checkHook('action:api.video.deleted')
77 after(async function () {
78 const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
83 describe('Video channel hooks', function () {
84 const channelName = 'my_super_channel'
86 it('Should run action:api.video-channel.created', async function () {
87 await servers[0].channels.create({ attributes: { name: channelName } })
89 await checkHook('action:api.video-channel.created')
92 it('Should run action:api.video-channel.updated', async function () {
93 await servers[0].channels.update({ channelName, attributes: { displayName: 'my display name' } })
95 await checkHook('action:api.video-channel.updated')
98 it('Should run action:api.video-channel.deleted', async function () {
99 await servers[0].channels.delete({ channelName })
101 await checkHook('action:api.video-channel.deleted')
105 describe('Live hooks', function () {
107 it('Should run action:api.live-video.created', async function () {
110 privacy: VideoPrivacy.PUBLIC,
111 channelId: servers[0].store.channel.id
114 await servers[0].live.create({ fields: attributes })
116 await checkHook('action:api.live-video.created')
120 describe('Comments hooks', function () {
121 it('Should run action:api.video-thread.created', async function () {
122 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
123 threadId = created.id
125 await checkHook('action:api.video-thread.created')
128 it('Should run action:api.video-comment-reply.created', async function () {
129 await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
131 await checkHook('action:api.video-comment-reply.created')
134 it('Should run action:api.video-comment.deleted', async function () {
135 await servers[0].comments.delete({ videoId: videoUUID, commentId: threadId })
137 await checkHook('action:api.video-comment.deleted')
141 describe('Captions hooks', function () {
142 it('Should run action:api.video-caption.created', async function () {
143 await servers[0].captions.add({ videoId: videoUUID, language: 'en', fixture: 'subtitle-good.srt' })
145 await checkHook('action:api.video-caption.created')
148 it('Should run action:api.video-caption.deleted', async function () {
149 await servers[0].captions.delete({ videoId: videoUUID, language: 'en' })
151 await checkHook('action:api.video-caption.deleted')
155 describe('Users hooks', function () {
158 it('Should run action:api.user.registered', async function () {
159 await servers[0].registrations.register({ username: 'registered_user' })
161 await checkHook('action:api.user.registered')
164 it('Should run action:api.user.created', async function () {
165 const user = await servers[0].users.create({ username: 'created_user' })
168 await checkHook('action:api.user.created')
171 it('Should run action:api.user.oauth2-got-token', async function () {
172 await servers[0].login.login({ user: { username: 'created_user' } })
174 await checkHook('action:api.user.oauth2-got-token')
177 it('Should run action:api.user.blocked', async function () {
178 await servers[0].users.banUser({ userId })
180 await checkHook('action:api.user.blocked')
183 it('Should run action:api.user.unblocked', async function () {
184 await servers[0].users.unbanUser({ userId })
186 await checkHook('action:api.user.unblocked')
189 it('Should run action:api.user.updated', async function () {
190 await servers[0].users.update({ userId, videoQuota: 50 })
192 await checkHook('action:api.user.updated')
195 it('Should run action:api.user.deleted', async function () {
196 await servers[0].users.remove({ userId })
198 await checkHook('action:api.user.deleted')
202 describe('Playlist hooks', function () {
203 let playlistId: number
206 before(async function () {
208 const { id } = await servers[0].playlists.create({
210 displayName: 'My playlist',
211 privacy: VideoPlaylistPrivacy.PRIVATE
218 const { id } = await servers[0].videos.upload({ attributes: { name: 'my super name' } })
223 it('Should run action:api.video-playlist-element.created', async function () {
224 await servers[0].playlists.addElement({ playlistId, attributes: { videoId } })
226 await checkHook('action:api.video-playlist-element.created')
230 describe('Notification hook', function () {
232 it('Should run action:notifier.notification.created', async function () {
233 await checkHook('action:notifier.notification.created', false)
237 describe('Activity Pub hooks', function () {
238 let videoUUID: string
240 it('Should run action:activity-pub.remote-video.created', async function () {
243 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
246 await servers[0].servers.waitUntilLog('action:activity-pub.remote-video.created - AP remote video - video remote video')
249 it('Should run action:activity-pub.remote-video.updated', async function () {
252 await servers[1].videos.update({ id: videoUUID, attributes: { name: 'remote video updated' } })
254 await servers[0].servers.waitUntilLog(
255 'action:activity-pub.remote-video.updated - AP remote video updated - video remote video updated',
262 after(async function () {
263 await cleanupTests(servers)