]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { ServerHookName, VideoPrivacy } from '@shared/models' | |
5 | import { | |
6 | addVideoCommentReply, | |
7 | addVideoCommentThread, | |
8 | blockUser, | |
9 | createLive, | |
10 | createUser, | |
11 | deleteVideoComment, | |
12 | getPluginTestPath, | |
13 | installPlugin, | |
14 | registerUser, | |
15 | removeUser, | |
16 | setAccessTokensToServers, | |
17 | setDefaultVideoChannel, | |
18 | unblockUser, | |
19 | updateUser, | |
20 | updateVideo, | |
21 | uploadVideo, | |
22 | userLogin, | |
23 | viewVideo | |
24 | } from '../../../shared/extra-utils' | |
25 | import { | |
26 | cleanupTests, | |
27 | flushAndRunMultipleServers, | |
28 | killallServers, | |
29 | reRunServer, | |
30 | ServerInfo, | |
31 | waitUntilLog | |
32 | } from '../../../shared/extra-utils/server/servers' | |
33 | ||
34 | describe('Test plugin action hooks', function () { | |
35 | let servers: ServerInfo[] | |
36 | let videoUUID: string | |
37 | let threadId: number | |
38 | ||
39 | function checkHook (hook: ServerHookName) { | |
40 | return waitUntilLog(servers[0], 'Run hook ' + hook) | |
41 | } | |
42 | ||
43 | before(async function () { | |
44 | this.timeout(30000) | |
45 | ||
46 | servers = await flushAndRunMultipleServers(2) | |
47 | await setAccessTokensToServers(servers) | |
48 | await setDefaultVideoChannel(servers) | |
49 | ||
50 | await installPlugin({ | |
51 | url: servers[0].url, | |
52 | accessToken: servers[0].accessToken, | |
53 | path: getPluginTestPath() | |
54 | }) | |
55 | ||
56 | killallServers([ servers[0] ]) | |
57 | ||
58 | await reRunServer(servers[0], { | |
59 | live: { | |
60 | enabled: true | |
61 | } | |
62 | }) | |
63 | }) | |
64 | ||
65 | describe('Application hooks', function () { | |
66 | it('Should run action:application.listening', async function () { | |
67 | await checkHook('action:application.listening') | |
68 | }) | |
69 | }) | |
70 | ||
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 | |
75 | ||
76 | await checkHook('action:api.video.uploaded') | |
77 | }) | |
78 | ||
79 | it('Should run action:api.video.updated', async function () { | |
80 | await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' }) | |
81 | ||
82 | await checkHook('action:api.video.updated') | |
83 | }) | |
84 | ||
85 | it('Should run action:api.video.viewed', async function () { | |
86 | await viewVideo(servers[0].url, videoUUID) | |
87 | ||
88 | await checkHook('action:api.video.viewed') | |
89 | }) | |
90 | }) | |
91 | ||
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 | ||
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 | |
111 | ||
112 | await checkHook('action:api.video-thread.created') | |
113 | }) | |
114 | ||
115 | it('Should run action:api.video-comment-reply.created', async function () { | |
116 | await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply') | |
117 | ||
118 | await checkHook('action:api.video-comment-reply.created') | |
119 | }) | |
120 | ||
121 | it('Should run action:api.video-comment.deleted', async function () { | |
122 | await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) | |
123 | ||
124 | await checkHook('action:api.video-comment.deleted') | |
125 | }) | |
126 | }) | |
127 | ||
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') | |
133 | ||
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 | }) | |
178 | }) | |
179 | ||
180 | after(async function () { | |
181 | await cleanupTests(servers) | |
182 | }) | |
183 | }) |