1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
10 setAccessTokensToServers,
11 setDefaultVideoChannel
12 } from '@shared/server-commands'
14 describe('Test plugin action hooks', function () {
15 let servers: PeerTubeServer[]
19 function checkHook (hook: ServerHookName, strictCount = true) {
20 return servers[0].servers.waitUntilLog('Run hook ' + hook, 1, strictCount)
23 before(async function () {
26 servers = await createMultipleServers(2)
27 await setAccessTokensToServers(servers)
28 await setDefaultVideoChannel(servers)
30 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() })
32 await killallServers([ servers[0] ])
34 await servers[0].run({
41 describe('Application hooks', function () {
42 it('Should run action:application.listening', async function () {
43 await checkHook('action:application.listening')
47 describe('Videos hooks', function () {
49 it('Should run action:api.video.uploaded', async function () {
50 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } })
53 await checkHook('action:api.video.uploaded')
56 it('Should run action:api.video.updated', async function () {
57 await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video updated' } })
59 await checkHook('action:api.video.updated')
62 it('Should run action:api.video.viewed', async function () {
63 await servers[0].views.simulateView({ id: videoUUID })
65 await checkHook('action:api.video.viewed')
68 it('Should run action:api.video.deleted', async function () {
69 await servers[0].videos.remove({ id: videoUUID })
71 await checkHook('action:api.video.deleted')
74 after(async function () {
75 const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
80 describe('Video channel hooks', function () {
81 const channelName = 'my_super_channel'
83 it('Should run action:api.video-channel.created', async function () {
84 await servers[0].channels.create({ attributes: { name: channelName } })
86 await checkHook('action:api.video-channel.created')
89 it('Should run action:api.video-channel.updated', async function () {
90 await servers[0].channels.update({ channelName, attributes: { displayName: 'my display name' } })
92 await checkHook('action:api.video-channel.updated')
95 it('Should run action:api.video-channel.deleted', async function () {
96 await servers[0].channels.delete({ channelName })
98 await checkHook('action:api.video-channel.deleted')
102 describe('Live hooks', function () {
104 it('Should run action:api.live-video.created', async function () {
107 privacy: VideoPrivacy.PUBLIC,
108 channelId: servers[0].store.channel.id
111 await servers[0].live.create({ fields: attributes })
113 await checkHook('action:api.live-video.created')
117 describe('Comments hooks', function () {
118 it('Should run action:api.video-thread.created', async function () {
119 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
120 threadId = created.id
122 await checkHook('action:api.video-thread.created')
125 it('Should run action:api.video-comment-reply.created', async function () {
126 await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
128 await checkHook('action:api.video-comment-reply.created')
131 it('Should run action:api.video-comment.deleted', async function () {
132 await servers[0].comments.delete({ videoId: videoUUID, commentId: threadId })
134 await checkHook('action:api.video-comment.deleted')
138 describe('Captions hooks', function () {
139 it('Should run action:api.video-caption.created', async function () {
140 await servers[0].captions.add({ videoId: videoUUID, language: 'en', fixture: 'subtitle-good.srt' })
142 await checkHook('action:api.video-caption.created')
145 it('Should run action:api.video-caption.deleted', async function () {
146 await servers[0].captions.delete({ videoId: videoUUID, language: 'en' })
148 await checkHook('action:api.video-caption.deleted')
152 describe('Users hooks', function () {
155 it('Should run action:api.user.registered', async function () {
156 await servers[0].registrations.register({ username: 'registered_user' })
158 await checkHook('action:api.user.registered')
161 it('Should run action:api.user.created', async function () {
162 const user = await servers[0].users.create({ username: 'created_user' })
165 await checkHook('action:api.user.created')
168 it('Should run action:api.user.oauth2-got-token', async function () {
169 await servers[0].login.login({ user: { username: 'created_user' } })
171 await checkHook('action:api.user.oauth2-got-token')
174 it('Should run action:api.user.blocked', async function () {
175 await servers[0].users.banUser({ userId })
177 await checkHook('action:api.user.blocked')
180 it('Should run action:api.user.unblocked', async function () {
181 await servers[0].users.unbanUser({ userId })
183 await checkHook('action:api.user.unblocked')
186 it('Should run action:api.user.updated', async function () {
187 await servers[0].users.update({ userId, videoQuota: 50 })
189 await checkHook('action:api.user.updated')
192 it('Should run action:api.user.deleted', async function () {
193 await servers[0].users.remove({ userId })
195 await checkHook('action:api.user.deleted')
199 describe('Playlist hooks', function () {
200 let playlistId: number
203 before(async function () {
205 const { id } = await servers[0].playlists.create({
207 displayName: 'My playlist',
208 privacy: VideoPlaylistPrivacy.PRIVATE
215 const { id } = await servers[0].videos.upload({ attributes: { name: 'my super name' } })
220 it('Should run action:api.video-playlist-element.created', async function () {
221 await servers[0].playlists.addElement({ playlistId, attributes: { videoId } })
223 await checkHook('action:api.video-playlist-element.created')
227 describe('Notification hook', function () {
229 it('Should run action:notifier.notification.created', async function () {
230 await checkHook('action:notifier.notification.created', false)
234 after(async function () {
235 await cleanupTests(servers)