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