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