1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 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) {
21 return servers[0].servers.waitUntilLog('Run hook ' + hook)
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({
42 describe('Application hooks', function () {
43 it('Should run action:application.listening', async function () {
44 await checkHook('action:application.listening')
48 describe('Videos hooks', function () {
50 it('Should run action:api.video.uploaded', async function () {
51 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } })
54 await checkHook('action:api.video.uploaded')
57 it('Should run action:api.video.updated', async function () {
58 await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video updated' } })
60 await checkHook('action:api.video.updated')
63 it('Should run action:api.video.viewed', async function () {
64 await servers[0].views.simulateView({ id: videoUUID })
66 await checkHook('action:api.video.viewed')
69 it('Should run action:api.video.deleted', async function () {
70 await servers[0].videos.remove({ id: videoUUID })
72 await checkHook('action:api.video.deleted')
75 after(async function () {
76 const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
81 describe('Video channel hooks', function () {
82 const channelName = 'my_super_channel'
84 it('Should run action:api.video-channel.created', async function () {
85 await servers[0].channels.create({ attributes: { name: channelName } })
87 await checkHook('action:api.video-channel.created')
90 it('Should run action:api.video-channel.updated', async function () {
91 await servers[0].channels.update({ channelName, attributes: { displayName: 'my display name' } })
93 await checkHook('action:api.video-channel.updated')
96 it('Should run action:api.video-channel.deleted', async function () {
97 await servers[0].channels.delete({ channelName })
99 await checkHook('action:api.video-channel.deleted')
103 describe('Live hooks', function () {
105 it('Should run action:api.live-video.created', async function () {
108 privacy: VideoPrivacy.PUBLIC,
109 channelId: servers[0].store.channel.id
112 await servers[0].live.create({ fields: attributes })
114 await checkHook('action:api.live-video.created')
118 describe('Comments hooks', function () {
119 it('Should run action:api.video-thread.created', async function () {
120 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
121 threadId = created.id
123 await checkHook('action:api.video-thread.created')
126 it('Should run action:api.video-comment-reply.created', async function () {
127 await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
129 await checkHook('action:api.video-comment-reply.created')
132 it('Should run action:api.video-comment.deleted', async function () {
133 await servers[0].comments.delete({ videoId: videoUUID, commentId: threadId })
135 await checkHook('action:api.video-comment.deleted')
139 describe('Captions hooks', function () {
140 it('Should run action:api.video-caption.created', async function () {
141 await servers[0].captions.add({ videoId: videoUUID, language: 'en', fixture: 'subtitle-good.srt' })
143 await checkHook('action:api.video-caption.created')
146 it('Should run action:api.video-caption.deleted', async function () {
147 await servers[0].captions.delete({ videoId: videoUUID, language: 'en' })
149 await checkHook('action:api.video-caption.deleted')
153 describe('Users hooks', function () {
156 it('Should run action:api.user.registered', async function () {
157 await servers[0].users.register({ username: 'registered_user' })
159 await checkHook('action:api.user.registered')
162 it('Should run action:api.user.created', async function () {
163 const user = await servers[0].users.create({ username: 'created_user' })
166 await checkHook('action:api.user.created')
169 it('Should run action:api.user.oauth2-got-token', async function () {
170 await servers[0].login.login({ user: { username: 'created_user' } })
172 await checkHook('action:api.user.oauth2-got-token')
175 it('Should run action:api.user.blocked', async function () {
176 await servers[0].users.banUser({ userId })
178 await checkHook('action:api.user.blocked')
181 it('Should run action:api.user.unblocked', async function () {
182 await servers[0].users.unbanUser({ userId })
184 await checkHook('action:api.user.unblocked')
187 it('Should run action:api.user.updated', async function () {
188 await servers[0].users.update({ userId, videoQuota: 50 })
190 await checkHook('action:api.user.updated')
193 it('Should run action:api.user.deleted', async function () {
194 await servers[0].users.remove({ userId })
196 await checkHook('action:api.user.deleted')
200 describe('Playlist hooks', function () {
201 let playlistId: number
204 before(async function () {
206 const { id } = await servers[0].playlists.create({
208 displayName: 'My playlist',
209 privacy: VideoPlaylistPrivacy.PRIVATE
216 const { id } = await servers[0].videos.upload({ attributes: { name: 'my super name' } })
221 it('Should run action:api.video-playlist-element.created', async function () {
222 await servers[0].playlists.addElement({ playlistId, attributes: { videoId } })
224 await checkHook('action:api.video-playlist-element.created')
228 after(async function () {
229 await cleanupTests(servers)