]>
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 C |
9 | blockUser, |
10 | createUser, | |
e2e0b645 | 11 | createVideoPlaylist, |
6f3fe96f | 12 | deleteVideoComment, |
ae2abfd3 | 13 | PluginsCommand, |
a1587156 C |
14 | registerUser, |
15 | removeUser, | |
89cd1275 | 16 | setAccessTokensToServers, |
3cabf353 | 17 | setDefaultVideoChannel, |
a1587156 C |
18 | unblockUser, |
19 | updateUser, | |
89cd1275 C |
20 | updateVideo, |
21 | uploadVideo, | |
a1587156 C |
22 | userLogin, |
23 | viewVideo | |
89cd1275 | 24 | } from '../../../shared/extra-utils' |
3cabf353 C |
25 | import { |
26 | cleanupTests, | |
27 | flushAndRunMultipleServers, | |
28 | killallServers, | |
29 | reRunServer, | |
30 | ServerInfo, | |
31 | waitUntilLog | |
32 | } from '../../../shared/extra-utils/server/servers' | |
9b474844 | 33 | |
09071200 | 34 | describe('Test plugin action hooks', function () { |
89cd1275 C |
35 | let servers: ServerInfo[] |
36 | let videoUUID: string | |
37 | let threadId: number | |
38 | ||
3cabf353 | 39 | function checkHook (hook: ServerHookName) { |
89cd1275 C |
40 | return waitUntilLog(servers[0], 'Run hook ' + hook) |
41 | } | |
9b474844 C |
42 | |
43 | before(async function () { | |
44 | this.timeout(30000) | |
9b474844 | 45 | |
89cd1275 C |
46 | servers = await flushAndRunMultipleServers(2) |
47 | await setAccessTokensToServers(servers) | |
3cabf353 | 48 | await setDefaultVideoChannel(servers) |
89cd1275 | 49 | |
ae2abfd3 | 50 | await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() }) |
89cd1275 | 51 | |
587568e1 | 52 | killallServers([ servers[0] ]) |
89cd1275 | 53 | |
3cabf353 C |
54 | await reRunServer(servers[0], { |
55 | live: { | |
56 | enabled: true | |
57 | } | |
58 | }) | |
9b474844 C |
59 | }) |
60 | ||
6f3fe96f C |
61 | describe('Application hooks', function () { |
62 | it('Should run action:application.listening', async function () { | |
63 | await checkHook('action:application.listening') | |
64 | }) | |
89cd1275 C |
65 | }) |
66 | ||
6f3fe96f | 67 | describe('Videos hooks', function () { |
e2e0b645 | 68 | |
6f3fe96f C |
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 | |
89cd1275 | 72 | |
6f3fe96f C |
73 | await checkHook('action:api.video.uploaded') |
74 | }) | |
89cd1275 | 75 | |
6f3fe96f C |
76 | it('Should run action:api.video.updated', async function () { |
77 | await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' }) | |
89cd1275 | 78 | |
6f3fe96f C |
79 | await checkHook('action:api.video.updated') |
80 | }) | |
89cd1275 | 81 | |
6f3fe96f C |
82 | it('Should run action:api.video.viewed', async function () { |
83 | await viewVideo(servers[0].url, videoUUID) | |
89cd1275 | 84 | |
6f3fe96f C |
85 | await checkHook('action:api.video.viewed') |
86 | }) | |
89cd1275 C |
87 | }) |
88 | ||
3cabf353 C |
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 | ||
04aed767 | 98 | await servers[0].liveCommand.create({ fields: attributes }) |
3cabf353 C |
99 | |
100 | await checkHook('action:api.live-video.created') | |
101 | }) | |
102 | }) | |
103 | ||
6f3fe96f C |
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 | |
89cd1275 | 108 | |
6f3fe96f C |
109 | await checkHook('action:api.video-thread.created') |
110 | }) | |
89cd1275 | 111 | |
6f3fe96f C |
112 | it('Should run action:api.video-comment-reply.created', async function () { |
113 | await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply') | |
89cd1275 | 114 | |
6f3fe96f C |
115 | await checkHook('action:api.video-comment-reply.created') |
116 | }) | |
89cd1275 | 117 | |
6f3fe96f C |
118 | it('Should run action:api.video-comment.deleted', async function () { |
119 | await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) | |
89cd1275 | 120 | |
6f3fe96f C |
121 | await checkHook('action:api.video-comment.deleted') |
122 | }) | |
89cd1275 C |
123 | }) |
124 | ||
6f3fe96f C |
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') | |
89cd1275 | 130 | |
6f3fe96f C |
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 | }) | |
9b474844 C |
175 | }) |
176 | ||
e2e0b645 | 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 | ||
9b474844 | 212 | after(async function () { |
89cd1275 | 213 | await cleanupTests(servers) |
9b474844 C |
214 | }) |
215 | }) |