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