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