1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
18 } from '../../../shared/extra-utils'
21 flushAndRunMultipleServers,
25 } from '../../../shared/extra-utils/server/servers'
27 describe('Test plugin action hooks', function () {
28 let servers: ServerInfo[]
32 function checkHook (hook: ServerHookName) {
33 return servers[0].serversCommand.waitUntilLog('Run hook ' + hook)
36 before(async function () {
39 servers = await flushAndRunMultipleServers(2)
40 await setAccessTokensToServers(servers)
41 await setDefaultVideoChannel(servers)
43 await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() })
45 await killallServers([ servers[0] ])
47 await reRunServer(servers[0], {
54 describe('Application hooks', function () {
55 it('Should run action:application.listening', async function () {
56 await checkHook('action:application.listening')
60 describe('Videos hooks', function () {
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
66 await checkHook('action:api.video.uploaded')
69 it('Should run action:api.video.updated', async function () {
70 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
72 await checkHook('action:api.video.updated')
75 it('Should run action:api.video.viewed', async function () {
76 await viewVideo(servers[0].url, videoUUID)
78 await checkHook('action:api.video.viewed')
82 describe('Live hooks', function () {
84 it('Should run action:api.live-video.created', async function () {
87 privacy: VideoPrivacy.PUBLIC,
88 channelId: servers[0].videoChannel.id
91 await servers[0].liveCommand.create({ fields: attributes })
93 await checkHook('action:api.live-video.created')
97 describe('Comments hooks', function () {
98 it('Should run action:api.video-thread.created', async function () {
99 const created = await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'thread' })
100 threadId = created.id
102 await checkHook('action:api.video-thread.created')
105 it('Should run action:api.video-comment-reply.created', async function () {
106 await servers[0].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
108 await checkHook('action:api.video-comment-reply.created')
111 it('Should run action:api.video-comment.deleted', async function () {
112 await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId: threadId })
114 await checkHook('action:api.video-comment.deleted')
118 describe('Users hooks', function () {
121 it('Should run action:api.user.registered', async function () {
122 await registerUser(servers[0].url, 'registered_user', 'super_password')
124 await checkHook('action:api.user.registered')
127 it('Should run action:api.user.created', async function () {
128 const res = await createUser({
130 accessToken: servers[0].accessToken,
131 username: 'created_user',
132 password: 'super_password'
134 userId = res.body.user.id
136 await checkHook('action:api.user.created')
139 it('Should run action:api.user.oauth2-got-token', async function () {
140 await servers[0].loginCommand.getAccessToken('created_user', 'super_password')
142 await checkHook('action:api.user.oauth2-got-token')
145 it('Should run action:api.user.blocked', async function () {
146 await blockUser(servers[0].url, userId, servers[0].accessToken)
148 await checkHook('action:api.user.blocked')
151 it('Should run action:api.user.unblocked', async function () {
152 await unblockUser(servers[0].url, userId, servers[0].accessToken)
154 await checkHook('action:api.user.unblocked')
157 it('Should run action:api.user.updated', async function () {
158 await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 })
160 await checkHook('action:api.user.updated')
163 it('Should run action:api.user.deleted', async function () {
164 await removeUser(servers[0].url, userId, servers[0].accessToken)
166 await checkHook('action:api.user.deleted')
170 describe('Playlist hooks', function () {
171 let playlistId: number
174 before(async function () {
176 const { id } = await servers[0].playlistsCommand.create({
178 displayName: 'My playlist',
179 privacy: VideoPlaylistPrivacy.PRIVATE
186 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' })
187 videoId = res.body.video.id
191 it('Should run action:api.video-playlist-element.created', async function () {
192 await servers[0].playlistsCommand.addElement({ playlistId, attributes: { videoId } })
194 await checkHook('action:api.video-playlist-element.created')
198 after(async function () {
199 await cleanupTests(servers)