1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
6 flushAndRunMultipleServers,
11 setAccessTokensToServers,
12 setDefaultVideoChannel
13 } from '@shared/extra-utils'
14 import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
16 describe('Test plugin action hooks', function () {
17 let servers: ServerInfo[]
21 function checkHook (hook: ServerHookName) {
22 return servers[0].serversCommand.waitUntilLog('Run hook ' + hook)
25 before(async function () {
28 servers = await flushAndRunMultipleServers(2)
29 await setAccessTokensToServers(servers)
30 await setDefaultVideoChannel(servers)
32 await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() })
34 await killallServers([ servers[0] ])
36 await reRunServer(servers[0], {
43 describe('Application hooks', function () {
44 it('Should run action:application.listening', async function () {
45 await checkHook('action:application.listening')
49 describe('Videos hooks', function () {
51 it('Should run action:api.video.uploaded', async function () {
52 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } })
55 await checkHook('action:api.video.uploaded')
58 it('Should run action:api.video.updated', async function () {
59 await servers[0].videosCommand.update({ id: videoUUID, attributes: { name: 'video updated' } })
61 await checkHook('action:api.video.updated')
64 it('Should run action:api.video.viewed', async function () {
65 await servers[0].videosCommand.view({ id: videoUUID })
67 await checkHook('action:api.video.viewed')
71 describe('Live hooks', function () {
73 it('Should run action:api.live-video.created', async function () {
76 privacy: VideoPrivacy.PUBLIC,
77 channelId: servers[0].videoChannel.id
80 await servers[0].liveCommand.create({ fields: attributes })
82 await checkHook('action:api.live-video.created')
86 describe('Comments hooks', function () {
87 it('Should run action:api.video-thread.created', async function () {
88 const created = await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'thread' })
91 await checkHook('action:api.video-thread.created')
94 it('Should run action:api.video-comment-reply.created', async function () {
95 await servers[0].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
97 await checkHook('action:api.video-comment-reply.created')
100 it('Should run action:api.video-comment.deleted', async function () {
101 await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId: threadId })
103 await checkHook('action:api.video-comment.deleted')
107 describe('Users hooks', function () {
110 it('Should run action:api.user.registered', async function () {
111 await servers[0].usersCommand.register({ username: 'registered_user' })
113 await checkHook('action:api.user.registered')
116 it('Should run action:api.user.created', async function () {
117 const user = await servers[0].usersCommand.create({ username: 'created_user' })
120 await checkHook('action:api.user.created')
123 it('Should run action:api.user.oauth2-got-token', async function () {
124 await servers[0].loginCommand.getAccessToken('created_user', 'super_password')
126 await checkHook('action:api.user.oauth2-got-token')
129 it('Should run action:api.user.blocked', async function () {
130 await servers[0].usersCommand.banUser({ userId })
132 await checkHook('action:api.user.blocked')
135 it('Should run action:api.user.unblocked', async function () {
136 await servers[0].usersCommand.unbanUser({ userId })
138 await checkHook('action:api.user.unblocked')
141 it('Should run action:api.user.updated', async function () {
142 await servers[0].usersCommand.update({ userId, videoQuota: 50 })
144 await checkHook('action:api.user.updated')
147 it('Should run action:api.user.deleted', async function () {
148 await servers[0].usersCommand.remove({ userId })
150 await checkHook('action:api.user.deleted')
154 describe('Playlist hooks', function () {
155 let playlistId: number
158 before(async function () {
160 const { id } = await servers[0].playlistsCommand.create({
162 displayName: 'My playlist',
163 privacy: VideoPlaylistPrivacy.PRIVATE
170 const { id } = await servers[0].videosCommand.upload({ attributes: { name: 'my super name' } })
175 it('Should run action:api.video-playlist-element.created', async function () {
176 await servers[0].playlistsCommand.addElement({ playlistId, attributes: { videoId } })
178 await checkHook('action:api.video-playlist-element.created')
182 after(async function () {
183 await cleanupTests(servers)