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