]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/plugins/action-hooks.ts
Add runner server tests
[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,
d23dd9fb 12 setDefaultVideoChannel
bf54587a 13} from '@shared/server-commands'
9b474844 14
09071200 15describe('Test plugin action hooks', function () {
254d3579 16 let servers: PeerTubeServer[]
89cd1275
C
17 let videoUUID: string
18 let threadId: number
19
785f1897
C
20 function checkHook (hook: ServerHookName, strictCount = true) {
21 return servers[0].servers.waitUntilLog('Run hook ' + hook, 1, strictCount)
89cd1275 22 }
9b474844
C
23
24 before(async function () {
0015924a 25 this.timeout(120000)
9b474844 26
254d3579 27 servers = await createMultipleServers(2)
89cd1275 28 await setAccessTokensToServers(servers)
3cabf353 29 await setDefaultVideoChannel(servers)
89cd1275 30
89d241a7 31 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() })
89cd1275 32
9293139f 33 await killallServers([ servers[0] ])
89cd1275 34
254d3579 35 await servers[0].run({
3cabf353
C
36 live: {
37 enabled: true
38 }
39 })
c3441b03
C
40
41 await doubleFollow(servers[0], servers[1])
9b474844
C
42 })
43
6f3fe96f
C
44 describe('Application hooks', function () {
45 it('Should run action:application.listening', async function () {
46 await checkHook('action:application.listening')
47 })
89cd1275
C
48 })
49
6f3fe96f 50 describe('Videos hooks', function () {
e2e0b645 51
6f3fe96f 52 it('Should run action:api.video.uploaded', async function () {
89d241a7 53 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } })
d23dd9fb 54 videoUUID = uuid
89cd1275 55
6f3fe96f
C
56 await checkHook('action:api.video.uploaded')
57 })
89cd1275 58
6f3fe96f 59 it('Should run action:api.video.updated', async function () {
89d241a7 60 await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video updated' } })
89cd1275 61
6f3fe96f
C
62 await checkHook('action:api.video.updated')
63 })
89cd1275 64
6f3fe96f 65 it('Should run action:api.video.viewed', async function () {
b2111066 66 await servers[0].views.simulateView({ id: videoUUID })
89cd1275 67
6f3fe96f
C
68 await checkHook('action:api.video.viewed')
69 })
0260dc8a
C
70
71 it('Should run action:api.video.deleted', async function () {
72 await servers[0].videos.remove({ id: videoUUID })
73
74 await checkHook('action:api.video.deleted')
75 })
76
77 after(async function () {
78 const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
79 videoUUID = uuid
80 })
81 })
82
83 describe('Video channel hooks', function () {
84 const channelName = 'my_super_channel'
85
86 it('Should run action:api.video-channel.created', async function () {
87 await servers[0].channels.create({ attributes: { name: channelName } })
88
89 await checkHook('action:api.video-channel.created')
90 })
91
92 it('Should run action:api.video-channel.updated', async function () {
93 await servers[0].channels.update({ channelName, attributes: { displayName: 'my display name' } })
94
95 await checkHook('action:api.video-channel.updated')
96 })
97
98 it('Should run action:api.video-channel.deleted', async function () {
99 await servers[0].channels.delete({ channelName })
100
101 await checkHook('action:api.video-channel.deleted')
102 })
89cd1275
C
103 })
104
3cabf353
C
105 describe('Live hooks', function () {
106
107 it('Should run action:api.live-video.created', async function () {
108 const attributes = {
109 name: 'live',
110 privacy: VideoPrivacy.PUBLIC,
89d241a7 111 channelId: servers[0].store.channel.id
3cabf353
C
112 }
113
89d241a7 114 await servers[0].live.create({ fields: attributes })
3cabf353
C
115
116 await checkHook('action:api.live-video.created')
117 })
118 })
119
6f3fe96f
C
120 describe('Comments hooks', function () {
121 it('Should run action:api.video-thread.created', async function () {
89d241a7 122 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
12edc149 123 threadId = created.id
89cd1275 124
6f3fe96f
C
125 await checkHook('action:api.video-thread.created')
126 })
89cd1275 127
6f3fe96f 128 it('Should run action:api.video-comment-reply.created', async function () {
89d241a7 129 await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
89cd1275 130
6f3fe96f
C
131 await checkHook('action:api.video-comment-reply.created')
132 })
89cd1275 133
6f3fe96f 134 it('Should run action:api.video-comment.deleted', async function () {
89d241a7 135 await servers[0].comments.delete({ videoId: videoUUID, commentId: threadId })
89cd1275 136
6f3fe96f
C
137 await checkHook('action:api.video-comment.deleted')
138 })
89cd1275
C
139 })
140
5e3d29ab 141 describe('Captions hooks', function () {
142 it('Should run action:api.video-caption.created', async function () {
143 await servers[0].captions.add({ videoId: videoUUID, language: 'en', fixture: 'subtitle-good.srt' })
144
145 await checkHook('action:api.video-caption.created')
146 })
147
148 it('Should run action:api.video-caption.deleted', async function () {
149 await servers[0].captions.delete({ videoId: videoUUID, language: 'en' })
150
151 await checkHook('action:api.video-caption.deleted')
152 })
153 })
154
6f3fe96f
C
155 describe('Users hooks', function () {
156 let userId: number
157
158 it('Should run action:api.user.registered', async function () {
b379759f 159 await servers[0].registrations.register({ username: 'registered_user' })
89cd1275 160
6f3fe96f
C
161 await checkHook('action:api.user.registered')
162 })
163
164 it('Should run action:api.user.created', async function () {
89d241a7 165 const user = await servers[0].users.create({ username: 'created_user' })
7926c5f9 166 userId = user.id
6f3fe96f
C
167
168 await checkHook('action:api.user.created')
169 })
170
171 it('Should run action:api.user.oauth2-got-token', async function () {
4c7e60bc 172 await servers[0].login.login({ user: { username: 'created_user' } })
6f3fe96f
C
173
174 await checkHook('action:api.user.oauth2-got-token')
175 })
176
177 it('Should run action:api.user.blocked', async function () {
89d241a7 178 await servers[0].users.banUser({ userId })
6f3fe96f
C
179
180 await checkHook('action:api.user.blocked')
181 })
182
183 it('Should run action:api.user.unblocked', async function () {
89d241a7 184 await servers[0].users.unbanUser({ userId })
6f3fe96f
C
185
186 await checkHook('action:api.user.unblocked')
187 })
188
189 it('Should run action:api.user.updated', async function () {
89d241a7 190 await servers[0].users.update({ userId, videoQuota: 50 })
6f3fe96f
C
191
192 await checkHook('action:api.user.updated')
193 })
194
195 it('Should run action:api.user.deleted', async function () {
89d241a7 196 await servers[0].users.remove({ userId })
6f3fe96f
C
197
198 await checkHook('action:api.user.deleted')
199 })
9b474844
C
200 })
201
e2e0b645 202 describe('Playlist hooks', function () {
203 let playlistId: number
204 let videoId: number
205
206 before(async function () {
207 {
89d241a7 208 const { id } = await servers[0].playlists.create({
e6346d59 209 attributes: {
e2e0b645 210 displayName: 'My playlist',
211 privacy: VideoPlaylistPrivacy.PRIVATE
212 }
213 })
e6346d59 214 playlistId = id
e2e0b645 215 }
216
217 {
89d241a7 218 const { id } = await servers[0].videos.upload({ attributes: { name: 'my super name' } })
d23dd9fb 219 videoId = id
e2e0b645 220 }
221 })
222
223 it('Should run action:api.video-playlist-element.created', async function () {
89d241a7 224 await servers[0].playlists.addElement({ playlistId, attributes: { videoId } })
e2e0b645 225
226 await checkHook('action:api.video-playlist-element.created')
227 })
228 })
229
785f1897
C
230 describe('Notification hook', function () {
231
232 it('Should run action:notifier.notification.created', async function () {
233 await checkHook('action:notifier.notification.created', false)
234 })
235 })
236
c3441b03
C
237 describe('Activity Pub hooks', function () {
238 let videoUUID: string
239
240 it('Should run action:activity-pub.remote-video.created', async function () {
241 this.timeout(30000)
242
243 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
244 videoUUID = uuid
245
246 await servers[0].servers.waitUntilLog('action:activity-pub.remote-video.created - AP remote video - video remote video')
247 })
248
249 it('Should run action:activity-pub.remote-video.updated', async function () {
250 this.timeout(30000)
251
252 await servers[1].videos.update({ id: videoUUID, attributes: { name: 'remote video updated' } })
253
8b197aca 254 await servers[0].servers.waitUntilLog('action:activity-pub.remote-video.updated - AP remote video - video remote video', 1, false)
c3441b03
C
255 })
256 })
257
9b474844 258 after(async function () {
89cd1275 259 await cleanupTests(servers)
9b474844
C
260 })
261})