1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
6 flushAndRunMultipleServers,
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
16 } from '@shared/extra-utils'
17 import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
19 describe('Test plugin action hooks', function () {
20 let servers: ServerInfo[]
24 function checkHook (hook: ServerHookName) {
25 return servers[0].serversCommand.waitUntilLog('Run hook ' + hook)
28 before(async function () {
31 servers = await flushAndRunMultipleServers(2)
32 await setAccessTokensToServers(servers)
33 await setDefaultVideoChannel(servers)
35 await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() })
37 await killallServers([ servers[0] ])
39 await reRunServer(servers[0], {
46 describe('Application hooks', function () {
47 it('Should run action:application.listening', async function () {
48 await checkHook('action:application.listening')
52 describe('Videos hooks', function () {
54 it('Should run action:api.video.uploaded', async function () {
55 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
56 videoUUID = res.body.video.uuid
58 await checkHook('action:api.video.uploaded')
61 it('Should run action:api.video.updated', async function () {
62 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
64 await checkHook('action:api.video.updated')
67 it('Should run action:api.video.viewed', async function () {
68 await viewVideo(servers[0].url, videoUUID)
70 await checkHook('action:api.video.viewed')
74 describe('Live hooks', function () {
76 it('Should run action:api.live-video.created', async function () {
79 privacy: VideoPrivacy.PUBLIC,
80 channelId: servers[0].videoChannel.id
83 await servers[0].liveCommand.create({ fields: attributes })
85 await checkHook('action:api.live-video.created')
89 describe('Comments hooks', function () {
90 it('Should run action:api.video-thread.created', async function () {
91 const created = await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'thread' })
94 await checkHook('action:api.video-thread.created')
97 it('Should run action:api.video-comment-reply.created', async function () {
98 await servers[0].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
100 await checkHook('action:api.video-comment-reply.created')
103 it('Should run action:api.video-comment.deleted', async function () {
104 await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId: threadId })
106 await checkHook('action:api.video-comment.deleted')
110 describe('Users hooks', function () {
113 it('Should run action:api.user.registered', async function () {
114 await servers[0].usersCommand.register({ username: 'registered_user' })
116 await checkHook('action:api.user.registered')
119 it('Should run action:api.user.created', async function () {
120 const user = await servers[0].usersCommand.create({ username: 'created_user' })
123 await checkHook('action:api.user.created')
126 it('Should run action:api.user.oauth2-got-token', async function () {
127 await servers[0].loginCommand.getAccessToken('created_user', 'super_password')
129 await checkHook('action:api.user.oauth2-got-token')
132 it('Should run action:api.user.blocked', async function () {
133 await servers[0].usersCommand.banUser({ userId })
135 await checkHook('action:api.user.blocked')
138 it('Should run action:api.user.unblocked', async function () {
139 await servers[0].usersCommand.unbanUser({ userId })
141 await checkHook('action:api.user.unblocked')
144 it('Should run action:api.user.updated', async function () {
145 await servers[0].usersCommand.update({ userId, videoQuota: 50 })
147 await checkHook('action:api.user.updated')
150 it('Should run action:api.user.deleted', async function () {
151 await servers[0].usersCommand.remove({ userId })
153 await checkHook('action:api.user.deleted')
157 describe('Playlist hooks', function () {
158 let playlistId: number
161 before(async function () {
163 const { id } = await servers[0].playlistsCommand.create({
165 displayName: 'My playlist',
166 privacy: VideoPlaylistPrivacy.PRIVATE
173 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' })
174 videoId = res.body.video.id
178 it('Should run action:api.video-playlist-element.created', async function () {
179 await servers[0].playlistsCommand.addElement({ playlistId, attributes: { videoId } })
181 await checkHook('action:api.video-playlist-element.created')
185 after(async function () {
186 await cleanupTests(servers)