aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/action-hooks.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-12-06 15:59:12 +0100
committerChocobozzz <me@florianbigard.com>2019-12-06 15:59:12 +0100
commit6f3fe96f4003fd9ad198cdf0ee5a47b32e9e6568 (patch)
treea3f1f541abec41abee96df9960cbe2b2a6c3ba86 /server/tests/plugins/action-hooks.ts
parent349be1eaa9a61b2e2acaa24db58acb95774c0d20 (diff)
downloadPeerTube-6f3fe96f4003fd9ad198cdf0ee5a47b32e9e6568.tar.gz
PeerTube-6f3fe96f4003fd9ad198cdf0ee5a47b32e9e6568.tar.zst
PeerTube-6f3fe96f4003fd9ad198cdf0ee5a47b32e9e6568.zip
Add action hooks to user routes
Diffstat (limited to 'server/tests/plugins/action-hooks.ts')
-rw-r--r--server/tests/plugins/action-hooks.ts125
1 files changed, 92 insertions, 33 deletions
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts
index e28732cac..510ec3151 100644
--- a/server/tests/plugins/action-hooks.ts
+++ b/server/tests/plugins/action-hooks.ts
@@ -5,19 +5,26 @@ import 'mocha'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
8 flushAndRunServer, killallServers, reRunServer, 8 killallServers,
9 reRunServer,
9 ServerInfo, 10 ServerInfo,
10 waitUntilLog 11 waitUntilLog
11} from '../../../shared/extra-utils/server/servers' 12} from '../../../shared/extra-utils/server/servers'
12import { 13import {
13 addVideoCommentReply, 14 addVideoCommentReply,
14 addVideoCommentThread, deleteVideoComment, 15 addVideoCommentThread,
16 blockUser,
17 createUser,
18 deleteVideoComment,
15 getPluginTestPath, 19 getPluginTestPath,
16 installPlugin, removeVideo, 20 installPlugin, login,
21 registerUser, removeUser,
17 setAccessTokensToServers, 22 setAccessTokensToServers,
23 unblockUser, updateUser,
18 updateVideo, 24 updateVideo,
19 uploadVideo, 25 uploadVideo,
20 viewVideo 26 viewVideo,
27 userLogin
21} from '../../../shared/extra-utils' 28} from '../../../shared/extra-utils'
22 29
23const expect = chai.expect 30const expect = chai.expect
@@ -48,52 +55,104 @@ describe('Test plugin action hooks', function () {
48 await reRunServer(servers[0]) 55 await reRunServer(servers[0])
49 }) 56 })
50 57
51 it('Should run action:application.listening', async function () { 58 describe('Application hooks', function () {
52 await checkHook('action:application.listening') 59 it('Should run action:application.listening', async function () {
60 await checkHook('action:application.listening')
61 })
53 }) 62 })
54 63
55 it('Should run action:api.video.uploaded', async function () { 64 describe('Videos hooks', function () {
56 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) 65 it('Should run action:api.video.uploaded', async function () {
57 videoUUID = res.body.video.uuid 66 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
67 videoUUID = res.body.video.uuid
58 68
59 await checkHook('action:api.video.uploaded') 69 await checkHook('action:api.video.uploaded')
60 }) 70 })
61 71
62 it('Should run action:api.video.updated', async function () { 72 it('Should run action:api.video.updated', async function () {
63 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' }) 73 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' })
64 74
65 await checkHook('action:api.video.updated') 75 await checkHook('action:api.video.updated')
66 }) 76 })
67 77
68 it('Should run action:api.video.viewed', async function () { 78 it('Should run action:api.video.viewed', async function () {
69 await viewVideo(servers[0].url, videoUUID) 79 await viewVideo(servers[0].url, videoUUID)
70 80
71 await checkHook('action:api.video.viewed') 81 await checkHook('action:api.video.viewed')
82 })
72 }) 83 })
73 84
74 it('Should run action:api.video-thread.created', async function () { 85 describe('Comments hooks', function () {
75 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread') 86 it('Should run action:api.video-thread.created', async function () {
76 threadId = res.body.comment.id 87 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
88 threadId = res.body.comment.id
77 89
78 await checkHook('action:api.video-thread.created') 90 await checkHook('action:api.video-thread.created')
79 }) 91 })
80 92
81 it('Should run action:api.video-comment-reply.created', async function () { 93 it('Should run action:api.video-comment-reply.created', async function () {
82 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply') 94 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply')
83 95
84 await checkHook('action:api.video-comment-reply.created') 96 await checkHook('action:api.video-comment-reply.created')
85 }) 97 })
86 98
87 it('Should run action:api.video-comment.deleted', async function () { 99 it('Should run action:api.video-comment.deleted', async function () {
88 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) 100 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
89 101
90 await checkHook('action:api.video-comment.deleted') 102 await checkHook('action:api.video-comment.deleted')
103 })
91 }) 104 })
92 105
93 it('Should run action:api.video.deleted', async function () { 106 describe('Users hooks', function () {
94 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) 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')
95 111
96 await checkHook('action:api.video.deleted') 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 })
97 }) 156 })
98 157
99 after(async function () { 158 after(async function () {