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