diff options
Diffstat (limited to 'server/tests/plugins/filter-hooks.ts')
-rw-r--r-- | server/tests/plugins/filter-hooks.ts | 408 |
1 files changed, 198 insertions, 210 deletions
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 644b41dea..02915f08c 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts | |||
@@ -2,192 +2,152 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels' | ||
6 | import { ServerConfig } from '@shared/models' | ||
7 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
8 | import { | 5 | import { |
9 | addVideoCommentReply, | 6 | cleanupTests, |
10 | addVideoCommentThread, | 7 | createMultipleServers, |
11 | advancedVideoPlaylistSearch, | ||
12 | advancedVideosSearch, | ||
13 | createLive, | ||
14 | createVideoPlaylist, | ||
15 | doubleFollow, | 8 | doubleFollow, |
16 | getAccountVideos, | 9 | FIXTURE_URLS, |
17 | getConfig, | ||
18 | getMyVideos, | ||
19 | getPluginTestPath, | ||
20 | getVideo, | ||
21 | getVideoChannelVideos, | ||
22 | getVideoCommentThreads, | ||
23 | getVideoPlaylist, | ||
24 | getVideosList, | ||
25 | getVideosListPagination, | ||
26 | getVideoThreadComments, | ||
27 | getVideoWithToken, | ||
28 | installPlugin, | ||
29 | makeRawRequest, | 10 | makeRawRequest, |
30 | registerUser, | 11 | PeerTubeServer, |
12 | PluginsCommand, | ||
31 | setAccessTokensToServers, | 13 | setAccessTokensToServers, |
32 | setDefaultVideoChannel, | 14 | setDefaultVideoChannel, |
33 | updateCustomSubConfig, | ||
34 | updateVideo, | ||
35 | uploadVideo, | ||
36 | uploadVideoAndGetId, | ||
37 | waitJobs | 15 | waitJobs |
38 | } from '../../../shared/extra-utils' | 16 | } from '@shared/extra-utils' |
39 | import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' | 17 | import { HttpStatusCode, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' |
40 | import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports' | ||
41 | import { | ||
42 | VideoCommentThreadTree, | ||
43 | VideoDetails, | ||
44 | VideoImport, | ||
45 | VideoImportState, | ||
46 | VideoPlaylist, | ||
47 | VideoPlaylistPrivacy, | ||
48 | VideoPrivacy | ||
49 | } from '../../../shared/models/videos' | ||
50 | 18 | ||
51 | const expect = chai.expect | 19 | const expect = chai.expect |
52 | 20 | ||
53 | describe('Test plugin filter hooks', function () { | 21 | describe('Test plugin filter hooks', function () { |
54 | let servers: ServerInfo[] | 22 | let servers: PeerTubeServer[] |
55 | let videoUUID: string | 23 | let videoUUID: string |
56 | let threadId: number | 24 | let threadId: number |
57 | 25 | ||
58 | before(async function () { | 26 | before(async function () { |
59 | this.timeout(60000) | 27 | this.timeout(60000) |
60 | 28 | ||
61 | servers = await flushAndRunMultipleServers(2) | 29 | servers = await createMultipleServers(2) |
62 | await setAccessTokensToServers(servers) | 30 | await setAccessTokensToServers(servers) |
63 | await setDefaultVideoChannel(servers) | 31 | await setDefaultVideoChannel(servers) |
64 | await doubleFollow(servers[0], servers[1]) | 32 | await doubleFollow(servers[0], servers[1]) |
65 | 33 | ||
66 | await installPlugin({ | 34 | await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() }) |
67 | url: servers[0].url, | 35 | await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) |
68 | accessToken: servers[0].accessToken, | ||
69 | path: getPluginTestPath() | ||
70 | }) | ||
71 | |||
72 | await installPlugin({ | ||
73 | url: servers[0].url, | ||
74 | accessToken: servers[0].accessToken, | ||
75 | path: getPluginTestPath('-filter-translations') | ||
76 | }) | ||
77 | 36 | ||
78 | for (let i = 0; i < 10; i++) { | 37 | for (let i = 0; i < 10; i++) { |
79 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) | 38 | await servers[0].videos.upload({ attributes: { name: 'default video ' + i } }) |
80 | } | 39 | } |
81 | 40 | ||
82 | const res = await getVideosList(servers[0].url) | 41 | const { data } = await servers[0].videos.list() |
83 | videoUUID = res.body.data[0].uuid | 42 | videoUUID = data[0].uuid |
84 | 43 | ||
85 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | 44 | await servers[0].config.updateCustomSubConfig({ |
86 | live: { enabled: true }, | 45 | newConfig: { |
87 | signup: { enabled: true }, | 46 | live: { enabled: true }, |
88 | import: { | 47 | signup: { enabled: true }, |
89 | videos: { | 48 | import: { |
90 | http: { enabled: true }, | 49 | videos: { |
91 | torrent: { enabled: true } | 50 | http: { enabled: true }, |
51 | torrent: { enabled: true } | ||
52 | } | ||
92 | } | 53 | } |
93 | } | 54 | } |
94 | }) | 55 | }) |
95 | }) | 56 | }) |
96 | 57 | ||
97 | it('Should run filter:api.videos.list.params', async function () { | 58 | it('Should run filter:api.videos.list.params', async function () { |
98 | const res = await getVideosListPagination(servers[0].url, 0, 2) | 59 | const { data } = await servers[0].videos.list({ start: 0, count: 2 }) |
99 | 60 | ||
100 | // 2 plugins do +1 to the count parameter | 61 | // 2 plugins do +1 to the count parameter |
101 | expect(res.body.data).to.have.lengthOf(4) | 62 | expect(data).to.have.lengthOf(4) |
102 | }) | 63 | }) |
103 | 64 | ||
104 | it('Should run filter:api.videos.list.result', async function () { | 65 | it('Should run filter:api.videos.list.result', async function () { |
105 | const res = await getVideosListPagination(servers[0].url, 0, 0) | 66 | const { total } = await servers[0].videos.list({ start: 0, count: 0 }) |
106 | 67 | ||
107 | // Plugin do +1 to the total result | 68 | // Plugin do +1 to the total result |
108 | expect(res.body.total).to.equal(11) | 69 | expect(total).to.equal(11) |
109 | }) | 70 | }) |
110 | 71 | ||
111 | it('Should run filter:api.accounts.videos.list.params', async function () { | 72 | it('Should run filter:api.accounts.videos.list.params', async function () { |
112 | const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) | 73 | const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 }) |
113 | 74 | ||
114 | // 1 plugin do +1 to the count parameter | 75 | // 1 plugin do +1 to the count parameter |
115 | expect(res.body.data).to.have.lengthOf(3) | 76 | expect(data).to.have.lengthOf(3) |
116 | }) | 77 | }) |
117 | 78 | ||
118 | it('Should run filter:api.accounts.videos.list.result', async function () { | 79 | it('Should run filter:api.accounts.videos.list.result', async function () { |
119 | const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) | 80 | const { total } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 }) |
120 | 81 | ||
121 | // Plugin do +2 to the total result | 82 | // Plugin do +2 to the total result |
122 | expect(res.body.total).to.equal(12) | 83 | expect(total).to.equal(12) |
123 | }) | 84 | }) |
124 | 85 | ||
125 | it('Should run filter:api.video-channels.videos.list.params', async function () { | 86 | it('Should run filter:api.video-channels.videos.list.params', async function () { |
126 | const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) | 87 | const { data } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 }) |
127 | 88 | ||
128 | // 1 plugin do +3 to the count parameter | 89 | // 1 plugin do +3 to the count parameter |
129 | expect(res.body.data).to.have.lengthOf(5) | 90 | expect(data).to.have.lengthOf(5) |
130 | }) | 91 | }) |
131 | 92 | ||
132 | it('Should run filter:api.video-channels.videos.list.result', async function () { | 93 | it('Should run filter:api.video-channels.videos.list.result', async function () { |
133 | const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) | 94 | const { total } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 }) |
134 | 95 | ||
135 | // Plugin do +3 to the total result | 96 | // Plugin do +3 to the total result |
136 | expect(res.body.total).to.equal(13) | 97 | expect(total).to.equal(13) |
137 | }) | 98 | }) |
138 | 99 | ||
139 | it('Should run filter:api.user.me.videos.list.params', async function () { | 100 | it('Should run filter:api.user.me.videos.list.params', async function () { |
140 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) | 101 | const { data } = await servers[0].videos.listMyVideos({ start: 0, count: 2 }) |
141 | 102 | ||
142 | // 1 plugin do +4 to the count parameter | 103 | // 1 plugin do +4 to the count parameter |
143 | expect(res.body.data).to.have.lengthOf(6) | 104 | expect(data).to.have.lengthOf(6) |
144 | }) | 105 | }) |
145 | 106 | ||
146 | it('Should run filter:api.user.me.videos.list.result', async function () { | 107 | it('Should run filter:api.user.me.videos.list.result', async function () { |
147 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) | 108 | const { total } = await servers[0].videos.listMyVideos({ start: 0, count: 2 }) |
148 | 109 | ||
149 | // Plugin do +4 to the total result | 110 | // Plugin do +4 to the total result |
150 | expect(res.body.total).to.equal(14) | 111 | expect(total).to.equal(14) |
151 | }) | 112 | }) |
152 | 113 | ||
153 | it('Should run filter:api.video.get.result', async function () { | 114 | it('Should run filter:api.video.get.result', async function () { |
154 | const res = await getVideo(servers[0].url, videoUUID) | 115 | const video = await servers[0].videos.get({ id: videoUUID }) |
155 | 116 | expect(video.name).to.contain('<3') | |
156 | expect(res.body.name).to.contain('<3') | ||
157 | }) | 117 | }) |
158 | 118 | ||
159 | it('Should run filter:api.video.upload.accept.result', async function () { | 119 | it('Should run filter:api.video.upload.accept.result', async function () { |
160 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, HttpStatusCode.FORBIDDEN_403) | 120 | await servers[0].videos.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
161 | }) | 121 | }) |
162 | 122 | ||
163 | it('Should run filter:api.live-video.create.accept.result', async function () { | 123 | it('Should run filter:api.live-video.create.accept.result', async function () { |
164 | const attributes = { | 124 | const attributes = { |
165 | name: 'video with bad word', | 125 | name: 'video with bad word', |
166 | privacy: VideoPrivacy.PUBLIC, | 126 | privacy: VideoPrivacy.PUBLIC, |
167 | channelId: servers[0].videoChannel.id | 127 | channelId: servers[0].store.channel.id |
168 | } | 128 | } |
169 | 129 | ||
170 | await createLive(servers[0].url, servers[0].accessToken, attributes, HttpStatusCode.FORBIDDEN_403) | 130 | await servers[0].live.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
171 | }) | 131 | }) |
172 | 132 | ||
173 | it('Should run filter:api.video.pre-import-url.accept.result', async function () { | 133 | it('Should run filter:api.video.pre-import-url.accept.result', async function () { |
174 | const baseAttributes = { | 134 | const attributes = { |
175 | name: 'normal title', | 135 | name: 'normal title', |
176 | privacy: VideoPrivacy.PUBLIC, | 136 | privacy: VideoPrivacy.PUBLIC, |
177 | channelId: servers[0].videoChannel.id, | 137 | channelId: servers[0].store.channel.id, |
178 | targetUrl: getGoodVideoUrl() + 'bad' | 138 | targetUrl: FIXTURE_URLS.goodVideo + 'bad' |
179 | } | 139 | } |
180 | await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) | 140 | await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
181 | }) | 141 | }) |
182 | 142 | ||
183 | it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { | 143 | it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { |
184 | const baseAttributes = { | 144 | const attributes = { |
185 | name: 'bad torrent', | 145 | name: 'bad torrent', |
186 | privacy: VideoPrivacy.PUBLIC, | 146 | privacy: VideoPrivacy.PUBLIC, |
187 | channelId: servers[0].videoChannel.id, | 147 | channelId: servers[0].store.channel.id, |
188 | torrentfile: 'video-720p.torrent' as any | 148 | torrentfile: 'video-720p.torrent' as any |
189 | } | 149 | } |
190 | await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) | 150 | await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
191 | }) | 151 | }) |
192 | 152 | ||
193 | it('Should run filter:api.video.post-import-url.accept.result', async function () { | 153 | it('Should run filter:api.video.post-import-url.accept.result', async function () { |
@@ -196,21 +156,21 @@ describe('Test plugin filter hooks', function () { | |||
196 | let videoImportId: number | 156 | let videoImportId: number |
197 | 157 | ||
198 | { | 158 | { |
199 | const baseAttributes = { | 159 | const attributes = { |
200 | name: 'title with bad word', | 160 | name: 'title with bad word', |
201 | privacy: VideoPrivacy.PUBLIC, | 161 | privacy: VideoPrivacy.PUBLIC, |
202 | channelId: servers[0].videoChannel.id, | 162 | channelId: servers[0].store.channel.id, |
203 | targetUrl: getGoodVideoUrl() | 163 | targetUrl: FIXTURE_URLS.goodVideo |
204 | } | 164 | } |
205 | const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) | 165 | const body = await servers[0].imports.importVideo({ attributes }) |
206 | videoImportId = res.body.id | 166 | videoImportId = body.id |
207 | } | 167 | } |
208 | 168 | ||
209 | await waitJobs(servers) | 169 | await waitJobs(servers) |
210 | 170 | ||
211 | { | 171 | { |
212 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) | 172 | const body = await servers[0].imports.getMyVideoImports() |
213 | const videoImports = res.body.data as VideoImport[] | 173 | const videoImports = body.data |
214 | 174 | ||
215 | const videoImport = videoImports.find(i => i.id === videoImportId) | 175 | const videoImport = videoImports.find(i => i.id === videoImportId) |
216 | 176 | ||
@@ -225,21 +185,20 @@ describe('Test plugin filter hooks', function () { | |||
225 | let videoImportId: number | 185 | let videoImportId: number |
226 | 186 | ||
227 | { | 187 | { |
228 | const baseAttributes = { | 188 | const attributes = { |
229 | name: 'title with bad word', | 189 | name: 'title with bad word', |
230 | privacy: VideoPrivacy.PUBLIC, | 190 | privacy: VideoPrivacy.PUBLIC, |
231 | channelId: servers[0].videoChannel.id, | 191 | channelId: servers[0].store.channel.id, |
232 | torrentfile: 'video-720p.torrent' as any | 192 | torrentfile: 'video-720p.torrent' as any |
233 | } | 193 | } |
234 | const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) | 194 | const body = await servers[0].imports.importVideo({ attributes }) |
235 | videoImportId = res.body.id | 195 | videoImportId = body.id |
236 | } | 196 | } |
237 | 197 | ||
238 | await waitJobs(servers) | 198 | await waitJobs(servers) |
239 | 199 | ||
240 | { | 200 | { |
241 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) | 201 | const { data: videoImports } = await servers[0].imports.getMyVideoImports() |
242 | const videoImports = res.body.data as VideoImport[] | ||
243 | 202 | ||
244 | const videoImport = videoImports.find(i => i.id === videoImportId) | 203 | const videoImport = videoImports.find(i => i.id === videoImportId) |
245 | 204 | ||
@@ -249,60 +208,71 @@ describe('Test plugin filter hooks', function () { | |||
249 | }) | 208 | }) |
250 | 209 | ||
251 | it('Should run filter:api.video-thread.create.accept.result', async function () { | 210 | it('Should run filter:api.video-thread.create.accept.result', async function () { |
252 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', HttpStatusCode.FORBIDDEN_403) | 211 | await servers[0].comments.createThread({ |
212 | videoId: videoUUID, | ||
213 | text: 'comment with bad word', | ||
214 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
215 | }) | ||
253 | }) | 216 | }) |
254 | 217 | ||
255 | it('Should run filter:api.video-comment-reply.create.accept.result', async function () { | 218 | it('Should run filter:api.video-comment-reply.create.accept.result', async function () { |
256 | const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread') | 219 | const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' }) |
257 | threadId = res.body.comment.id | 220 | threadId = created.id |
258 | 221 | ||
259 | await addVideoCommentReply( | 222 | await servers[0].comments.addReply({ |
260 | servers[0].url, | 223 | videoId: videoUUID, |
261 | servers[0].accessToken, | 224 | toCommentId: threadId, |
262 | videoUUID, | 225 | text: 'comment with bad word', |
263 | threadId, | 226 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
264 | 'comment with bad word', | 227 | }) |
265 | HttpStatusCode.FORBIDDEN_403 | 228 | await servers[0].comments.addReply({ |
266 | ) | 229 | videoId: videoUUID, |
267 | await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with good word', HttpStatusCode.OK_200) | 230 | toCommentId: threadId, |
231 | text: 'comment with good word', | ||
232 | expectedStatus: HttpStatusCode.OK_200 | ||
233 | }) | ||
268 | }) | 234 | }) |
269 | 235 | ||
270 | it('Should run filter:api.video-threads.list.params', async function () { | 236 | it('Should run filter:api.video-threads.list.params', async function () { |
271 | const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) | 237 | const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 }) |
272 | 238 | ||
273 | // our plugin do +1 to the count parameter | 239 | // our plugin do +1 to the count parameter |
274 | expect(res.body.data).to.have.lengthOf(1) | 240 | expect(data).to.have.lengthOf(1) |
275 | }) | 241 | }) |
276 | 242 | ||
277 | it('Should run filter:api.video-threads.list.result', async function () { | 243 | it('Should run filter:api.video-threads.list.result', async function () { |
278 | const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) | 244 | const { total } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 }) |
279 | 245 | ||
280 | // Plugin do +1 to the total result | 246 | // Plugin do +1 to the total result |
281 | expect(res.body.total).to.equal(2) | 247 | expect(total).to.equal(2) |
282 | }) | 248 | }) |
283 | 249 | ||
284 | it('Should run filter:api.video-thread-comments.list.params') | 250 | it('Should run filter:api.video-thread-comments.list.params') |
285 | 251 | ||
286 | it('Should run filter:api.video-thread-comments.list.result', async function () { | 252 | it('Should run filter:api.video-thread-comments.list.result', async function () { |
287 | const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId) | 253 | const thread = await servers[0].comments.getThread({ videoId: videoUUID, threadId }) |
288 | 254 | ||
289 | const thread = res.body as VideoCommentThreadTree | ||
290 | expect(thread.comment.text.endsWith(' <3')).to.be.true | 255 | expect(thread.comment.text.endsWith(' <3')).to.be.true |
291 | }) | 256 | }) |
292 | 257 | ||
293 | describe('Should run filter:video.auto-blacklist.result', function () { | 258 | it('Should run filter:api.overviews.videos.list.{params,result}', async function () { |
259 | await servers[0].overviews.getVideos({ page: 1 }) | ||
294 | 260 | ||
295 | async function checkIsBlacklisted (oldRes: any, value: boolean) { | 261 | // 3 because we get 3 samples per page |
296 | const videoId = oldRes.body.video.uuid | 262 | await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.params', 3) |
263 | await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.result', 3) | ||
264 | }) | ||
297 | 265 | ||
298 | const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId) | 266 | describe('Should run filter:video.auto-blacklist.result', function () { |
299 | const video: VideoDetails = res.body | 267 | |
268 | async function checkIsBlacklisted (id: number | string, value: boolean) { | ||
269 | const video = await servers[0].videos.getWithToken({ id }) | ||
300 | expect(video.blacklisted).to.equal(value) | 270 | expect(video.blacklisted).to.equal(value) |
301 | } | 271 | } |
302 | 272 | ||
303 | it('Should blacklist on upload', async function () { | 273 | it('Should blacklist on upload', async function () { |
304 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) | 274 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video please blacklist me' } }) |
305 | await checkIsBlacklisted(res, true) | 275 | await checkIsBlacklisted(uuid, true) |
306 | }) | 276 | }) |
307 | 277 | ||
308 | it('Should blacklist on import', async function () { | 278 | it('Should blacklist on import', async function () { |
@@ -310,60 +280,62 @@ describe('Test plugin filter hooks', function () { | |||
310 | 280 | ||
311 | const attributes = { | 281 | const attributes = { |
312 | name: 'video please blacklist me', | 282 | name: 'video please blacklist me', |
313 | targetUrl: getGoodVideoUrl(), | 283 | targetUrl: FIXTURE_URLS.goodVideo, |
314 | channelId: servers[0].videoChannel.id | 284 | channelId: servers[0].store.channel.id |
315 | } | 285 | } |
316 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | 286 | const body = await servers[0].imports.importVideo({ attributes }) |
317 | await checkIsBlacklisted(res, true) | 287 | await checkIsBlacklisted(body.video.uuid, true) |
318 | }) | 288 | }) |
319 | 289 | ||
320 | it('Should blacklist on update', async function () { | 290 | it('Should blacklist on update', async function () { |
321 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) | 291 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } }) |
322 | const videoId = res.body.video.uuid | 292 | await checkIsBlacklisted(uuid, false) |
323 | await checkIsBlacklisted(res, false) | ||
324 | 293 | ||
325 | await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) | 294 | await servers[0].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } }) |
326 | await checkIsBlacklisted(res, true) | 295 | await checkIsBlacklisted(uuid, true) |
327 | }) | 296 | }) |
328 | 297 | ||
329 | it('Should blacklist on remote upload', async function () { | 298 | it('Should blacklist on remote upload', async function () { |
330 | this.timeout(120000) | 299 | this.timeout(120000) |
331 | 300 | ||
332 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) | 301 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'remote please blacklist me' } }) |
333 | await waitJobs(servers) | 302 | await waitJobs(servers) |
334 | 303 | ||
335 | await checkIsBlacklisted(res, true) | 304 | await checkIsBlacklisted(uuid, true) |
336 | }) | 305 | }) |
337 | 306 | ||
338 | it('Should blacklist on remote update', async function () { | 307 | it('Should blacklist on remote update', async function () { |
339 | this.timeout(120000) | 308 | this.timeout(120000) |
340 | 309 | ||
341 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' }) | 310 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video' } }) |
342 | await waitJobs(servers) | 311 | await waitJobs(servers) |
343 | 312 | ||
344 | const videoId = res.body.video.uuid | 313 | await checkIsBlacklisted(uuid, false) |
345 | await checkIsBlacklisted(res, false) | ||
346 | 314 | ||
347 | await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) | 315 | await servers[1].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } }) |
348 | await waitJobs(servers) | 316 | await waitJobs(servers) |
349 | 317 | ||
350 | await checkIsBlacklisted(res, true) | 318 | await checkIsBlacklisted(uuid, true) |
351 | }) | 319 | }) |
352 | }) | 320 | }) |
353 | 321 | ||
354 | describe('Should run filter:api.user.signup.allowed.result', function () { | 322 | describe('Should run filter:api.user.signup.allowed.result', function () { |
355 | 323 | ||
356 | it('Should run on config endpoint', async function () { | 324 | it('Should run on config endpoint', async function () { |
357 | const res = await getConfig(servers[0].url) | 325 | const body = await servers[0].config.getConfig() |
358 | expect((res.body as ServerConfig).signup.allowed).to.be.true | 326 | expect(body.signup.allowed).to.be.true |
359 | }) | 327 | }) |
360 | 328 | ||
361 | it('Should allow a signup', async function () { | 329 | it('Should allow a signup', async function () { |
362 | await registerUser(servers[0].url, 'john', 'password') | 330 | await servers[0].users.register({ username: 'john', password: 'password' }) |
363 | }) | 331 | }) |
364 | 332 | ||
365 | it('Should not allow a signup', async function () { | 333 | it('Should not allow a signup', async function () { |
366 | const res = await registerUser(servers[0].url, 'jma', 'password', HttpStatusCode.FORBIDDEN_403) | 334 | const res = await servers[0].users.register({ |
335 | username: 'jma', | ||
336 | password: 'password', | ||
337 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
338 | }) | ||
367 | 339 | ||
368 | expect(res.body.error).to.equal('No jma') | 340 | expect(res.body.error).to.equal('No jma') |
369 | }) | 341 | }) |
@@ -375,13 +347,15 @@ describe('Test plugin filter hooks', function () { | |||
375 | before(async function () { | 347 | before(async function () { |
376 | this.timeout(120000) | 348 | this.timeout(120000) |
377 | 349 | ||
378 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | 350 | await servers[0].config.updateCustomSubConfig({ |
379 | transcoding: { | 351 | newConfig: { |
380 | webtorrent: { | 352 | transcoding: { |
381 | enabled: true | 353 | webtorrent: { |
382 | }, | 354 | enabled: true |
383 | hls: { | 355 | }, |
384 | enabled: true | 356 | hls: { |
357 | enabled: true | ||
358 | } | ||
385 | } | 359 | } |
386 | } | 360 | } |
387 | }) | 361 | }) |
@@ -389,15 +363,14 @@ describe('Test plugin filter hooks', function () { | |||
389 | const uuids: string[] = [] | 363 | const uuids: string[] = [] |
390 | 364 | ||
391 | for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) { | 365 | for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) { |
392 | const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid | 366 | const uuid = (await servers[0].videos.quickUpload({ name: name })).uuid |
393 | uuids.push(uuid) | 367 | uuids.push(uuid) |
394 | } | 368 | } |
395 | 369 | ||
396 | await waitJobs(servers) | 370 | await waitJobs(servers) |
397 | 371 | ||
398 | for (const uuid of uuids) { | 372 | for (const uuid of uuids) { |
399 | const res = await getVideo(servers[0].url, uuid) | 373 | downloadVideos.push(await servers[0].videos.get({ id: uuid })) |
400 | downloadVideos.push(res.body) | ||
401 | } | 374 | } |
402 | }) | 375 | }) |
403 | 376 | ||
@@ -437,25 +410,26 @@ describe('Test plugin filter hooks', function () { | |||
437 | before(async function () { | 410 | before(async function () { |
438 | this.timeout(60000) | 411 | this.timeout(60000) |
439 | 412 | ||
440 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | 413 | await servers[0].config.updateCustomSubConfig({ |
441 | transcoding: { | 414 | newConfig: { |
442 | enabled: false | 415 | transcoding: { |
416 | enabled: false | ||
417 | } | ||
443 | } | 418 | } |
444 | }) | 419 | }) |
445 | 420 | ||
446 | for (const name of [ 'bad embed', 'good embed' ]) { | 421 | for (const name of [ 'bad embed', 'good embed' ]) { |
447 | { | 422 | { |
448 | const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid | 423 | const uuid = (await servers[0].videos.quickUpload({ name: name })).uuid |
449 | const res = await getVideo(servers[0].url, uuid) | 424 | embedVideos.push(await servers[0].videos.get({ id: uuid })) |
450 | embedVideos.push(res.body) | ||
451 | } | 425 | } |
452 | 426 | ||
453 | { | 427 | { |
454 | const playlistAttrs = { displayName: name, videoChannelId: servers[0].videoChannel.id, privacy: VideoPlaylistPrivacy.PUBLIC } | 428 | const attributes = { displayName: name, videoChannelId: servers[0].store.channel.id, privacy: VideoPlaylistPrivacy.PUBLIC } |
455 | const res = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs }) | 429 | const { id } = await servers[0].playlists.create({ attributes }) |
456 | 430 | ||
457 | const resPlaylist = await getVideoPlaylist(servers[0].url, res.body.videoPlaylist.id) | 431 | const playlist = await servers[0].playlists.get({ playlistId: id }) |
458 | embedPlaylists.push(resPlaylist.body) | 432 | embedPlaylists.push(playlist) |
459 | } | 433 | } |
460 | } | 434 | } |
461 | }) | 435 | }) |
@@ -474,78 +448,92 @@ describe('Test plugin filter hooks', function () { | |||
474 | describe('Search filters', function () { | 448 | describe('Search filters', function () { |
475 | 449 | ||
476 | before(async function () { | 450 | before(async function () { |
477 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | 451 | await servers[0].config.updateCustomSubConfig({ |
478 | search: { | 452 | newConfig: { |
479 | searchIndex: { | 453 | search: { |
480 | enabled: true, | 454 | searchIndex: { |
481 | isDefaultSearch: false, | 455 | enabled: true, |
482 | disableLocalSearch: false | 456 | isDefaultSearch: false, |
457 | disableLocalSearch: false | ||
458 | } | ||
483 | } | 459 | } |
484 | } | 460 | } |
485 | }) | 461 | }) |
486 | }) | 462 | }) |
487 | 463 | ||
488 | it('Should run filter:api.search.videos.local.list.{params,result}', async function () { | 464 | it('Should run filter:api.search.videos.local.list.{params,result}', async function () { |
489 | await advancedVideosSearch(servers[0].url, { | 465 | await servers[0].search.advancedVideoSearch({ |
490 | search: 'Sun Quan' | 466 | search: { |
467 | search: 'Sun Quan' | ||
468 | } | ||
491 | }) | 469 | }) |
492 | 470 | ||
493 | await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) | 471 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1) |
494 | await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.result', 1) | 472 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1) |
495 | }) | 473 | }) |
496 | 474 | ||
497 | it('Should run filter:api.search.videos.index.list.{params,result}', async function () { | 475 | it('Should run filter:api.search.videos.index.list.{params,result}', async function () { |
498 | await advancedVideosSearch(servers[0].url, { | 476 | await servers[0].search.advancedVideoSearch({ |
499 | search: 'Sun Quan', | 477 | search: { |
500 | searchTarget: 'search-index' | 478 | search: 'Sun Quan', |
479 | searchTarget: 'search-index' | ||
480 | } | ||
501 | }) | 481 | }) |
502 | 482 | ||
503 | await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) | 483 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1) |
504 | await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.result', 1) | 484 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1) |
505 | await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.index.list.params', 1) | 485 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.params', 1) |
506 | await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.index.list.result', 1) | 486 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.result', 1) |
507 | }) | 487 | }) |
508 | 488 | ||
509 | it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () { | 489 | it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () { |
510 | await advancedVideoChannelSearch(servers[0].url, { | 490 | await servers[0].search.advancedChannelSearch({ |
511 | search: 'Sun Ce' | 491 | search: { |
492 | search: 'Sun Ce' | ||
493 | } | ||
512 | }) | 494 | }) |
513 | 495 | ||
514 | await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) | 496 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1) |
515 | await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.result', 1) | 497 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1) |
516 | }) | 498 | }) |
517 | 499 | ||
518 | it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () { | 500 | it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () { |
519 | await advancedVideoChannelSearch(servers[0].url, { | 501 | await servers[0].search.advancedChannelSearch({ |
520 | search: 'Sun Ce', | 502 | search: { |
521 | searchTarget: 'search-index' | 503 | search: 'Sun Ce', |
504 | searchTarget: 'search-index' | ||
505 | } | ||
522 | }) | 506 | }) |
523 | 507 | ||
524 | await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) | 508 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1) |
525 | await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.result', 1) | 509 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1) |
526 | await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.index.list.params', 1) | 510 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.params', 1) |
527 | await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.index.list.result', 1) | 511 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.result', 1) |
528 | }) | 512 | }) |
529 | 513 | ||
530 | it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () { | 514 | it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () { |
531 | await advancedVideoPlaylistSearch(servers[0].url, { | 515 | await servers[0].search.advancedPlaylistSearch({ |
532 | search: 'Sun Jian' | 516 | search: { |
517 | search: 'Sun Jian' | ||
518 | } | ||
533 | }) | 519 | }) |
534 | 520 | ||
535 | await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) | 521 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1) |
536 | await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.result', 1) | 522 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1) |
537 | }) | 523 | }) |
538 | 524 | ||
539 | it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () { | 525 | it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () { |
540 | await advancedVideoPlaylistSearch(servers[0].url, { | 526 | await servers[0].search.advancedPlaylistSearch({ |
541 | search: 'Sun Jian', | 527 | search: { |
542 | searchTarget: 'search-index' | 528 | search: 'Sun Jian', |
529 | searchTarget: 'search-index' | ||
530 | } | ||
543 | }) | 531 | }) |
544 | 532 | ||
545 | await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) | 533 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1) |
546 | await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.result', 1) | 534 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1) |
547 | await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.index.list.params', 1) | 535 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.params', 1) |
548 | await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.index.list.result', 1) | 536 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.result', 1) |
549 | }) | 537 | }) |
550 | }) | 538 | }) |
551 | 539 | ||