1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
14 setAccessTokensToServers,
15 setDefaultVideoChannel,
22 } from '../../../shared/extra-utils'
25 flushAndRunMultipleServers,
30 } from '../../../shared/extra-utils/server/servers'
32 describe('Test plugin action hooks', function () {
33 let servers: ServerInfo[]
37 function checkHook (hook: ServerHookName) {
38 return waitUntilLog(servers[0], 'Run hook ' + hook)
41 before(async function () {
44 servers = await flushAndRunMultipleServers(2)
45 await setAccessTokensToServers(servers)
46 await setDefaultVideoChannel(servers)
48 await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() })
50 killallServers([ servers[0] ])
52 await reRunServer(servers[0], {
59 describe('Application hooks', function () {
60 it('Should run action:application.listening', async function () {
61 await checkHook('action:application.listening')
65 describe('Videos hooks', function () {
67 it('Should run action:api.video.uploaded', async function () {
68 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
69 videoUUID = res.body.video.uuid
71 await checkHook('action:api.video.uploaded')
74 it('Should run action:api.video.updated', async function () {
75 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
77 await checkHook('action:api.video.updated')
80 it('Should run action:api.video.viewed', async function () {
81 await viewVideo(servers[0].url, videoUUID)
83 await checkHook('action:api.video.viewed')
87 describe('Live hooks', function () {
89 it('Should run action:api.live-video.created', async function () {
92 privacy: VideoPrivacy.PUBLIC,
93 channelId: servers[0].videoChannel.id
96 await servers[0].liveCommand.create({ fields: attributes })
98 await checkHook('action:api.live-video.created')
102 describe('Comments hooks', function () {
103 it('Should run action:api.video-thread.created', async function () {
104 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
105 threadId = res.body.comment.id
107 await checkHook('action:api.video-thread.created')
110 it('Should run action:api.video-comment-reply.created', async function () {
111 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply')
113 await checkHook('action:api.video-comment-reply.created')
116 it('Should run action:api.video-comment.deleted', async function () {
117 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
119 await checkHook('action:api.video-comment.deleted')
123 describe('Users hooks', function () {
126 it('Should run action:api.user.registered', async function () {
127 await registerUser(servers[0].url, 'registered_user', 'super_password')
129 await checkHook('action:api.user.registered')
132 it('Should run action:api.user.created', async function () {
133 const res = await createUser({
135 accessToken: servers[0].accessToken,
136 username: 'created_user',
137 password: 'super_password'
139 userId = res.body.user.id
141 await checkHook('action:api.user.created')
144 it('Should run action:api.user.oauth2-got-token', async function () {
145 await userLogin(servers[0], { username: 'created_user', password: 'super_password' })
147 await checkHook('action:api.user.oauth2-got-token')
150 it('Should run action:api.user.blocked', async function () {
151 await blockUser(servers[0].url, userId, servers[0].accessToken)
153 await checkHook('action:api.user.blocked')
156 it('Should run action:api.user.unblocked', async function () {
157 await unblockUser(servers[0].url, userId, servers[0].accessToken)
159 await checkHook('action:api.user.unblocked')
162 it('Should run action:api.user.updated', async function () {
163 await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 })
165 await checkHook('action:api.user.updated')
168 it('Should run action:api.user.deleted', async function () {
169 await removeUser(servers[0].url, userId, servers[0].accessToken)
171 await checkHook('action:api.user.deleted')
175 describe('Playlist hooks', function () {
176 let playlistId: number
179 before(async function () {
181 const { id } = await servers[0].playlistsCommand.create({
183 displayName: 'My playlist',
184 privacy: VideoPlaylistPrivacy.PRIVATE
191 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' })
192 videoId = res.body.video.id
196 it('Should run action:api.video-playlist-element.created', async function () {
197 await servers[0].playlistsCommand.addElement({ playlistId, attributes: { videoId } })
199 await checkHook('action:api.video-playlist-element.created')
203 after(async function () {
204 await cleanupTests(servers)