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