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