diff options
Diffstat (limited to 'server/tests/api/videos/video-blacklist.ts')
-rw-r--r-- | server/tests/api/videos/video-blacklist.ts | 115 |
1 files changed, 101 insertions, 14 deletions
diff --git a/server/tests/api/videos/video-blacklist.ts b/server/tests/api/videos/video-blacklist.ts index 10b412a80..1feae19e9 100644 --- a/server/tests/api/videos/video-blacklist.ts +++ b/server/tests/api/videos/video-blacklist.ts | |||
@@ -5,29 +5,31 @@ import { orderBy } from 'lodash' | |||
5 | import 'mocha' | 5 | import 'mocha' |
6 | import { | 6 | import { |
7 | addVideoToBlacklist, | 7 | addVideoToBlacklist, |
8 | createUser, | ||
8 | flushAndRunMultipleServers, | 9 | flushAndRunMultipleServers, |
9 | getBlacklistedVideosList, | 10 | getBlacklistedVideosList, |
10 | getBlacklistedVideosListWithTypeFilter, | ||
11 | getMyVideos, | 11 | getMyVideos, |
12 | getSortedBlacklistedVideosList, | ||
13 | getVideosList, | 12 | getVideosList, |
14 | killallServers, | 13 | killallServers, |
15 | removeVideoFromBlacklist, | 14 | removeVideoFromBlacklist, |
15 | reRunServer, | ||
16 | searchVideo, | 16 | searchVideo, |
17 | ServerInfo, | 17 | ServerInfo, |
18 | setAccessTokensToServers, | 18 | setAccessTokensToServers, |
19 | updateVideo, | 19 | updateVideo, |
20 | updateVideoBlacklist, | 20 | updateVideoBlacklist, |
21 | uploadVideo, | 21 | uploadVideo, |
22 | viewVideo | 22 | userLogin |
23 | } from '../../../../shared/utils/index' | 23 | } from '../../../../shared/utils/index' |
24 | import { doubleFollow } from '../../../../shared/utils/server/follows' | 24 | import { doubleFollow } from '../../../../shared/utils/server/follows' |
25 | import { waitJobs } from '../../../../shared/utils/server/jobs' | 25 | import { waitJobs } from '../../../../shared/utils/server/jobs' |
26 | import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' | 26 | import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' |
27 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | ||
28 | import { UserRole } from '../../../../shared/models/users' | ||
27 | 29 | ||
28 | const expect = chai.expect | 30 | const expect = chai.expect |
29 | 31 | ||
30 | describe('Test video blacklist management', function () { | 32 | describe('Test video blacklist', function () { |
31 | let servers: ServerInfo[] = [] | 33 | let servers: ServerInfo[] = [] |
32 | let videoId: number | 34 | let videoId: number |
33 | 35 | ||
@@ -104,7 +106,7 @@ describe('Test video blacklist management', function () { | |||
104 | 106 | ||
105 | describe('When listing manually blacklisted videos', function () { | 107 | describe('When listing manually blacklisted videos', function () { |
106 | it('Should display all the blacklisted videos', async function () { | 108 | it('Should display all the blacklisted videos', async function () { |
107 | const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken) | 109 | const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken }) |
108 | 110 | ||
109 | expect(res.body.total).to.equal(2) | 111 | expect(res.body.total).to.equal(2) |
110 | 112 | ||
@@ -119,7 +121,11 @@ describe('Test video blacklist management', function () { | |||
119 | }) | 121 | }) |
120 | 122 | ||
121 | it('Should display all the blacklisted videos when applying manual type filter', async function () { | 123 | it('Should display all the blacklisted videos when applying manual type filter', async function () { |
122 | const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.MANUAL) | 124 | const res = await getBlacklistedVideosList({ |
125 | url: servers[ 0 ].url, | ||
126 | token: servers[ 0 ].accessToken, | ||
127 | type: VideoBlacklistType.MANUAL | ||
128 | }) | ||
123 | 129 | ||
124 | expect(res.body.total).to.equal(2) | 130 | expect(res.body.total).to.equal(2) |
125 | 131 | ||
@@ -129,7 +135,11 @@ describe('Test video blacklist management', function () { | |||
129 | }) | 135 | }) |
130 | 136 | ||
131 | it('Should display nothing when applying automatic type filter', async function () { | 137 | it('Should display nothing when applying automatic type filter', async function () { |
132 | const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.AUTO_BEFORE_PUBLISHED) // tslint:disable:max-line-length | 138 | const res = await getBlacklistedVideosList({ |
139 | url: servers[ 0 ].url, | ||
140 | token: servers[ 0 ].accessToken, | ||
141 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED | ||
142 | }) | ||
133 | 143 | ||
134 | expect(res.body.total).to.equal(0) | 144 | expect(res.body.total).to.equal(0) |
135 | 145 | ||
@@ -139,7 +149,7 @@ describe('Test video blacklist management', function () { | |||
139 | }) | 149 | }) |
140 | 150 | ||
141 | it('Should get the correct sort when sorting by descending id', async function () { | 151 | it('Should get the correct sort when sorting by descending id', async function () { |
142 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') | 152 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-id' }) |
143 | expect(res.body.total).to.equal(2) | 153 | expect(res.body.total).to.equal(2) |
144 | 154 | ||
145 | const blacklistedVideos = res.body.data | 155 | const blacklistedVideos = res.body.data |
@@ -152,7 +162,7 @@ describe('Test video blacklist management', function () { | |||
152 | }) | 162 | }) |
153 | 163 | ||
154 | it('Should get the correct sort when sorting by descending video name', async function () { | 164 | it('Should get the correct sort when sorting by descending video name', async function () { |
155 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | 165 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) |
156 | expect(res.body.total).to.equal(2) | 166 | expect(res.body.total).to.equal(2) |
157 | 167 | ||
158 | const blacklistedVideos = res.body.data | 168 | const blacklistedVideos = res.body.data |
@@ -165,7 +175,7 @@ describe('Test video blacklist management', function () { | |||
165 | }) | 175 | }) |
166 | 176 | ||
167 | it('Should get the correct sort when sorting by ascending creation date', async function () { | 177 | it('Should get the correct sort when sorting by ascending creation date', async function () { |
168 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') | 178 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' }) |
169 | expect(res.body.total).to.equal(2) | 179 | expect(res.body.total).to.equal(2) |
170 | 180 | ||
171 | const blacklistedVideos = res.body.data | 181 | const blacklistedVideos = res.body.data |
@@ -182,7 +192,7 @@ describe('Test video blacklist management', function () { | |||
182 | it('Should change the reason', async function () { | 192 | it('Should change the reason', async function () { |
183 | await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') | 193 | await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') |
184 | 194 | ||
185 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | 195 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) |
186 | const video = res.body.data.find(b => b.video.id === videoId) | 196 | const video = res.body.data.find(b => b.video.id === videoId) |
187 | 197 | ||
188 | expect(video.reason).to.equal('my super reason updated') | 198 | expect(video.reason).to.equal('my super reason updated') |
@@ -218,7 +228,7 @@ describe('Test video blacklist management', function () { | |||
218 | 228 | ||
219 | it('Should remove a video from the blacklist on server 1', async function () { | 229 | it('Should remove a video from the blacklist on server 1', async function () { |
220 | // Get one video in the blacklist | 230 | // Get one video in the blacklist |
221 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | 231 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) |
222 | videoToRemove = res.body.data[0] | 232 | videoToRemove = res.body.data[0] |
223 | blacklist = res.body.data.slice(1) | 233 | blacklist = res.body.data.slice(1) |
224 | 234 | ||
@@ -239,7 +249,7 @@ describe('Test video blacklist management', function () { | |||
239 | }) | 249 | }) |
240 | 250 | ||
241 | it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { | 251 | it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { |
242 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | 252 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) |
243 | expect(res.body.total).to.equal(1) | 253 | expect(res.body.total).to.equal(1) |
244 | 254 | ||
245 | const videos = res.body.data | 255 | const videos = res.body.data |
@@ -313,7 +323,7 @@ describe('Test video blacklist management', function () { | |||
313 | }) | 323 | }) |
314 | 324 | ||
315 | it('Should have the correct video blacklist unfederate attribute', async function () { | 325 | it('Should have the correct video blacklist unfederate attribute', async function () { |
316 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') | 326 | const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' }) |
317 | 327 | ||
318 | const blacklistedVideos: VideoBlacklist[] = res.body.data | 328 | const blacklistedVideos: VideoBlacklist[] = res.body.data |
319 | const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) | 329 | const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) |
@@ -338,6 +348,83 @@ describe('Test video blacklist management', function () { | |||
338 | 348 | ||
339 | }) | 349 | }) |
340 | 350 | ||
351 | describe('When auto blacklist videos', function () { | ||
352 | let userWithoutFlag: string | ||
353 | let userWithFlag: string | ||
354 | |||
355 | before(async function () { | ||
356 | this.timeout(20000) | ||
357 | |||
358 | killallServers([ servers[0] ]) | ||
359 | |||
360 | const config = { | ||
361 | 'auto_blacklist': { | ||
362 | videos: { | ||
363 | 'of_users': { | ||
364 | enabled: true | ||
365 | } | ||
366 | } | ||
367 | } | ||
368 | } | ||
369 | await reRunServer(servers[0], config) | ||
370 | |||
371 | { | ||
372 | const user = { username: 'user_without_flag', password: 'password' } | ||
373 | await createUser({ | ||
374 | url: servers[ 0 ].url, | ||
375 | accessToken: servers[ 0 ].accessToken, | ||
376 | username: user.username, | ||
377 | adminFlags: UserAdminFlag.NONE, | ||
378 | password: user.password, | ||
379 | role: UserRole.USER | ||
380 | }) | ||
381 | |||
382 | userWithoutFlag = await userLogin(servers[0], user) | ||
383 | } | ||
384 | |||
385 | { | ||
386 | const user = { username: 'user_with_flag', password: 'password' } | ||
387 | await createUser({ | ||
388 | url: servers[ 0 ].url, | ||
389 | accessToken: servers[ 0 ].accessToken, | ||
390 | username: user.username, | ||
391 | adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST, | ||
392 | password: user.password, | ||
393 | role: UserRole.USER | ||
394 | }) | ||
395 | |||
396 | userWithFlag = await userLogin(servers[0], user) | ||
397 | } | ||
398 | |||
399 | await waitJobs(servers) | ||
400 | }) | ||
401 | |||
402 | it('Should auto blacklist a video', async function () { | ||
403 | await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) | ||
404 | |||
405 | const res = await getBlacklistedVideosList({ | ||
406 | url: servers[ 0 ].url, | ||
407 | token: servers[ 0 ].accessToken, | ||
408 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED | ||
409 | }) | ||
410 | |||
411 | expect(res.body.total).to.equal(1) | ||
412 | expect(res.body.data[0].video.name).to.equal('blacklisted') | ||
413 | }) | ||
414 | |||
415 | it('Should not auto blacklist a video', async function () { | ||
416 | await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) | ||
417 | |||
418 | const res = await getBlacklistedVideosList({ | ||
419 | url: servers[ 0 ].url, | ||
420 | token: servers[ 0 ].accessToken, | ||
421 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED | ||
422 | }) | ||
423 | |||
424 | expect(res.body.total).to.equal(1) | ||
425 | }) | ||
426 | }) | ||
427 | |||
341 | after(async function () { | 428 | after(async function () { |
342 | killallServers(servers) | 429 | killallServers(servers) |
343 | }) | 430 | }) |