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')
70 describe('Live hooks', function () {
72 it('Should run action:api.live-video.created', async function () {
75 privacy: VideoPrivacy.PUBLIC,
76 channelId: servers[0].store.channel.id
79 await servers[0].live.create({ fields: attributes })
81 await checkHook('action:api.live-video.created')
85 describe('Comments hooks', function () {
86 it('Should run action:api.video-thread.created', async function () {
87 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
90 await checkHook('action:api.video-thread.created')
93 it('Should run action:api.video-comment-reply.created', async function () {
94 await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
96 await checkHook('action:api.video-comment-reply.created')
99 it('Should run action:api.video-comment.deleted', async function () {
100 await servers[0].comments.delete({ videoId: videoUUID, commentId: threadId })
102 await checkHook('action:api.video-comment.deleted')
106 describe('Captions hooks', function () {
107 it('Should run action:api.video-caption.created', async function () {
108 await servers[0].captions.add({ videoId: videoUUID, language: 'en', fixture: 'subtitle-good.srt' })
110 await checkHook('action:api.video-caption.created')
113 it('Should run action:api.video-caption.deleted', async function () {
114 await servers[0].captions.delete({ videoId: videoUUID, language: 'en' })
116 await checkHook('action:api.video-caption.deleted')
120 describe('Users hooks', function () {
123 it('Should run action:api.user.registered', async function () {
124 await servers[0].users.register({ username: 'registered_user' })
126 await checkHook('action:api.user.registered')
129 it('Should run action:api.user.created', async function () {
130 const user = await servers[0].users.create({ username: 'created_user' })
133 await checkHook('action:api.user.created')
136 it('Should run action:api.user.oauth2-got-token', async function () {
137 await servers[0].login.login({ user: { username: 'created_user' } })
139 await checkHook('action:api.user.oauth2-got-token')
142 it('Should run action:api.user.blocked', async function () {
143 await servers[0].users.banUser({ userId })
145 await checkHook('action:api.user.blocked')
148 it('Should run action:api.user.unblocked', async function () {
149 await servers[0].users.unbanUser({ userId })
151 await checkHook('action:api.user.unblocked')
154 it('Should run action:api.user.updated', async function () {
155 await servers[0].users.update({ userId, videoQuota: 50 })
157 await checkHook('action:api.user.updated')
160 it('Should run action:api.user.deleted', async function () {
161 await servers[0].users.remove({ userId })
163 await checkHook('action:api.user.deleted')
167 describe('Playlist hooks', function () {
168 let playlistId: number
171 before(async function () {
173 const { id } = await servers[0].playlists.create({
175 displayName: 'My playlist',
176 privacy: VideoPlaylistPrivacy.PRIVATE
183 const { id } = await servers[0].videos.upload({ attributes: { name: 'my super name' } })
188 it('Should run action:api.video-playlist-element.created', async function () {
189 await servers[0].playlists.addElement({ playlistId, attributes: { videoId } })
191 await checkHook('action:api.video-playlist-element.created')
195 after(async function () {
196 await cleanupTests(servers)