]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/plugins/action-hooks.ts
emit more specific status codes on video upload (#3423)
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / action-hooks.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
9b474844 2
9b474844 3import 'mocha'
3cabf353 4import { ServerHookName, VideoPrivacy } from '@shared/models'
89cd1275
C
5import {
6 addVideoCommentReply,
6f3fe96f
C
7 addVideoCommentThread,
8 blockUser,
3cabf353 9 createLive,
6f3fe96f
C
10 createUser,
11 deleteVideoComment,
89cd1275 12 getPluginTestPath,
a1587156
C
13 installPlugin,
14 registerUser,
15 removeUser,
89cd1275 16 setAccessTokensToServers,
3cabf353 17 setDefaultVideoChannel,
a1587156
C
18 unblockUser,
19 updateUser,
89cd1275
C
20 updateVideo,
21 uploadVideo,
a1587156
C
22 userLogin,
23 viewVideo
89cd1275 24} from '../../../shared/extra-utils'
3cabf353
C
25import {
26 cleanupTests,
27 flushAndRunMultipleServers,
28 killallServers,
29 reRunServer,
30 ServerInfo,
31 waitUntilLog
32} from '../../../shared/extra-utils/server/servers'
9b474844 33
09071200 34describe('Test plugin action hooks', function () {
89cd1275
C
35 let servers: ServerInfo[]
36 let videoUUID: string
37 let threadId: number
38
3cabf353 39 function checkHook (hook: ServerHookName) {
89cd1275
C
40 return waitUntilLog(servers[0], 'Run hook ' + hook)
41 }
9b474844
C
42
43 before(async function () {
44 this.timeout(30000)
9b474844 45
89cd1275
C
46 servers = await flushAndRunMultipleServers(2)
47 await setAccessTokensToServers(servers)
3cabf353 48 await setDefaultVideoChannel(servers)
89cd1275
C
49
50 await installPlugin({
51 url: servers[0].url,
52 accessToken: servers[0].accessToken,
53 path: getPluginTestPath()
54 })
55
587568e1 56 killallServers([ servers[0] ])
89cd1275 57
3cabf353
C
58 await reRunServer(servers[0], {
59 live: {
60 enabled: true
61 }
62 })
9b474844
C
63 })
64
6f3fe96f
C
65 describe('Application hooks', function () {
66 it('Should run action:application.listening', async function () {
67 await checkHook('action:application.listening')
68 })
89cd1275
C
69 })
70
6f3fe96f
C
71 describe('Videos hooks', function () {
72 it('Should run action:api.video.uploaded', async function () {
73 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
74 videoUUID = res.body.video.uuid
89cd1275 75
6f3fe96f
C
76 await checkHook('action:api.video.uploaded')
77 })
89cd1275 78
6f3fe96f
C
79 it('Should run action:api.video.updated', async function () {
80 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
89cd1275 81
6f3fe96f
C
82 await checkHook('action:api.video.updated')
83 })
89cd1275 84
6f3fe96f
C
85 it('Should run action:api.video.viewed', async function () {
86 await viewVideo(servers[0].url, videoUUID)
89cd1275 87
6f3fe96f
C
88 await checkHook('action:api.video.viewed')
89 })
89cd1275
C
90 })
91
3cabf353
C
92 describe('Live hooks', function () {
93
94 it('Should run action:api.live-video.created', async function () {
95 const attributes = {
96 name: 'live',
97 privacy: VideoPrivacy.PUBLIC,
98 channelId: servers[0].videoChannel.id
99 }
100
101 await createLive(servers[0].url, servers[0].accessToken, attributes)
102
103 await checkHook('action:api.live-video.created')
104 })
105 })
106
6f3fe96f
C
107 describe('Comments hooks', function () {
108 it('Should run action:api.video-thread.created', async function () {
109 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
110 threadId = res.body.comment.id
89cd1275 111
6f3fe96f
C
112 await checkHook('action:api.video-thread.created')
113 })
89cd1275 114
6f3fe96f
C
115 it('Should run action:api.video-comment-reply.created', async function () {
116 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply')
89cd1275 117
6f3fe96f
C
118 await checkHook('action:api.video-comment-reply.created')
119 })
89cd1275 120
6f3fe96f
C
121 it('Should run action:api.video-comment.deleted', async function () {
122 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
89cd1275 123
6f3fe96f
C
124 await checkHook('action:api.video-comment.deleted')
125 })
89cd1275
C
126 })
127
6f3fe96f
C
128 describe('Users hooks', function () {
129 let userId: number
130
131 it('Should run action:api.user.registered', async function () {
132 await registerUser(servers[0].url, 'registered_user', 'super_password')
89cd1275 133
6f3fe96f
C
134 await checkHook('action:api.user.registered')
135 })
136
137 it('Should run action:api.user.created', async function () {
138 const res = await createUser({
139 url: servers[0].url,
140 accessToken: servers[0].accessToken,
141 username: 'created_user',
142 password: 'super_password'
143 })
144 userId = res.body.user.id
145
146 await checkHook('action:api.user.created')
147 })
148
149 it('Should run action:api.user.oauth2-got-token', async function () {
150 await userLogin(servers[0], { username: 'created_user', password: 'super_password' })
151
152 await checkHook('action:api.user.oauth2-got-token')
153 })
154
155 it('Should run action:api.user.blocked', async function () {
156 await blockUser(servers[0].url, userId, servers[0].accessToken)
157
158 await checkHook('action:api.user.blocked')
159 })
160
161 it('Should run action:api.user.unblocked', async function () {
162 await unblockUser(servers[0].url, userId, servers[0].accessToken)
163
164 await checkHook('action:api.user.unblocked')
165 })
166
167 it('Should run action:api.user.updated', async function () {
168 await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 })
169
170 await checkHook('action:api.user.updated')
171 })
172
173 it('Should run action:api.user.deleted', async function () {
174 await removeUser(servers[0].url, userId, servers[0].accessToken)
175
176 await checkHook('action:api.user.deleted')
177 })
9b474844
C
178 })
179
180 after(async function () {
89cd1275 181 await cleanupTests(servers)
9b474844
C
182 })
183})