From 1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 15 Apr 2019 10:49:46 +0200 Subject: Add user adminFlags --- server/tests/api/videos/video-blacklist.ts | 115 +++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 14 deletions(-) (limited to 'server/tests/api/videos/video-blacklist.ts') 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' import 'mocha' import { addVideoToBlacklist, + createUser, flushAndRunMultipleServers, getBlacklistedVideosList, - getBlacklistedVideosListWithTypeFilter, getMyVideos, - getSortedBlacklistedVideosList, getVideosList, killallServers, removeVideoFromBlacklist, + reRunServer, searchVideo, ServerInfo, setAccessTokensToServers, updateVideo, updateVideoBlacklist, uploadVideo, - viewVideo + userLogin } from '../../../../shared/utils/index' import { doubleFollow } from '../../../../shared/utils/server/follows' import { waitJobs } from '../../../../shared/utils/server/jobs' import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' +import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' +import { UserRole } from '../../../../shared/models/users' const expect = chai.expect -describe('Test video blacklist management', function () { +describe('Test video blacklist', function () { let servers: ServerInfo[] = [] let videoId: number @@ -104,7 +106,7 @@ describe('Test video blacklist management', function () { describe('When listing manually blacklisted videos', function () { it('Should display all the blacklisted videos', async function () { - const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken) + const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken }) expect(res.body.total).to.equal(2) @@ -119,7 +121,11 @@ describe('Test video blacklist management', function () { }) it('Should display all the blacklisted videos when applying manual type filter', async function () { - const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.MANUAL) + const res = await getBlacklistedVideosList({ + url: servers[ 0 ].url, + token: servers[ 0 ].accessToken, + type: VideoBlacklistType.MANUAL + }) expect(res.body.total).to.equal(2) @@ -129,7 +135,11 @@ describe('Test video blacklist management', function () { }) it('Should display nothing when applying automatic type filter', async function () { - const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.AUTO_BEFORE_PUBLISHED) // tslint:disable:max-line-length + const res = await getBlacklistedVideosList({ + url: servers[ 0 ].url, + token: servers[ 0 ].accessToken, + type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED + }) expect(res.body.total).to.equal(0) @@ -139,7 +149,7 @@ describe('Test video blacklist management', function () { }) it('Should get the correct sort when sorting by descending id', async function () { - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-id' }) expect(res.body.total).to.equal(2) const blacklistedVideos = res.body.data @@ -152,7 +162,7 @@ describe('Test video blacklist management', function () { }) it('Should get the correct sort when sorting by descending video name', async function () { - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) expect(res.body.total).to.equal(2) const blacklistedVideos = res.body.data @@ -165,7 +175,7 @@ describe('Test video blacklist management', function () { }) it('Should get the correct sort when sorting by ascending creation date', async function () { - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' }) expect(res.body.total).to.equal(2) const blacklistedVideos = res.body.data @@ -182,7 +192,7 @@ describe('Test video blacklist management', function () { it('Should change the reason', async function () { await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) const video = res.body.data.find(b => b.video.id === videoId) expect(video.reason).to.equal('my super reason updated') @@ -218,7 +228,7 @@ describe('Test video blacklist management', function () { it('Should remove a video from the blacklist on server 1', async function () { // Get one video in the blacklist - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) videoToRemove = res.body.data[0] blacklist = res.body.data.slice(1) @@ -239,7 +249,7 @@ describe('Test video blacklist management', function () { }) it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' }) expect(res.body.total).to.equal(1) const videos = res.body.data @@ -313,7 +323,7 @@ describe('Test video blacklist management', function () { }) it('Should have the correct video blacklist unfederate attribute', async function () { - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') + const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' }) const blacklistedVideos: VideoBlacklist[] = res.body.data const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) @@ -338,6 +348,83 @@ describe('Test video blacklist management', function () { }) + describe('When auto blacklist videos', function () { + let userWithoutFlag: string + let userWithFlag: string + + before(async function () { + this.timeout(20000) + + killallServers([ servers[0] ]) + + const config = { + 'auto_blacklist': { + videos: { + 'of_users': { + enabled: true + } + } + } + } + await reRunServer(servers[0], config) + + { + const user = { username: 'user_without_flag', password: 'password' } + await createUser({ + url: servers[ 0 ].url, + accessToken: servers[ 0 ].accessToken, + username: user.username, + adminFlags: UserAdminFlag.NONE, + password: user.password, + role: UserRole.USER + }) + + userWithoutFlag = await userLogin(servers[0], user) + } + + { + const user = { username: 'user_with_flag', password: 'password' } + await createUser({ + url: servers[ 0 ].url, + accessToken: servers[ 0 ].accessToken, + username: user.username, + adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST, + password: user.password, + role: UserRole.USER + }) + + userWithFlag = await userLogin(servers[0], user) + } + + await waitJobs(servers) + }) + + it('Should auto blacklist a video', async function () { + await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) + + const res = await getBlacklistedVideosList({ + url: servers[ 0 ].url, + token: servers[ 0 ].accessToken, + type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED + }) + + expect(res.body.total).to.equal(1) + expect(res.body.data[0].video.name).to.equal('blacklisted') + }) + + it('Should not auto blacklist a video', async function () { + await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) + + const res = await getBlacklistedVideosList({ + url: servers[ 0 ].url, + token: servers[ 0 ].accessToken, + type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED + }) + + expect(res.body.total).to.equal(1) + }) + }) + after(async function () { killallServers(servers) }) -- cgit v1.2.3