]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/plugins/action-hooks.ts
Introduce plugins command
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / action-hooks.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
5 import {
6 addVideoCommentReply,
7 addVideoCommentThread,
8 addVideoInPlaylist,
9 blockUser,
10 createLive,
11 createUser,
12 createVideoPlaylist,
13 deleteVideoComment,
14 PluginsCommand,
15 registerUser,
16 removeUser,
17 setAccessTokensToServers,
18 setDefaultVideoChannel,
19 unblockUser,
20 updateUser,
21 updateVideo,
22 uploadVideo,
23 userLogin,
24 viewVideo
25 } from '../../../shared/extra-utils'
26 import {
27 cleanupTests,
28 flushAndRunMultipleServers,
29 killallServers,
30 reRunServer,
31 ServerInfo,
32 waitUntilLog
33 } from '../../../shared/extra-utils/server/servers'
34
35 describe('Test plugin action hooks', function () {
36 let servers: ServerInfo[]
37 let videoUUID: string
38 let threadId: number
39
40 function checkHook (hook: ServerHookName) {
41 return waitUntilLog(servers[0], 'Run hook ' + hook)
42 }
43
44 before(async function () {
45 this.timeout(30000)
46
47 servers = await flushAndRunMultipleServers(2)
48 await setAccessTokensToServers(servers)
49 await setDefaultVideoChannel(servers)
50
51 await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() })
52
53 killallServers([ servers[0] ])
54
55 await reRunServer(servers[0], {
56 live: {
57 enabled: true
58 }
59 })
60 })
61
62 describe('Application hooks', function () {
63 it('Should run action:application.listening', async function () {
64 await checkHook('action:application.listening')
65 })
66 })
67
68 describe('Videos hooks', function () {
69
70 it('Should run action:api.video.uploaded', async function () {
71 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
72 videoUUID = res.body.video.uuid
73
74 await checkHook('action:api.video.uploaded')
75 })
76
77 it('Should run action:api.video.updated', async function () {
78 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
79
80 await checkHook('action:api.video.updated')
81 })
82
83 it('Should run action:api.video.viewed', async function () {
84 await viewVideo(servers[0].url, videoUUID)
85
86 await checkHook('action:api.video.viewed')
87 })
88 })
89
90 describe('Live hooks', function () {
91
92 it('Should run action:api.live-video.created', async function () {
93 const attributes = {
94 name: 'live',
95 privacy: VideoPrivacy.PUBLIC,
96 channelId: servers[0].videoChannel.id
97 }
98
99 await createLive(servers[0].url, servers[0].accessToken, attributes)
100
101 await checkHook('action:api.live-video.created')
102 })
103 })
104
105 describe('Comments hooks', function () {
106 it('Should run action:api.video-thread.created', async function () {
107 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
108 threadId = res.body.comment.id
109
110 await checkHook('action:api.video-thread.created')
111 })
112
113 it('Should run action:api.video-comment-reply.created', async function () {
114 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply')
115
116 await checkHook('action:api.video-comment-reply.created')
117 })
118
119 it('Should run action:api.video-comment.deleted', async function () {
120 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
121
122 await checkHook('action:api.video-comment.deleted')
123 })
124 })
125
126 describe('Users hooks', function () {
127 let userId: number
128
129 it('Should run action:api.user.registered', async function () {
130 await registerUser(servers[0].url, 'registered_user', 'super_password')
131
132 await checkHook('action:api.user.registered')
133 })
134
135 it('Should run action:api.user.created', async function () {
136 const res = await createUser({
137 url: servers[0].url,
138 accessToken: servers[0].accessToken,
139 username: 'created_user',
140 password: 'super_password'
141 })
142 userId = res.body.user.id
143
144 await checkHook('action:api.user.created')
145 })
146
147 it('Should run action:api.user.oauth2-got-token', async function () {
148 await userLogin(servers[0], { username: 'created_user', password: 'super_password' })
149
150 await checkHook('action:api.user.oauth2-got-token')
151 })
152
153 it('Should run action:api.user.blocked', async function () {
154 await blockUser(servers[0].url, userId, servers[0].accessToken)
155
156 await checkHook('action:api.user.blocked')
157 })
158
159 it('Should run action:api.user.unblocked', async function () {
160 await unblockUser(servers[0].url, userId, servers[0].accessToken)
161
162 await checkHook('action:api.user.unblocked')
163 })
164
165 it('Should run action:api.user.updated', async function () {
166 await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 })
167
168 await checkHook('action:api.user.updated')
169 })
170
171 it('Should run action:api.user.deleted', async function () {
172 await removeUser(servers[0].url, userId, servers[0].accessToken)
173
174 await checkHook('action:api.user.deleted')
175 })
176 })
177
178 describe('Playlist hooks', function () {
179 let playlistId: number
180 let videoId: number
181
182 before(async function () {
183 {
184 const res = await createVideoPlaylist({
185 url: servers[0].url,
186 token: servers[0].accessToken,
187 playlistAttrs: {
188 displayName: 'My playlist',
189 privacy: VideoPlaylistPrivacy.PRIVATE
190 }
191 })
192 playlistId = res.body.videoPlaylist.id
193 }
194
195 {
196 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' })
197 videoId = res.body.video.id
198 }
199 })
200
201 it('Should run action:api.video-playlist-element.created', async function () {
202 await addVideoInPlaylist({
203 url: servers[0].url,
204 token: servers[0].accessToken,
205 playlistId,
206 elementAttrs: { videoId }
207 })
208
209 await checkHook('action:api.video-playlist-element.created')
210 })
211 })
212
213 after(async function () {
214 await cleanupTests(servers)
215 })
216 })