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