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