]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
9b474844 | 2 | |
b2111066 | 3 | import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' |
89cd1275 | 4 | import { |
7926c5f9 | 5 | cleanupTests, |
254d3579 | 6 | createMultipleServers, |
7926c5f9 | 7 | killallServers, |
254d3579 | 8 | PeerTubeServer, |
ae2abfd3 | 9 | PluginsCommand, |
89cd1275 | 10 | setAccessTokensToServers, |
d23dd9fb | 11 | setDefaultVideoChannel |
bf54587a | 12 | } from '@shared/server-commands' |
9b474844 | 13 | |
09071200 | 14 | describe('Test plugin action hooks', function () { |
254d3579 | 15 | let servers: PeerTubeServer[] |
89cd1275 C |
16 | let videoUUID: string |
17 | let threadId: number | |
18 | ||
785f1897 C |
19 | function checkHook (hook: ServerHookName, strictCount = true) { |
20 | return servers[0].servers.waitUntilLog('Run hook ' + hook, 1, strictCount) | |
89cd1275 | 21 | } |
9b474844 C |
22 | |
23 | before(async function () { | |
0015924a | 24 | this.timeout(120000) |
9b474844 | 25 | |
254d3579 | 26 | servers = await createMultipleServers(2) |
89cd1275 | 27 | await setAccessTokensToServers(servers) |
3cabf353 | 28 | await setDefaultVideoChannel(servers) |
89cd1275 | 29 | |
89d241a7 | 30 | await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() }) |
89cd1275 | 31 | |
9293139f | 32 | await killallServers([ servers[0] ]) |
89cd1275 | 33 | |
254d3579 | 34 | await servers[0].run({ |
3cabf353 C |
35 | live: { |
36 | enabled: true | |
37 | } | |
38 | }) | |
9b474844 C |
39 | }) |
40 | ||
6f3fe96f C |
41 | describe('Application hooks', function () { |
42 | it('Should run action:application.listening', async function () { | |
43 | await checkHook('action:application.listening') | |
44 | }) | |
89cd1275 C |
45 | }) |
46 | ||
6f3fe96f | 47 | describe('Videos hooks', function () { |
e2e0b645 | 48 | |
6f3fe96f | 49 | it('Should run action:api.video.uploaded', async function () { |
89d241a7 | 50 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } }) |
d23dd9fb | 51 | videoUUID = uuid |
89cd1275 | 52 | |
6f3fe96f C |
53 | await checkHook('action:api.video.uploaded') |
54 | }) | |
89cd1275 | 55 | |
6f3fe96f | 56 | it('Should run action:api.video.updated', async function () { |
89d241a7 | 57 | await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video updated' } }) |
89cd1275 | 58 | |
6f3fe96f C |
59 | await checkHook('action:api.video.updated') |
60 | }) | |
89cd1275 | 61 | |
6f3fe96f | 62 | it('Should run action:api.video.viewed', async function () { |
b2111066 | 63 | await servers[0].views.simulateView({ id: videoUUID }) |
89cd1275 | 64 | |
6f3fe96f C |
65 | await checkHook('action:api.video.viewed') |
66 | }) | |
0260dc8a C |
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 | }) | |
89cd1275 C |
100 | }) |
101 | ||
3cabf353 C |
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, | |
89d241a7 | 108 | channelId: servers[0].store.channel.id |
3cabf353 C |
109 | } |
110 | ||
89d241a7 | 111 | await servers[0].live.create({ fields: attributes }) |
3cabf353 C |
112 | |
113 | await checkHook('action:api.live-video.created') | |
114 | }) | |
115 | }) | |
116 | ||
6f3fe96f C |
117 | describe('Comments hooks', function () { |
118 | it('Should run action:api.video-thread.created', async function () { | |
89d241a7 | 119 | const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' }) |
12edc149 | 120 | threadId = created.id |
89cd1275 | 121 | |
6f3fe96f C |
122 | await checkHook('action:api.video-thread.created') |
123 | }) | |
89cd1275 | 124 | |
6f3fe96f | 125 | it('Should run action:api.video-comment-reply.created', async function () { |
89d241a7 | 126 | await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' }) |
89cd1275 | 127 | |
6f3fe96f C |
128 | await checkHook('action:api.video-comment-reply.created') |
129 | }) | |
89cd1275 | 130 | |
6f3fe96f | 131 | it('Should run action:api.video-comment.deleted', async function () { |
89d241a7 | 132 | await servers[0].comments.delete({ videoId: videoUUID, commentId: threadId }) |
89cd1275 | 133 | |
6f3fe96f C |
134 | await checkHook('action:api.video-comment.deleted') |
135 | }) | |
89cd1275 C |
136 | }) |
137 | ||
5e3d29ab | 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 | ||
6f3fe96f C |
152 | describe('Users hooks', function () { |
153 | let userId: number | |
154 | ||
155 | it('Should run action:api.user.registered', async function () { | |
89d241a7 | 156 | await servers[0].users.register({ username: 'registered_user' }) |
89cd1275 | 157 | |
6f3fe96f C |
158 | await checkHook('action:api.user.registered') |
159 | }) | |
160 | ||
161 | it('Should run action:api.user.created', async function () { | |
89d241a7 | 162 | const user = await servers[0].users.create({ username: 'created_user' }) |
7926c5f9 | 163 | userId = user.id |
6f3fe96f C |
164 | |
165 | await checkHook('action:api.user.created') | |
166 | }) | |
167 | ||
168 | it('Should run action:api.user.oauth2-got-token', async function () { | |
4c7e60bc | 169 | await servers[0].login.login({ user: { username: 'created_user' } }) |
6f3fe96f C |
170 | |
171 | await checkHook('action:api.user.oauth2-got-token') | |
172 | }) | |
173 | ||
174 | it('Should run action:api.user.blocked', async function () { | |
89d241a7 | 175 | await servers[0].users.banUser({ userId }) |
6f3fe96f C |
176 | |
177 | await checkHook('action:api.user.blocked') | |
178 | }) | |
179 | ||
180 | it('Should run action:api.user.unblocked', async function () { | |
89d241a7 | 181 | await servers[0].users.unbanUser({ userId }) |
6f3fe96f C |
182 | |
183 | await checkHook('action:api.user.unblocked') | |
184 | }) | |
185 | ||
186 | it('Should run action:api.user.updated', async function () { | |
89d241a7 | 187 | await servers[0].users.update({ userId, videoQuota: 50 }) |
6f3fe96f C |
188 | |
189 | await checkHook('action:api.user.updated') | |
190 | }) | |
191 | ||
192 | it('Should run action:api.user.deleted', async function () { | |
89d241a7 | 193 | await servers[0].users.remove({ userId }) |
6f3fe96f C |
194 | |
195 | await checkHook('action:api.user.deleted') | |
196 | }) | |
9b474844 C |
197 | }) |
198 | ||
e2e0b645 | 199 | describe('Playlist hooks', function () { |
200 | let playlistId: number | |
201 | let videoId: number | |
202 | ||
203 | before(async function () { | |
204 | { | |
89d241a7 | 205 | const { id } = await servers[0].playlists.create({ |
e6346d59 | 206 | attributes: { |
e2e0b645 | 207 | displayName: 'My playlist', |
208 | privacy: VideoPlaylistPrivacy.PRIVATE | |
209 | } | |
210 | }) | |
e6346d59 | 211 | playlistId = id |
e2e0b645 | 212 | } |
213 | ||
214 | { | |
89d241a7 | 215 | const { id } = await servers[0].videos.upload({ attributes: { name: 'my super name' } }) |
d23dd9fb | 216 | videoId = id |
e2e0b645 | 217 | } |
218 | }) | |
219 | ||
220 | it('Should run action:api.video-playlist-element.created', async function () { | |
89d241a7 | 221 | await servers[0].playlists.addElement({ playlistId, attributes: { videoId } }) |
e2e0b645 | 222 | |
223 | await checkHook('action:api.video-playlist-element.created') | |
224 | }) | |
225 | }) | |
226 | ||
785f1897 C |
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 | ||
9b474844 | 234 | after(async function () { |
89cd1275 | 235 | await cleanupTests(servers) |
9b474844 C |
236 | }) |
237 | }) |