1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
19 } from '../../../shared/extra-utils'
22 flushAndRunMultipleServers,
27 } from '../../../shared/extra-utils/server/servers'
29 describe('Test plugin action hooks', function () {
30 let servers: ServerInfo[]
34 function checkHook (hook: ServerHookName) {
35 return waitUntilLog(servers[0], 'Run hook ' + hook)
38 before(async function () {
41 servers = await flushAndRunMultipleServers(2)
42 await setAccessTokensToServers(servers)
43 await setDefaultVideoChannel(servers)
45 await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() })
47 killallServers([ servers[0] ])
49 await reRunServer(servers[0], {
56 describe('Application hooks', function () {
57 it('Should run action:application.listening', async function () {
58 await checkHook('action:application.listening')
62 describe('Videos hooks', function () {
64 it('Should run action:api.video.uploaded', async function () {
65 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
66 videoUUID = res.body.video.uuid
68 await checkHook('action:api.video.uploaded')
71 it('Should run action:api.video.updated', async function () {
72 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
74 await checkHook('action:api.video.updated')
77 it('Should run action:api.video.viewed', async function () {
78 await viewVideo(servers[0].url, videoUUID)
80 await checkHook('action:api.video.viewed')
84 describe('Live hooks', function () {
86 it('Should run action:api.live-video.created', async function () {
89 privacy: VideoPrivacy.PUBLIC,
90 channelId: servers[0].videoChannel.id
93 await servers[0].liveCommand.create({ fields: attributes })
95 await checkHook('action:api.live-video.created')
99 describe('Comments hooks', function () {
100 it('Should run action:api.video-thread.created', async function () {
101 const created = await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'thread' })
102 threadId = created.id
104 await checkHook('action:api.video-thread.created')
107 it('Should run action:api.video-comment-reply.created', async function () {
108 await servers[0].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
110 await checkHook('action:api.video-comment-reply.created')
113 it('Should run action:api.video-comment.deleted', async function () {
114 await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId: threadId })
116 await checkHook('action:api.video-comment.deleted')
120 describe('Users hooks', function () {
123 it('Should run action:api.user.registered', async function () {
124 await registerUser(servers[0].url, 'registered_user', 'super_password')
126 await checkHook('action:api.user.registered')
129 it('Should run action:api.user.created', async function () {
130 const res = await createUser({
132 accessToken: servers[0].accessToken,
133 username: 'created_user',
134 password: 'super_password'
136 userId = res.body.user.id
138 await checkHook('action:api.user.created')
141 it('Should run action:api.user.oauth2-got-token', async function () {
142 await userLogin(servers[0], { username: 'created_user', password: 'super_password' })
144 await checkHook('action:api.user.oauth2-got-token')
147 it('Should run action:api.user.blocked', async function () {
148 await blockUser(servers[0].url, userId, servers[0].accessToken)
150 await checkHook('action:api.user.blocked')
153 it('Should run action:api.user.unblocked', async function () {
154 await unblockUser(servers[0].url, userId, servers[0].accessToken)
156 await checkHook('action:api.user.unblocked')
159 it('Should run action:api.user.updated', async function () {
160 await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 })
162 await checkHook('action:api.user.updated')
165 it('Should run action:api.user.deleted', async function () {
166 await removeUser(servers[0].url, userId, servers[0].accessToken)
168 await checkHook('action:api.user.deleted')
172 describe('Playlist hooks', function () {
173 let playlistId: number
176 before(async function () {
178 const { id } = await servers[0].playlistsCommand.create({
180 displayName: 'My playlist',
181 privacy: VideoPlaylistPrivacy.PRIVATE
188 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' })
189 videoId = res.body.video.id
193 it('Should run action:api.video-playlist-element.created', async function () {
194 await servers[0].playlistsCommand.addElement({ playlistId, attributes: { videoId } })
196 await checkHook('action:api.video-playlist-element.created')
200 after(async function () {
201 await cleanupTests(servers)