aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/action-hooks.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-31 14:34:36 +0200
committerChocobozzz <me@florianbigard.com>2023-08-11 15:02:33 +0200
commit3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch)
treee4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/tests/plugins/action-hooks.ts
parent04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff)
downloadPeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/tests/plugins/action-hooks.ts')
-rw-r--r--server/tests/plugins/action-hooks.ts298
1 files changed, 0 insertions, 298 deletions
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts
deleted file mode 100644
index 773be0d76..000000000
--- a/server/tests/plugins/action-hooks.ts
+++ /dev/null
@@ -1,298 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
4import {
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
17describe('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 servers[0].config.enableFileUpdate()
44
45 await doubleFollow(servers[0], servers[1])
46 })
47
48 describe('Application hooks', function () {
49 it('Should run action:application.listening', async function () {
50 await checkHook('action:application.listening')
51 })
52 })
53
54 describe('Videos hooks', function () {
55
56 it('Should run action:api.video.uploaded', async function () {
57 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } })
58 videoUUID = uuid
59
60 await checkHook('action:api.video.uploaded')
61 })
62
63 it('Should run action:api.video.updated', async function () {
64 await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video updated' } })
65
66 await checkHook('action:api.video.updated')
67 })
68
69 it('Should run action:api.video.viewed', async function () {
70 await servers[0].views.simulateView({ id: videoUUID })
71
72 await checkHook('action:api.video.viewed')
73 })
74
75 it('Should run action:api.video.file-updated', async function () {
76 await servers[0].videos.replaceSourceFile({ videoId: videoUUID, fixture: 'video_short.mp4' })
77
78 await checkHook('action:api.video.file-updated')
79 })
80
81 it('Should run action:api.video.deleted', async function () {
82 await servers[0].videos.remove({ id: videoUUID })
83
84 await checkHook('action:api.video.deleted')
85 })
86
87 after(async function () {
88 const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
89 videoUUID = uuid
90 })
91 })
92
93 describe('Video channel hooks', function () {
94 const channelName = 'my_super_channel'
95
96 it('Should run action:api.video-channel.created', async function () {
97 await servers[0].channels.create({ attributes: { name: channelName } })
98
99 await checkHook('action:api.video-channel.created')
100 })
101
102 it('Should run action:api.video-channel.updated', async function () {
103 await servers[0].channels.update({ channelName, attributes: { displayName: 'my display name' } })
104
105 await checkHook('action:api.video-channel.updated')
106 })
107
108 it('Should run action:api.video-channel.deleted', async function () {
109 await servers[0].channels.delete({ channelName })
110
111 await checkHook('action:api.video-channel.deleted')
112 })
113 })
114
115 describe('Live hooks', function () {
116
117 it('Should run action:api.live-video.created', async function () {
118 const attributes = {
119 name: 'live',
120 privacy: VideoPrivacy.PUBLIC,
121 channelId: servers[0].store.channel.id
122 }
123
124 await servers[0].live.create({ fields: attributes })
125
126 await checkHook('action:api.live-video.created')
127 })
128
129 it('Should run action:live.video.state.updated', async function () {
130 this.timeout(60000)
131
132 const attributes = {
133 name: 'live',
134 privacy: VideoPrivacy.PUBLIC,
135 channelId: servers[0].store.channel.id
136 }
137
138 const { uuid: liveVideoId } = await servers[0].live.create({ fields: attributes })
139 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId })
140 await servers[0].live.waitUntilPublished({ videoId: liveVideoId })
141 await waitJobs(servers)
142
143 await checkHook('action:live.video.state.updated', true, 1)
144
145 await stopFfmpeg(ffmpegCommand)
146 await servers[0].live.waitUntilEnded({ videoId: liveVideoId })
147 await waitJobs(servers)
148
149 await checkHook('action:live.video.state.updated', true, 2)
150 })
151 })
152
153 describe('Comments hooks', function () {
154 it('Should run action:api.video-thread.created', async function () {
155 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
156 threadId = created.id
157
158 await checkHook('action:api.video-thread.created')
159 })
160
161 it('Should run action:api.video-comment-reply.created', async function () {
162 await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
163
164 await checkHook('action:api.video-comment-reply.created')
165 })
166
167 it('Should run action:api.video-comment.deleted', async function () {
168 await servers[0].comments.delete({ videoId: videoUUID, commentId: threadId })
169
170 await checkHook('action:api.video-comment.deleted')
171 })
172 })
173
174 describe('Captions hooks', function () {
175 it('Should run action:api.video-caption.created', async function () {
176 await servers[0].captions.add({ videoId: videoUUID, language: 'en', fixture: 'subtitle-good.srt' })
177
178 await checkHook('action:api.video-caption.created')
179 })
180
181 it('Should run action:api.video-caption.deleted', async function () {
182 await servers[0].captions.delete({ videoId: videoUUID, language: 'en' })
183
184 await checkHook('action:api.video-caption.deleted')
185 })
186 })
187
188 describe('Users hooks', function () {
189 let userId: number
190
191 it('Should run action:api.user.registered', async function () {
192 await servers[0].registrations.register({ username: 'registered_user' })
193
194 await checkHook('action:api.user.registered')
195 })
196
197 it('Should run action:api.user.created', async function () {
198 const user = await servers[0].users.create({ username: 'created_user' })
199 userId = user.id
200
201 await checkHook('action:api.user.created')
202 })
203
204 it('Should run action:api.user.oauth2-got-token', async function () {
205 await servers[0].login.login({ user: { username: 'created_user' } })
206
207 await checkHook('action:api.user.oauth2-got-token')
208 })
209
210 it('Should run action:api.user.blocked', async function () {
211 await servers[0].users.banUser({ userId })
212
213 await checkHook('action:api.user.blocked')
214 })
215
216 it('Should run action:api.user.unblocked', async function () {
217 await servers[0].users.unbanUser({ userId })
218
219 await checkHook('action:api.user.unblocked')
220 })
221
222 it('Should run action:api.user.updated', async function () {
223 await servers[0].users.update({ userId, videoQuota: 50 })
224
225 await checkHook('action:api.user.updated')
226 })
227
228 it('Should run action:api.user.deleted', async function () {
229 await servers[0].users.remove({ userId })
230
231 await checkHook('action:api.user.deleted')
232 })
233 })
234
235 describe('Playlist hooks', function () {
236 let playlistId: number
237 let videoId: number
238
239 before(async function () {
240 {
241 const { id } = await servers[0].playlists.create({
242 attributes: {
243 displayName: 'My playlist',
244 privacy: VideoPlaylistPrivacy.PRIVATE
245 }
246 })
247 playlistId = id
248 }
249
250 {
251 const { id } = await servers[0].videos.upload({ attributes: { name: 'my super name' } })
252 videoId = id
253 }
254 })
255
256 it('Should run action:api.video-playlist-element.created', async function () {
257 await servers[0].playlists.addElement({ playlistId, attributes: { videoId } })
258
259 await checkHook('action:api.video-playlist-element.created')
260 })
261 })
262
263 describe('Notification hook', function () {
264
265 it('Should run action:notifier.notification.created', async function () {
266 await checkHook('action:notifier.notification.created', false)
267 })
268 })
269
270 describe('Activity Pub hooks', function () {
271 let videoUUID: string
272
273 it('Should run action:activity-pub.remote-video.created', async function () {
274 this.timeout(30000)
275
276 const { uuid } = await servers[1].videos.quickUpload({ name: 'remote video' })
277 videoUUID = uuid
278
279 await servers[0].servers.waitUntilLog('action:activity-pub.remote-video.created - AP remote video - video remote video')
280 })
281
282 it('Should run action:activity-pub.remote-video.updated', async function () {
283 this.timeout(30000)
284
285 await servers[1].videos.update({ id: videoUUID, attributes: { name: 'remote video updated' } })
286
287 await servers[0].servers.waitUntilLog(
288 'action:activity-pub.remote-video.updated - AP remote video updated - video remote video updated',
289 1,
290 false
291 )
292 })
293 })
294
295 after(async function () {
296 await cleanupTests(servers)
297 })
298})