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