]>
Commit | Line | Data |
---|---|---|
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 | } from '@shared/server-commands' | |
14 | ||
15 | describe('Test plugin action hooks', function () { | |
16 | let servers: PeerTubeServer[] | |
17 | let videoUUID: string | |
18 | let threadId: number | |
19 | ||
20 | function checkHook (hook: ServerHookName, strictCount = true) { | |
21 | return servers[0].servers.waitUntilLog('Run hook ' + hook, 1, strictCount) | |
22 | } | |
23 | ||
24 | before(async function () { | |
25 | this.timeout(120000) | |
26 | ||
27 | servers = await createMultipleServers(2) | |
28 | await setAccessTokensToServers(servers) | |
29 | await setDefaultVideoChannel(servers) | |
30 | ||
31 | await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() }) | |
32 | ||
33 | await killallServers([ servers[0] ]) | |
34 | ||
35 | await servers[0].run({ | |
36 | live: { | |
37 | enabled: true | |
38 | } | |
39 | }) | |
40 | ||
41 | await doubleFollow(servers[0], servers[1]) | |
42 | }) | |
43 | ||
44 | describe('Application hooks', function () { | |
45 | it('Should run action:application.listening', async function () { | |
46 | await checkHook('action:application.listening') | |
47 | }) | |
48 | }) | |
49 | ||
50 | describe('Videos hooks', function () { | |
51 | ||
52 | it('Should run action:api.video.uploaded', async function () { | |
53 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } }) | |
54 | videoUUID = uuid | |
55 | ||
56 | await checkHook('action:api.video.uploaded') | |
57 | }) | |
58 | ||
59 | it('Should run action:api.video.updated', async function () { | |
60 | await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video updated' } }) | |
61 | ||
62 | await checkHook('action:api.video.updated') | |
63 | }) | |
64 | ||
65 | it('Should run action:api.video.viewed', async function () { | |
66 | await servers[0].views.simulateView({ id: videoUUID }) | |
67 | ||
68 | await checkHook('action:api.video.viewed') | |
69 | }) | |
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 | }) | |
103 | }) | |
104 | ||
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, | |
111 | channelId: servers[0].store.channel.id | |
112 | } | |
113 | ||
114 | await servers[0].live.create({ fields: attributes }) | |
115 | ||
116 | await checkHook('action:api.live-video.created') | |
117 | }) | |
118 | }) | |
119 | ||
120 | describe('Comments hooks', function () { | |
121 | it('Should run action:api.video-thread.created', async function () { | |
122 | const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' }) | |
123 | threadId = created.id | |
124 | ||
125 | await checkHook('action:api.video-thread.created') | |
126 | }) | |
127 | ||
128 | it('Should run action:api.video-comment-reply.created', async function () { | |
129 | await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' }) | |
130 | ||
131 | await checkHook('action:api.video-comment-reply.created') | |
132 | }) | |
133 | ||
134 | it('Should run action:api.video-comment.deleted', async function () { | |
135 | await servers[0].comments.delete({ videoId: videoUUID, commentId: threadId }) | |
136 | ||
137 | await checkHook('action:api.video-comment.deleted') | |
138 | }) | |
139 | }) | |
140 | ||
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 | ||
155 | describe('Users hooks', function () { | |
156 | let userId: number | |
157 | ||
158 | it('Should run action:api.user.registered', async function () { | |
159 | await servers[0].registrations.register({ username: 'registered_user' }) | |
160 | ||
161 | await checkHook('action:api.user.registered') | |
162 | }) | |
163 | ||
164 | it('Should run action:api.user.created', async function () { | |
165 | const user = await servers[0].users.create({ username: 'created_user' }) | |
166 | userId = user.id | |
167 | ||
168 | await checkHook('action:api.user.created') | |
169 | }) | |
170 | ||
171 | it('Should run action:api.user.oauth2-got-token', async function () { | |
172 | await servers[0].login.login({ user: { username: 'created_user' } }) | |
173 | ||
174 | await checkHook('action:api.user.oauth2-got-token') | |
175 | }) | |
176 | ||
177 | it('Should run action:api.user.blocked', async function () { | |
178 | await servers[0].users.banUser({ userId }) | |
179 | ||
180 | await checkHook('action:api.user.blocked') | |
181 | }) | |
182 | ||
183 | it('Should run action:api.user.unblocked', async function () { | |
184 | await servers[0].users.unbanUser({ userId }) | |
185 | ||
186 | await checkHook('action:api.user.unblocked') | |
187 | }) | |
188 | ||
189 | it('Should run action:api.user.updated', async function () { | |
190 | await servers[0].users.update({ userId, videoQuota: 50 }) | |
191 | ||
192 | await checkHook('action:api.user.updated') | |
193 | }) | |
194 | ||
195 | it('Should run action:api.user.deleted', async function () { | |
196 | await servers[0].users.remove({ userId }) | |
197 | ||
198 | await checkHook('action:api.user.deleted') | |
199 | }) | |
200 | }) | |
201 | ||
202 | describe('Playlist hooks', function () { | |
203 | let playlistId: number | |
204 | let videoId: number | |
205 | ||
206 | before(async function () { | |
207 | { | |
208 | const { id } = await servers[0].playlists.create({ | |
209 | attributes: { | |
210 | displayName: 'My playlist', | |
211 | privacy: VideoPlaylistPrivacy.PRIVATE | |
212 | } | |
213 | }) | |
214 | playlistId = id | |
215 | } | |
216 | ||
217 | { | |
218 | const { id } = await servers[0].videos.upload({ attributes: { name: 'my super name' } }) | |
219 | videoId = id | |
220 | } | |
221 | }) | |
222 | ||
223 | it('Should run action:api.video-playlist-element.created', async function () { | |
224 | await servers[0].playlists.addElement({ playlistId, attributes: { videoId } }) | |
225 | ||
226 | await checkHook('action:api.video-playlist-element.created') | |
227 | }) | |
228 | }) | |
229 | ||
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 | ||
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 | ||
254 | await servers[0].servers.waitUntilLog('action:activity-pub.remote-video.updated - AP remote video - video remote video', 1, false) | |
255 | }) | |
256 | }) | |
257 | ||
258 | after(async function () { | |
259 | await cleanupTests(servers) | |
260 | }) | |
261 | }) |