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