]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/plugins/action-hooks.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / action-hooks.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
9b474844 2
b2111066 3import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
89cd1275 4import {
7926c5f9 5 cleanupTests,
254d3579 6 createMultipleServers,
c3441b03 7 doubleFollow,
7926c5f9 8 killallServers,
254d3579 9 PeerTubeServer,
ae2abfd3 10 PluginsCommand,
89cd1275 11 setAccessTokensToServers,
cb0eda56
AG
12 setDefaultVideoChannel,
13 stopFfmpeg,
14 waitJobs
bf54587a 15} from '@shared/server-commands'
9b474844 16
09071200 17describe('Test plugin action hooks', function () {
254d3579 18 let servers: PeerTubeServer[]
89cd1275
C
19 let videoUUID: string
20 let threadId: number
21
cb0eda56
AG
22 function checkHook (hook: ServerHookName, strictCount = true, count = 1) {
23 return servers[0].servers.waitUntilLog('Run hook ' + hook, count, strictCount)
89cd1275 24 }
9b474844
C
25
26 before(async function () {
0015924a 27 this.timeout(120000)
9b474844 28
254d3579 29 servers = await createMultipleServers(2)
89cd1275 30 await setAccessTokensToServers(servers)
3cabf353 31 await setDefaultVideoChannel(servers)
89cd1275 32
89d241a7 33 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() })
89cd1275 34
9293139f 35 await killallServers([ servers[0] ])
89cd1275 36
254d3579 37 await servers[0].run({
3cabf353
C
38 live: {
39 enabled: true
40 }
41 })
c3441b03
C
42
43 await doubleFollow(servers[0], servers[1])
9b474844
C
44 })
45
6f3fe96f
C
46 describe('Application hooks', function () {
47 it('Should run action:application.listening', async function () {
48 await checkHook('action:application.listening')
49 })
89cd1275
C
50 })
51
6f3fe96f 52 describe('Videos hooks', function () {
e2e0b645 53
6f3fe96f 54 it('Should run action:api.video.uploaded', async function () {
89d241a7 55 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } })
d23dd9fb 56 videoUUID = uuid
89cd1275 57
6f3fe96f
C
58 await checkHook('action:api.video.uploaded')
59 })
89cd1275 60
6f3fe96f 61 it('Should run action:api.video.updated', async function () {
89d241a7 62 await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video updated' } })
89cd1275 63
6f3fe96f
C
64 await checkHook('action:api.video.updated')
65 })
89cd1275 66
6f3fe96f 67 it('Should run action:api.video.viewed', async function () {
b2111066 68 await servers[0].views.simulateView({ id: videoUUID })
89cd1275 69
6f3fe96f
C
70 await checkHook('action:api.video.viewed')
71 })
0260dc8a
C
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 })
89cd1275
C
105 })
106
3cabf353
C
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,
89d241a7 113 channelId: servers[0].store.channel.id
3cabf353
C
114 }
115
89d241a7 116 await servers[0].live.create({ fields: attributes })
3cabf353
C
117
118 await checkHook('action:api.live-video.created')
119 })
cb0eda56
AG
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 })
3cabf353
C
143 })
144
6f3fe96f
C
145 describe('Comments hooks', function () {
146 it('Should run action:api.video-thread.created', async function () {
89d241a7 147 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
12edc149 148 threadId = created.id
89cd1275 149
6f3fe96f
C
150 await checkHook('action:api.video-thread.created')
151 })
89cd1275 152
6f3fe96f 153 it('Should run action:api.video-comment-reply.created', async function () {
89d241a7 154 await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
89cd1275 155
6f3fe96f
C
156 await checkHook('action:api.video-comment-reply.created')
157 })
89cd1275 158
6f3fe96f 159 it('Should run action:api.video-comment.deleted', async function () {
89d241a7 160 await servers[0].comments.delete({ videoId: videoUUID, commentId: threadId })
89cd1275 161
6f3fe96f
C
162 await checkHook('action:api.video-comment.deleted')
163 })
89cd1275
C
164 })
165
5e3d29ab 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
6f3fe96f
C
180 describe('Users hooks', function () {
181 let userId: number
182
183 it('Should run action:api.user.registered', async function () {
b379759f 184 await servers[0].registrations.register({ username: 'registered_user' })
89cd1275 185
6f3fe96f
C
186 await checkHook('action:api.user.registered')
187 })
188
189 it('Should run action:api.user.created', async function () {
89d241a7 190 const user = await servers[0].users.create({ username: 'created_user' })
7926c5f9 191 userId = user.id
6f3fe96f
C
192
193 await checkHook('action:api.user.created')
194 })
195
196 it('Should run action:api.user.oauth2-got-token', async function () {
4c7e60bc 197 await servers[0].login.login({ user: { username: 'created_user' } })
6f3fe96f
C
198
199 await checkHook('action:api.user.oauth2-got-token')
200 })
201
202 it('Should run action:api.user.blocked', async function () {
89d241a7 203 await servers[0].users.banUser({ userId })
6f3fe96f
C
204
205 await checkHook('action:api.user.blocked')
206 })
207
208 it('Should run action:api.user.unblocked', async function () {
89d241a7 209 await servers[0].users.unbanUser({ userId })
6f3fe96f
C
210
211 await checkHook('action:api.user.unblocked')
212 })
213
214 it('Should run action:api.user.updated', async function () {
89d241a7 215 await servers[0].users.update({ userId, videoQuota: 50 })
6f3fe96f
C
216
217 await checkHook('action:api.user.updated')
218 })
219
220 it('Should run action:api.user.deleted', async function () {
89d241a7 221 await servers[0].users.remove({ userId })
6f3fe96f
C
222
223 await checkHook('action:api.user.deleted')
224 })
9b474844
C
225 })
226
e2e0b645 227 describe('Playlist hooks', function () {
228 let playlistId: number
229 let videoId: number
230
231 before(async function () {
232 {
89d241a7 233 const { id } = await servers[0].playlists.create({
e6346d59 234 attributes: {
e2e0b645 235 displayName: 'My playlist',
236 privacy: VideoPlaylistPrivacy.PRIVATE
237 }
238 })
e6346d59 239 playlistId = id
e2e0b645 240 }
241
242 {
89d241a7 243 const { id } = await servers[0].videos.upload({ attributes: { name: 'my super name' } })
d23dd9fb 244 videoId = id
e2e0b645 245 }
246 })
247
248 it('Should run action:api.video-playlist-element.created', async function () {
89d241a7 249 await servers[0].playlists.addElement({ playlistId, attributes: { videoId } })
e2e0b645 250
251 await checkHook('action:api.video-playlist-element.created')
252 })
253 })
254
785f1897
C
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
c3441b03
C
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
8eb6a9eb
C
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 )
c3441b03
C
284 })
285 })
286
9b474844 287 after(async function () {
89cd1275 288 await cleanupTests(servers)
9b474844
C
289 })
290})