1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
18 setAccessTokensToServers,
19 setDefaultVideoChannel,
26 } from '../../../shared/extra-utils'
29 flushAndRunMultipleServers,
34 } from '../../../shared/extra-utils/server/servers'
36 describe('Test plugin action hooks', function () {
37 let servers: ServerInfo[]
41 function checkHook (hook: ServerHookName) {
42 return waitUntilLog(servers[0], 'Run hook ' + hook)
45 before(async function () {
48 servers = await flushAndRunMultipleServers(2)
49 await setAccessTokensToServers(servers)
50 await setDefaultVideoChannel(servers)
54 accessToken: servers[0].accessToken,
55 path: getPluginTestPath()
58 killallServers([ servers[0] ])
60 await reRunServer(servers[0], {
67 describe('Application hooks', function () {
68 it('Should run action:application.listening', async function () {
69 await checkHook('action:application.listening')
73 describe('Videos hooks', function () {
75 it('Should run action:api.video.uploaded', async function () {
76 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
77 videoUUID = res.body.video.uuid
79 await checkHook('action:api.video.uploaded')
82 it('Should run action:api.video.updated', async function () {
83 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
85 await checkHook('action:api.video.updated')
88 it('Should run action:api.video.viewed', async function () {
89 await viewVideo(servers[0].url, videoUUID)
91 await checkHook('action:api.video.viewed')
95 describe('Live hooks', function () {
97 it('Should run action:api.live-video.created', async function () {
100 privacy: VideoPrivacy.PUBLIC,
101 channelId: servers[0].videoChannel.id
104 await createLive(servers[0].url, servers[0].accessToken, attributes)
106 await checkHook('action:api.live-video.created')
110 describe('Comments hooks', function () {
111 it('Should run action:api.video-thread.created', async function () {
112 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
113 threadId = res.body.comment.id
115 await checkHook('action:api.video-thread.created')
118 it('Should run action:api.video-comment-reply.created', async function () {
119 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply')
121 await checkHook('action:api.video-comment-reply.created')
124 it('Should run action:api.video-comment.deleted', async function () {
125 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
127 await checkHook('action:api.video-comment.deleted')
131 describe('Users hooks', function () {
134 it('Should run action:api.user.registered', async function () {
135 await registerUser(servers[0].url, 'registered_user', 'super_password')
137 await checkHook('action:api.user.registered')
140 it('Should run action:api.user.created', async function () {
141 const res = await createUser({
143 accessToken: servers[0].accessToken,
144 username: 'created_user',
145 password: 'super_password'
147 userId = res.body.user.id
149 await checkHook('action:api.user.created')
152 it('Should run action:api.user.oauth2-got-token', async function () {
153 await userLogin(servers[0], { username: 'created_user', password: 'super_password' })
155 await checkHook('action:api.user.oauth2-got-token')
158 it('Should run action:api.user.blocked', async function () {
159 await blockUser(servers[0].url, userId, servers[0].accessToken)
161 await checkHook('action:api.user.blocked')
164 it('Should run action:api.user.unblocked', async function () {
165 await unblockUser(servers[0].url, userId, servers[0].accessToken)
167 await checkHook('action:api.user.unblocked')
170 it('Should run action:api.user.updated', async function () {
171 await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 })
173 await checkHook('action:api.user.updated')
176 it('Should run action:api.user.deleted', async function () {
177 await removeUser(servers[0].url, userId, servers[0].accessToken)
179 await checkHook('action:api.user.deleted')
183 describe('Playlist hooks', function () {
184 let playlistId: number
187 before(async function () {
189 const res = await createVideoPlaylist({
191 token: servers[0].accessToken,
193 displayName: 'My playlist',
194 privacy: VideoPlaylistPrivacy.PRIVATE
197 playlistId = res.body.videoPlaylist.id
201 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' })
202 videoId = res.body.video.id
206 it('Should run action:api.video-playlist-element.created', async function () {
207 await addVideoInPlaylist({
209 token: servers[0].accessToken,
211 elementAttrs: { videoId }
214 await checkHook('action:api.video-playlist-element.created')
218 after(async function () {
219 await cleanupTests(servers)