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