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