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