]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' | |
5 | import { | |
6 | addVideoCommentReply, | |
7 | addVideoCommentThread, | |
8 | addVideoInPlaylist, | |
9 | blockUser, | |
10 | createUser, | |
11 | createVideoPlaylist, | |
12 | deleteVideoComment, | |
13 | PluginsCommand, | |
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 servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() }) | |
51 | ||
52 | killallServers([ servers[0] ]) | |
53 | ||
54 | await reRunServer(servers[0], { | |
55 | live: { | |
56 | enabled: true | |
57 | } | |
58 | }) | |
59 | }) | |
60 | ||
61 | describe('Application hooks', function () { | |
62 | it('Should run action:application.listening', async function () { | |
63 | await checkHook('action:application.listening') | |
64 | }) | |
65 | }) | |
66 | ||
67 | describe('Videos hooks', function () { | |
68 | ||
69 | it('Should run action:api.video.uploaded', async function () { | |
70 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) | |
71 | videoUUID = res.body.video.uuid | |
72 | ||
73 | await checkHook('action:api.video.uploaded') | |
74 | }) | |
75 | ||
76 | it('Should run action:api.video.updated', async function () { | |
77 | await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' }) | |
78 | ||
79 | await checkHook('action:api.video.updated') | |
80 | }) | |
81 | ||
82 | it('Should run action:api.video.viewed', async function () { | |
83 | await viewVideo(servers[0].url, videoUUID) | |
84 | ||
85 | await checkHook('action:api.video.viewed') | |
86 | }) | |
87 | }) | |
88 | ||
89 | describe('Live hooks', function () { | |
90 | ||
91 | it('Should run action:api.live-video.created', async function () { | |
92 | const attributes = { | |
93 | name: 'live', | |
94 | privacy: VideoPrivacy.PUBLIC, | |
95 | channelId: servers[0].videoChannel.id | |
96 | } | |
97 | ||
98 | await servers[0].liveCommand.create({ fields: attributes }) | |
99 | ||
100 | await checkHook('action:api.live-video.created') | |
101 | }) | |
102 | }) | |
103 | ||
104 | describe('Comments hooks', function () { | |
105 | it('Should run action:api.video-thread.created', async function () { | |
106 | const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread') | |
107 | threadId = res.body.comment.id | |
108 | ||
109 | await checkHook('action:api.video-thread.created') | |
110 | }) | |
111 | ||
112 | it('Should run action:api.video-comment-reply.created', async function () { | |
113 | await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply') | |
114 | ||
115 | await checkHook('action:api.video-comment-reply.created') | |
116 | }) | |
117 | ||
118 | it('Should run action:api.video-comment.deleted', async function () { | |
119 | await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) | |
120 | ||
121 | await checkHook('action:api.video-comment.deleted') | |
122 | }) | |
123 | }) | |
124 | ||
125 | describe('Users hooks', function () { | |
126 | let userId: number | |
127 | ||
128 | it('Should run action:api.user.registered', async function () { | |
129 | await registerUser(servers[0].url, 'registered_user', 'super_password') | |
130 | ||
131 | await checkHook('action:api.user.registered') | |
132 | }) | |
133 | ||
134 | it('Should run action:api.user.created', async function () { | |
135 | const res = await createUser({ | |
136 | url: servers[0].url, | |
137 | accessToken: servers[0].accessToken, | |
138 | username: 'created_user', | |
139 | password: 'super_password' | |
140 | }) | |
141 | userId = res.body.user.id | |
142 | ||
143 | await checkHook('action:api.user.created') | |
144 | }) | |
145 | ||
146 | it('Should run action:api.user.oauth2-got-token', async function () { | |
147 | await userLogin(servers[0], { username: 'created_user', password: 'super_password' }) | |
148 | ||
149 | await checkHook('action:api.user.oauth2-got-token') | |
150 | }) | |
151 | ||
152 | it('Should run action:api.user.blocked', async function () { | |
153 | await blockUser(servers[0].url, userId, servers[0].accessToken) | |
154 | ||
155 | await checkHook('action:api.user.blocked') | |
156 | }) | |
157 | ||
158 | it('Should run action:api.user.unblocked', async function () { | |
159 | await unblockUser(servers[0].url, userId, servers[0].accessToken) | |
160 | ||
161 | await checkHook('action:api.user.unblocked') | |
162 | }) | |
163 | ||
164 | it('Should run action:api.user.updated', async function () { | |
165 | await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 }) | |
166 | ||
167 | await checkHook('action:api.user.updated') | |
168 | }) | |
169 | ||
170 | it('Should run action:api.user.deleted', async function () { | |
171 | await removeUser(servers[0].url, userId, servers[0].accessToken) | |
172 | ||
173 | await checkHook('action:api.user.deleted') | |
174 | }) | |
175 | }) | |
176 | ||
177 | describe('Playlist hooks', function () { | |
178 | let playlistId: number | |
179 | let videoId: number | |
180 | ||
181 | before(async function () { | |
182 | { | |
183 | const res = await createVideoPlaylist({ | |
184 | url: servers[0].url, | |
185 | token: servers[0].accessToken, | |
186 | playlistAttrs: { | |
187 | displayName: 'My playlist', | |
188 | privacy: VideoPlaylistPrivacy.PRIVATE | |
189 | } | |
190 | }) | |
191 | playlistId = res.body.videoPlaylist.id | |
192 | } | |
193 | ||
194 | { | |
195 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' }) | |
196 | videoId = res.body.video.id | |
197 | } | |
198 | }) | |
199 | ||
200 | it('Should run action:api.video-playlist-element.created', async function () { | |
201 | await addVideoInPlaylist({ | |
202 | url: servers[0].url, | |
203 | token: servers[0].accessToken, | |
204 | playlistId, | |
205 | elementAttrs: { videoId } | |
206 | }) | |
207 | ||
208 | await checkHook('action:api.video-playlist-element.created') | |
209 | }) | |
210 | }) | |
211 | ||
212 | after(async function () { | |
213 | await cleanupTests(servers) | |
214 | }) | |
215 | }) |