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