]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/plugins/action-hooks.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / action-hooks.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
4 import {
5 cleanupTests,
6 createMultipleServers,
7 doubleFollow,
8 killallServers,
9 PeerTubeServer,
10 PluginsCommand,
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
13 stopFfmpeg,
14 waitJobs
15 } from '@shared/server-commands'
16
17 describe('Test plugin action hooks', function () {
18 let servers: PeerTubeServer[]
19 let videoUUID: string
20 let threadId: number
21
22 function checkHook (hook: ServerHookName, strictCount = true, count = 1) {
23 return servers[0].servers.waitUntilLog('Run hook ' + hook, count, strictCount)
24 }
25
26 before(async function () {
27 this.timeout(120000)
28
29 servers = await createMultipleServers(2)
30 await setAccessTokensToServers(servers)
31 await setDefaultVideoChannel(servers)
32
33 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() })
34
35 await killallServers([ servers[0] ])
36
37 await servers[0].run({
38 live: {
39 enabled: true
40 }
41 })
42
43 await doubleFollow(servers[0], servers[1])
44 })
45
46 describe('Application hooks', function () {
47 it('Should run action:application.listening', async function () {
48 await checkHook('action:application.listening')
49 })
50 })
51
52 describe('Videos hooks', function () {
53
54 it('Should run action:api.video.uploaded', async function () {
55 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } })
56 videoUUID = uuid
57
58 await checkHook('action:api.video.uploaded')
59 })
60
61 it('Should run action:api.video.updated', async function () {
62 await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video updated' } })
63
64 await checkHook('action:api.video.updated')
65 })
66
67 it('Should run action:api.video.viewed', async function () {
68 await servers[0].views.simulateView({ id: videoUUID })
69
70 await checkHook('action:api.video.viewed')
71 })
72
73 it('Should run action:api.video.deleted', async function () {
74 await servers[0].videos.remove({ id: videoUUID })
75
76 await checkHook('action:api.video.deleted')
77 })
78
79 after(async function () {
80 const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
81 videoUUID = uuid
82 })
83 })
84
85 describe('Video channel hooks', function () {
86 const channelName = 'my_super_channel'
87
88 it('Should run action:api.video-channel.created', async function () {
89 await servers[0].channels.create({ attributes: { name: channelName } })
90
91 await checkHook('action:api.video-channel.created')
92 })
93
94 it('Should run action:api.video-channel.updated', async function () {
95 await servers[0].channels.update({ channelName, attributes: { displayName: 'my display name' } })
96
97 await checkHook('action:api.video-channel.updated')
98 })
99
100 it('Should run action:api.video-channel.deleted', async function () {
101 await servers[0].channels.delete({ channelName })
102
103 await checkHook('action:api.video-channel.deleted')
104 })
105 })
106
107 describe('Live hooks', function () {
108
109 it('Should run action:api.live-video.created', async function () {
110 const attributes = {
111 name: 'live',
112 privacy: VideoPrivacy.PUBLIC,
113 channelId: servers[0].store.channel.id
114 }
115
116 await servers[0].live.create({ fields: attributes })
117
118 await checkHook('action:api.live-video.created')
119 })
120
121 it('Should run action:live.video.state.updated', async function () {
122 this.timeout(60000)
123
124 const attributes = {
125 name: 'live',
126 privacy: VideoPrivacy.PUBLIC,
127 channelId: servers[0].store.channel.id
128 }
129
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)
134
135 await checkHook('action:live.video.state.updated', true, 1)
136
137 await stopFfmpeg(ffmpegCommand)
138 await servers[0].live.waitUntilEnded({ videoId: liveVideoId })
139 await waitJobs(servers)
140
141 await checkHook('action:live.video.state.updated', true, 2)
142 })
143 })
144
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
149
150 await checkHook('action:api.video-thread.created')
151 })
152
153 it('Should run action:api.video-comment-reply.created', async function () {
154 await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
155
156 await checkHook('action:api.video-comment-reply.created')
157 })
158
159 it('Should run action:api.video-comment.deleted', async function () {
160 await servers[0].comments.delete({ videoId: videoUUID, commentId: threadId })
161
162 await checkHook('action:api.video-comment.deleted')
163 })
164 })
165
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' })
169
170 await checkHook('action:api.video-caption.created')
171 })
172
173 it('Should run action:api.video-caption.deleted', async function () {
174 await servers[0].captions.delete({ videoId: videoUUID, language: 'en' })
175
176 await checkHook('action:api.video-caption.deleted')
177 })
178 })
179
180 describe('Users hooks', function () {
181 let userId: number
182
183 it('Should run action:api.user.registered', async function () {
184 await servers[0].registrations.register({ username: 'registered_user' })
185
186 await checkHook('action:api.user.registered')
187 })
188
189 it('Should run action:api.user.created', async function () {
190 const user = await servers[0].users.create({ username: 'created_user' })
191 userId = user.id
192
193 await checkHook('action:api.user.created')
194 })
195
196 it('Should run action:api.user.oauth2-got-token', async function () {
197 await servers[0].login.login({ user: { username: 'created_user' } })
198
199 await checkHook('action:api.user.oauth2-got-token')
200 })
201
202 it('Should run action:api.user.blocked', async function () {
203 await servers[0].users.banUser({ userId })
204
205 await checkHook('action:api.user.blocked')
206 })
207
208 it('Should run action:api.user.unblocked', async function () {
209 await servers[0].users.unbanUser({ userId })
210
211 await checkHook('action:api.user.unblocked')
212 })
213
214 it('Should run action:api.user.updated', async function () {
215 await servers[0].users.update({ userId, videoQuota: 50 })
216
217 await checkHook('action:api.user.updated')
218 })
219
220 it('Should run action:api.user.deleted', async function () {
221 await servers[0].users.remove({ userId })
222
223 await checkHook('action:api.user.deleted')
224 })
225 })
226
227 describe('Playlist hooks', function () {
228 let playlistId: number
229 let videoId: number
230
231 before(async function () {
232 {
233 const { id } = await servers[0].playlists.create({
234 attributes: {
235 displayName: 'My playlist',
236 privacy: VideoPlaylistPrivacy.PRIVATE
237 }
238 })
239 playlistId = id
240 }
241
242 {
243 const { id } = await servers[0].videos.upload({ attributes: { name: 'my super name' } })
244 videoId = id
245 }
246 })
247
248 it('Should run action:api.video-playlist-element.created', async function () {
249 await servers[0].playlists.addElement({ playlistId, attributes: { videoId } })
250
251 await checkHook('action:api.video-playlist-element.created')
252 })
253 })
254
255 describe('Notification hook', function () {
256
257 it('Should run action:notifier.notification.created', async function () {
258 await checkHook('action:notifier.notification.created', false)
259 })
260 })
261
262 describe('Activity Pub hooks', function () {
263 let videoUUID: string
264
265 it('Should run action:activity-pub.remote-video.created', async function () {
266 this.timeout(30000)
267
268 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
269 videoUUID = uuid
270
271 await servers[0].servers.waitUntilLog('action:activity-pub.remote-video.created - AP remote video - video remote video')
272 })
273
274 it('Should run action:activity-pub.remote-video.updated', async function () {
275 this.timeout(30000)
276
277 await servers[1].videos.update({ id: videoUUID, attributes: { name: 'remote video updated' } })
278
279 await servers[0].servers.waitUntilLog(
280 'action:activity-pub.remote-video.updated - AP remote video updated - video remote video updated',
281 1,
282 false
283 )
284 })
285 })
286
287 after(async function () {
288 await cleanupTests(servers)
289 })
290 })