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