From 9639bd175726b73f8fe664b5ced12a72407b1f0b Mon Sep 17 00:00:00 2001 From: buoyantair Date: Mon, 29 Oct 2018 22:18:31 +0530 Subject: Move utils to /shared Move utils used by /server/tools/* & /server/tests/**/* into /shared folder. Issue: #1336 --- server/tests/api/videos/multiple-servers.ts | 6 +++--- server/tests/api/videos/services.ts | 12 ++++++++++-- server/tests/api/videos/single-server.ts | 2 +- server/tests/api/videos/video-abuse.ts | 6 +++--- server/tests/api/videos/video-blacklist-management.ts | 6 +++--- server/tests/api/videos/video-blacklist.ts | 6 +++--- server/tests/api/videos/video-captions.ts | 15 +++++++++++---- server/tests/api/videos/video-change-ownership.ts | 4 ++-- server/tests/api/videos/video-channels.ts | 6 +++--- server/tests/api/videos/video-comments.ts | 6 +++--- server/tests/api/videos/video-description.ts | 6 +++--- server/tests/api/videos/video-imports.ts | 6 +++--- server/tests/api/videos/video-nsfw.ts | 17 ++++++++++++----- server/tests/api/videos/video-privacy.ts | 12 ++++++------ server/tests/api/videos/video-schedule-update.ts | 4 ++-- server/tests/api/videos/video-transcoder.ts | 4 ++-- server/tests/api/videos/videos-filter.ts | 2 +- server/tests/api/videos/videos-history.ts | 4 ++-- server/tests/api/videos/videos-overview.ts | 4 ++-- 19 files changed, 75 insertions(+), 53 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index b9ace2885..aa38b6b33 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -31,15 +31,15 @@ import { viewVideo, wait, webtorrentAdd -} from '../../utils' +} from '../../../../shared/utils' import { addVideoCommentReply, addVideoCommentThread, deleteVideoComment, getVideoCommentThreads, getVideoThreadComments -} from '../../utils/videos/video-comments' -import { waitJobs } from '../../utils/server/jobs' +} from '../../../../shared/utils/videos/video-comments' +import { waitJobs } from '../../../../shared/utils/server/jobs' const expect = chai.expect diff --git a/server/tests/api/videos/services.ts b/server/tests/api/videos/services.ts index 2f1424292..2da86964f 100644 --- a/server/tests/api/videos/services.ts +++ b/server/tests/api/videos/services.ts @@ -2,8 +2,16 @@ import * as chai from 'chai' import 'mocha' -import { flushTests, getOEmbed, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils/index' -import { runServer } from '../../utils/server/servers' +import { + flushTests, + getOEmbed, + getVideosList, + killallServers, + ServerInfo, + setAccessTokensToServers, + uploadVideo +} from '../../../../shared/utils/index' +import { runServer } from '../../../../shared/utils/server/servers' const expect = chai.expect diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index 089c3df25..069dec67c 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -28,7 +28,7 @@ import { uploadVideo, viewVideo, wait -} from '../../utils' +} from '../../../../shared/utils' const expect = chai.expect diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts index a17f3c8de..3a7b623da 100644 --- a/server/tests/api/videos/video-abuse.ts +++ b/server/tests/api/videos/video-abuse.ts @@ -14,9 +14,9 @@ import { setAccessTokensToServers, updateVideoAbuse, uploadVideo -} from '../../utils/index' -import { doubleFollow } from '../../utils/server/follows' -import { waitJobs } from '../../utils/server/jobs' +} from '../../../../shared/utils/index' +import { doubleFollow } from '../../../../shared/utils/server/follows' +import { waitJobs } from '../../../../shared/utils/server/jobs' const expect = chai.expect diff --git a/server/tests/api/videos/video-blacklist-management.ts b/server/tests/api/videos/video-blacklist-management.ts index 7bf39dc99..06d80a270 100644 --- a/server/tests/api/videos/video-blacklist-management.ts +++ b/server/tests/api/videos/video-blacklist-management.ts @@ -16,9 +16,9 @@ import { setAccessTokensToServers, updateVideoBlacklist, uploadVideo -} from '../../utils/index' -import { doubleFollow } from '../../utils/server/follows' -import { waitJobs } from '../../utils/server/jobs' +} from '../../../../shared/utils/index' +import { doubleFollow } from '../../../../shared/utils/server/follows' +import { waitJobs } from '../../../../shared/utils/server/jobs' import { VideoAbuse } from '../../../../shared/models/videos' const expect = chai.expect diff --git a/server/tests/api/videos/video-blacklist.ts b/server/tests/api/videos/video-blacklist.ts index de4c68f1d..1cce82d2a 100644 --- a/server/tests/api/videos/video-blacklist.ts +++ b/server/tests/api/videos/video-blacklist.ts @@ -11,9 +11,9 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo -} from '../../utils/index' -import { doubleFollow } from '../../utils/server/follows' -import { waitJobs } from '../../utils/server/jobs' +} from '../../../../shared/utils/index' +import { doubleFollow } from '../../../../shared/utils/server/follows' +import { waitJobs } from '../../../../shared/utils/server/jobs' const expect = chai.expect diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index 6e441410d..57bee713f 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -2,10 +2,17 @@ import * as chai from 'chai' import 'mocha' -import { checkVideoFilesWereRemoved, doubleFollow, flushAndRunMultipleServers, removeVideo, uploadVideo, wait } from '../../utils' -import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index' -import { waitJobs } from '../../utils/server/jobs' -import { createVideoCaption, deleteVideoCaption, listVideoCaptions, testCaptionFile } from '../../utils/videos/video-captions' +import { + checkVideoFilesWereRemoved, + doubleFollow, + flushAndRunMultipleServers, + removeVideo, + uploadVideo, + wait +} from '../../../../shared/utils' +import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/utils/index' +import { waitJobs } from '../../../../shared/utils/server/jobs' +import { createVideoCaption, deleteVideoCaption, listVideoCaptions, testCaptionFile } from '../../../../shared/utils/videos/video-captions' import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model' const expect = chai.expect diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 1578a471d..25675a966 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -18,8 +18,8 @@ import { uploadVideo, userLogin, getVideo -} from '../../utils' -import { waitJobs } from '../../utils/server/jobs' +} from '../../../../shared/utils' +import { waitJobs } from '../../../../shared/utils/server/jobs' import { User } from '../../../../shared/models/users' import { VideoDetails } from '../../../../shared/models/videos' diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 8138c65d6..5bffffc66 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -11,7 +11,7 @@ import { updateVideo, updateVideoChannelAvatar, uploadVideo, wait, userLogin -} from '../../utils' +} from '../../../../shared/utils' import { addVideoChannel, deleteVideoChannel, @@ -24,8 +24,8 @@ import { ServerInfo, setAccessTokensToServers, updateVideoChannel -} from '../../utils/index' -import { waitJobs } from '../../utils/server/jobs' +} from '../../../../shared/utils/index' +import { waitJobs } from '../../../../shared/utils/server/jobs' const expect = chai.expect diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index d6e07c5b3..ce1b17e35 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -3,7 +3,7 @@ import * as chai from 'chai' import 'mocha' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' -import { testImage } from '../../utils' +import { testImage } from '../../../../shared/utils' import { dateIsValid, flushTests, @@ -13,14 +13,14 @@ import { setAccessTokensToServers, updateMyAvatar, uploadVideo -} from '../../utils/index' +} from '../../../../shared/utils/index' import { addVideoCommentReply, addVideoCommentThread, deleteVideoComment, getVideoCommentThreads, getVideoThreadComments -} from '../../utils/videos/video-comments' +} from '../../../../shared/utils/videos/video-comments' const expect = chai.expect diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index dd5cd78c0..cbda0b9a6 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -12,9 +12,9 @@ import { setAccessTokensToServers, updateVideo, uploadVideo -} from '../../utils/index' -import { doubleFollow } from '../../utils/server/follows' -import { waitJobs } from '../../utils/server/jobs' +} from '../../../../shared/utils/index' +import { doubleFollow } from '../../../../shared/utils/server/follows' +import { waitJobs } from '../../../../shared/utils/server/jobs' const expect = chai.expect diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index aaee79a4a..cd4988553 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -14,9 +14,9 @@ import { killallServers, ServerInfo, setAccessTokensToServers -} from '../../utils' -import { waitJobs } from '../../utils/server/jobs' -import { getMagnetURI, getYoutubeVideoUrl, importVideo, getMyVideoImports } from '../../utils/videos/video-imports' +} from '../../../../shared/utils' +import { waitJobs } from '../../../../shared/utils/server/jobs' +import { getMagnetURI, getYoutubeVideoUrl, importVideo, getMyVideoImports } from '../../../../shared/utils/videos/video-imports' const expect = chai.expect diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index eab7a6991..df1ee2eb9 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -2,10 +2,17 @@ import * as chai from 'chai' import 'mocha' -import { flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils/index' -import { userLogin } from '../../utils/users/login' -import { createUser } from '../../utils/users/users' -import { getMyVideos } from '../../utils/videos/videos' +import { + flushTests, + getVideosList, + killallServers, + ServerInfo, + setAccessTokensToServers, + uploadVideo +} from '../../../../shared/utils/index' +import { userLogin } from '../../../../shared/utils/users/login' +import { createUser } from '../../../../shared/utils/users/users' +import { getMyVideos } from '../../../../shared/utils/videos/videos' import { getAccountVideos, getConfig, @@ -18,7 +25,7 @@ import { searchVideoWithToken, updateCustomConfig, updateMyUser -} from '../../utils' +} from '../../../../shared/utils' import { ServerConfig } from '../../../../shared/models' import { CustomConfig } from '../../../../shared/models/server/custom-config.model' import { User } from '../../../../shared/models/users' diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index 9fefca7e3..0b4e66369 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -10,12 +10,12 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo -} from '../../utils/index' -import { doubleFollow } from '../../utils/server/follows' -import { userLogin } from '../../utils/users/login' -import { createUser } from '../../utils/users/users' -import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../utils/videos/videos' -import { waitJobs } from '../../utils/server/jobs' +} from '../../../../shared/utils/index' +import { doubleFollow } from '../../../../shared/utils/server/follows' +import { userLogin } from '../../../../shared/utils/users/login' +import { createUser } from '../../../../shared/utils/users/users' +import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/utils/videos/videos' +import { waitJobs } from '../../../../shared/utils/server/jobs' const expect = chai.expect diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts index a260fa4da..ecfc5e034 100644 --- a/server/tests/api/videos/video-schedule-update.ts +++ b/server/tests/api/videos/video-schedule-update.ts @@ -15,9 +15,9 @@ import { updateVideo, uploadVideo, wait -} from '../../utils' +} from '../../../../shared/utils' import { join } from 'path' -import { waitJobs } from '../../utils/server/jobs' +import { waitJobs } from '../../../../shared/utils/server/jobs' const expect = chai.expect diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 85795d2ed..f9458f0ec 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -20,9 +20,9 @@ import { uploadVideo, webtorrentAdd, generateHighBitrateVideo -} from '../../utils' +} from '../../../../shared/utils' import { join } from 'path' -import { waitJobs } from '../../utils/server/jobs' +import { waitJobs } from '../../../../shared/utils/server/jobs' import { pathExists } from 'fs-extra' import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index a7588129f..59e37ad86 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -13,7 +13,7 @@ import { setAccessTokensToServers, uploadVideo, userLogin -} from '../../utils' +} from '../../../../shared/utils' import { Video, VideoPrivacy } from '../../../../shared/models/videos' import { UserRole } from '../../../../shared/models/users' diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 6d289b288..40ae94f79 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -11,9 +11,9 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo -} from '../../utils' +} from '../../../../shared/utils' import { Video, VideoDetails } from '../../../../shared/models/videos' -import { userWatchVideo } from '../../utils/videos/video-history' +import { userWatchVideo } from '../../../../shared/utils/videos/video-history' const expect = chai.expect diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index 7d1f29c92..7221bcae6 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -2,8 +2,8 @@ import * as chai from 'chai' import 'mocha' -import { flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils' -import { getVideosOverview } from '../../utils/overviews/overviews' +import { flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/utils' +import { getVideosOverview } from '../../../../shared/utils/overviews/overviews' import { VideosOverview } from '../../../../shared/models/overviews' const expect = chai.expect -- cgit v1.2.3 From 8923187455c5aa7167d813c5c745d3857f183fd7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 Dec 2018 09:16:41 +0100 Subject: Add test regarding tmp directory --- server/tests/api/videos/multiple-servers.ts | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index aa38b6b33..6c281e49e 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -8,6 +8,7 @@ import { VideoPrivacy } from '../../../../shared/models/videos' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' import { addVideoChannel, + checkTmpIsEmpty, checkVideoFilesWereRemoved, completeVideoCheck, createUser, @@ -1008,6 +1009,14 @@ describe('Test multiple servers', function () { }) }) + describe('TMP directory', function () { + it('Should have an empty tmp directory', async function () { + for (const server of servers) { + await checkTmpIsEmpty(server) + } + }) + }) + after(async function () { killallServers(servers) -- cgit v1.2.3 From 14e2014acc1362cfbb770c051a7254b156cd8efb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 Dec 2018 14:52:50 +0100 Subject: Support additional video extensions --- server/tests/api/videos/video-transcoder.ts | 31 +++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 68cf00194..eefd32ef8 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -20,9 +20,8 @@ import { uploadVideo, webtorrentAdd } from '../../../../shared/utils' -import { join } from 'path' +import { extname, join } from 'path' import { waitJobs } from '../../../../shared/utils/server/jobs' -import { pathExists } from 'fs-extra' import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' const expect = chai.expect @@ -322,6 +321,34 @@ describe('Test video transcoding', function () { } }) + it('Should accept and transcode additional extensions', async function () { + this.timeout(300000) + + for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { + const videoAttributes = { + name: fixture, + fixture + } + + await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, videoAttributes) + + await waitJobs(servers) + + for (const server of servers) { + const res = await getVideosList(server.url) + + const video = res.body.data.find(v => v.name === videoAttributes.name) + const res2 = await getVideo(server.url, video.id) + const videoDetails = res2.body + + expect(videoDetails.files).to.have.lengthOf(4) + + const magnetUri = videoDetails.files[ 0 ].magnetUri + expect(magnetUri).to.contain('.mp4') + } + } + }) + after(async function () { killallServers(servers) }) -- cgit v1.2.3 From 8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 17 Dec 2018 15:52:38 +0100 Subject: Add history on server side Add ability to disable, clear and list user videos history --- server/tests/api/videos/videos-history.ts | 85 +++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 5 deletions(-) (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 40ae94f79..f654a422b 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -3,17 +3,21 @@ import * as chai from 'chai' import 'mocha' import { + createUser, flushTests, getVideosListWithToken, getVideoWithToken, - killallServers, makePutBodyRequest, - runServer, searchVideoWithToken, + killallServers, + runServer, + searchVideoWithToken, ServerInfo, setAccessTokensToServers, - uploadVideo + updateMyUser, + uploadVideo, + userLogin } from '../../../../shared/utils' import { Video, VideoDetails } from '../../../../shared/models/videos' -import { userWatchVideo } from '../../../../shared/utils/videos/video-history' +import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/utils/videos/video-history' const expect = chai.expect @@ -22,6 +26,8 @@ describe('Test videos history', function () { let video1UUID: string let video2UUID: string let video3UUID: string + let video3WatchedDate: Date + let userAccessToken: string before(async function () { this.timeout(30000) @@ -46,6 +52,13 @@ describe('Test videos history', function () { const res = await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) video3UUID = res.body.video.uuid } + + const user = { + username: 'user_1', + password: 'super password' + } + await createUser(server.url, server.accessToken, user.username, user.password) + userAccessToken = await userLogin(server, user) }) it('Should get videos, without watching history', async function () { @@ -62,8 +75,8 @@ describe('Test videos history', function () { }) it('Should watch the first and second video', async function () { - await userWatchVideo(server.url, server.accessToken, video1UUID, 3) await userWatchVideo(server.url, server.accessToken, video2UUID, 8) + await userWatchVideo(server.url, server.accessToken, video1UUID, 3) }) it('Should return the correct history when listing, searching and getting videos', async function () { @@ -117,6 +130,68 @@ describe('Test videos history', function () { } }) + it('Should have these videos when listing my history', async function () { + video3WatchedDate = new Date() + await userWatchVideo(server.url, server.accessToken, video3UUID, 2) + + const res = await listMyVideosHistory(server.url, server.accessToken) + + expect(res.body.total).to.equal(3) + + const videos: Video[] = res.body.data + expect(videos[0].name).to.equal('video 3') + expect(videos[1].name).to.equal('video 1') + expect(videos[2].name).to.equal('video 2') + }) + + it('Should not have videos history on another user', async function () { + const res = await listMyVideosHistory(server.url, userAccessToken) + + expect(res.body.total).to.equal(0) + expect(res.body.data).to.have.lengthOf(0) + }) + + it('Should clear my history', async function () { + await removeMyVideosHistory(server.url, server.accessToken, video3WatchedDate.toISOString()) + }) + + it('Should have my history cleared', async function () { + const res = await listMyVideosHistory(server.url, server.accessToken) + + expect(res.body.total).to.equal(1) + + const videos: Video[] = res.body.data + expect(videos[0].name).to.equal('video 3') + }) + + it('Should disable videos history', async function () { + await updateMyUser({ + url: server.url, + accessToken: server.accessToken, + videosHistoryEnabled: false + }) + + await userWatchVideo(server.url, server.accessToken, video2UUID, 8, 409) + }) + + it('Should re-enable videos history', async function () { + await updateMyUser({ + url: server.url, + accessToken: server.accessToken, + videosHistoryEnabled: true + }) + + await userWatchVideo(server.url, server.accessToken, video1UUID, 8) + + const res = await listMyVideosHistory(server.url, server.accessToken) + + expect(res.body.total).to.equal(2) + + const videos: Video[] = res.body.data + expect(videos[0].name).to.equal('video 1') + expect(videos[1].name).to.equal('video 3') + }) + after(async function () { killallServers([ server ]) -- cgit v1.2.3 From 5abb9fbbd12e7097e348d6a38622d364b1fa47ed Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 10 Jan 2019 15:39:51 +0100 Subject: Add ability to unfederate a local video (on blacklist) --- server/tests/api/videos/index.ts | 1 - .../tests/api/videos/video-blacklist-management.ts | 192 ------------- server/tests/api/videos/video-blacklist.ts | 299 ++++++++++++++++++--- 3 files changed, 265 insertions(+), 227 deletions(-) delete mode 100644 server/tests/api/videos/video-blacklist-management.ts (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/index.ts b/server/tests/api/videos/index.ts index 9bdb78491..97f467aae 100644 --- a/server/tests/api/videos/index.ts +++ b/server/tests/api/videos/index.ts @@ -3,7 +3,6 @@ import './services' import './single-server' import './video-abuse' import './video-blacklist' -import './video-blacklist-management' import './video-captions' import './video-change-ownership' import './video-channels' diff --git a/server/tests/api/videos/video-blacklist-management.ts b/server/tests/api/videos/video-blacklist-management.ts deleted file mode 100644 index 61411e30d..000000000 --- a/server/tests/api/videos/video-blacklist-management.ts +++ /dev/null @@ -1,192 +0,0 @@ -/* tslint:disable:no-unused-expression */ - -import * as chai from 'chai' -import { orderBy } from 'lodash' -import 'mocha' -import { - addVideoToBlacklist, - flushAndRunMultipleServers, - getBlacklistedVideosList, - getMyVideos, - getSortedBlacklistedVideosList, - getVideosList, - killallServers, - removeVideoFromBlacklist, - ServerInfo, - setAccessTokensToServers, - updateVideoBlacklist, - uploadVideo -} from '../../../../shared/utils/index' -import { doubleFollow } from '../../../../shared/utils/server/follows' -import { waitJobs } from '../../../../shared/utils/server/jobs' -import { VideoAbuse } from '../../../../shared/models/videos' - -const expect = chai.expect - -describe('Test video blacklist management', function () { - let servers: ServerInfo[] = [] - let videoId: number - - async function blacklistVideosOnServer (server: ServerInfo) { - const res = await getVideosList(server.url) - - const videos = res.body.data - for (let video of videos) { - await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason') - } - } - - before(async function () { - this.timeout(50000) - - // Run servers - servers = await flushAndRunMultipleServers(2) - - // Get the access tokens - await setAccessTokensToServers(servers) - - // Server 1 and server 2 follow each other - await doubleFollow(servers[0], servers[1]) - - // Upload 2 videos on server 2 - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) - - // Wait videos propagation, server 2 has transcoding enabled - await waitJobs(servers) - - // Blacklist the two videos on server 1 - await blacklistVideosOnServer(servers[0]) - }) - - describe('When listing blacklisted videos', function () { - it('Should display all the blacklisted videos', async function () { - const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken) - - expect(res.body.total).to.equal(2) - - const blacklistedVideos = res.body.data - expect(blacklistedVideos).to.be.an('array') - expect(blacklistedVideos.length).to.equal(2) - - for (const blacklistedVideo of blacklistedVideos) { - expect(blacklistedVideo.reason).to.equal('super reason') - videoId = blacklistedVideo.video.id - } - }) - - it('Should get the correct sort when sorting by descending id', async function () { - const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') - expect(res.body.total).to.equal(2) - - const blacklistedVideos = res.body.data - expect(blacklistedVideos).to.be.an('array') - expect(blacklistedVideos.length).to.equal(2) - - const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) - - expect(blacklistedVideos).to.deep.equal(result) - }) - - 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') - expect(res.body.total).to.equal(2) - - const blacklistedVideos = res.body.data - expect(blacklistedVideos).to.be.an('array') - expect(blacklistedVideos.length).to.equal(2) - - const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) - - expect(blacklistedVideos).to.deep.equal(result) - }) - - 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') - expect(res.body.total).to.equal(2) - - const blacklistedVideos = res.body.data - expect(blacklistedVideos).to.be.an('array') - expect(blacklistedVideos.length).to.equal(2) - - const result = orderBy(res.body.data, [ 'createdAt' ]) - - expect(blacklistedVideos).to.deep.equal(result) - }) - }) - - describe('When updating blacklisted videos', 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 video = res.body.data.find(b => b.video.id === videoId) - - expect(video.reason).to.equal('my super reason updated') - }) - }) - - describe('When listing my videos', function () { - it('Should display blacklisted videos', async function () { - await blacklistVideosOnServer(servers[1]) - - const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5) - - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) - - for (const video of res.body.data) { - expect(video.blacklisted).to.be.true - expect(video.blacklistedReason).to.equal('super reason') - } - }) - }) - - describe('When removing a blacklisted video', function () { - let videoToRemove: VideoAbuse - let blacklist = [] - - it('Should not have any video in videos list on server 1', async function () { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) - }) - - 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') - videoToRemove = res.body.data[0] - blacklist = res.body.data.slice(1) - - // Remove it - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id) - }) - - it('Should have the ex-blacklisted video in videos list on server 1', async function () { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) - - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(1) - - expect(videos[0].name).to.equal(videoToRemove.video.name) - expect(videos[0].id).to.equal(videoToRemove.video.id) - }) - - 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') - expect(res.body.total).to.equal(1) - - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(1) - expect(videos).to.deep.equal(blacklist) - }) - }) - - after(async function () { - killallServers(servers) - }) -}) diff --git a/server/tests/api/videos/video-blacklist.ts b/server/tests/api/videos/video-blacklist.ts index 1cce82d2a..d39ad63b4 100644 --- a/server/tests/api/videos/video-blacklist.ts +++ b/server/tests/api/videos/video-blacklist.ts @@ -1,24 +1,43 @@ /* tslint:disable:no-unused-expression */ import * as chai from 'chai' +import { orderBy } from 'lodash' import 'mocha' import { addVideoToBlacklist, flushAndRunMultipleServers, + getBlacklistedVideosList, + getMyVideos, + getSortedBlacklistedVideosList, getVideosList, killallServers, + removeVideoFromBlacklist, searchVideo, ServerInfo, setAccessTokensToServers, - uploadVideo + updateVideo, + updateVideoBlacklist, + uploadVideo, + viewVideo } from '../../../../shared/utils/index' import { doubleFollow } from '../../../../shared/utils/server/follows' import { waitJobs } from '../../../../shared/utils/server/jobs' +import { VideoBlacklist } from '../../../../shared/models/videos' const expect = chai.expect -describe('Test video blacklists', function () { +describe('Test video blacklist management', function () { let servers: ServerInfo[] = [] + let videoId: number + + async function blacklistVideosOnServer (server: ServerInfo) { + const res = await getVideosList(server.url) + + const videos = res.body.data + for (let video of videos) { + await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason') + } + } before(async function () { this.timeout(50000) @@ -32,58 +51,270 @@ describe('Test video blacklists', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - // Upload a video on server 2 - const videoAttributes = { - name: 'my super name for server 2', - description: 'my super description for server 2' - } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + // Upload 2 videos on server 2 + await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) + await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) // Wait videos propagation, server 2 has transcoding enabled await waitJobs(servers) - const res = await getVideosList(servers[0].url) - const videos = res.body.data + // Blacklist the two videos on server 1 + await blacklistVideosOnServer(servers[0]) + }) + + describe('When listing/searching videos', function () { - expect(videos.length).to.equal(1) + it('Should not have the video blacklisted in videos list/search on server 1', async function () { + { + const res = await getVideosList(servers[ 0 ].url) - servers[0].remoteVideo = videos.find(video => video.name === 'my super name for server 2') + expect(res.body.total).to.equal(0) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(0) + } + + { + const res = await searchVideo(servers[ 0 ].url, 'name') + + expect(res.body.total).to.equal(0) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(0) + } + }) + + it('Should have the blacklisted video in videos list/search on server 2', async function () { + { + const res = await getVideosList(servers[ 1 ].url) + + expect(res.body.total).to.equal(2) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(2) + } + + { + const res = await searchVideo(servers[ 1 ].url, 'video') + + expect(res.body.total).to.equal(2) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(2) + } + }) }) - it('Should blacklist a remote video on server 1', async function () { - await addVideoToBlacklist(servers[0].url, servers[0].accessToken, servers[0].remoteVideo.id) + describe('When listing blacklisted videos', function () { + it('Should display all the blacklisted videos', async function () { + const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken) + + expect(res.body.total).to.equal(2) + + const blacklistedVideos = res.body.data + expect(blacklistedVideos).to.be.an('array') + expect(blacklistedVideos.length).to.equal(2) + + for (const blacklistedVideo of blacklistedVideos) { + expect(blacklistedVideo.reason).to.equal('super reason') + videoId = blacklistedVideo.video.id + } + }) + + it('Should get the correct sort when sorting by descending id', async function () { + const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') + expect(res.body.total).to.equal(2) + + const blacklistedVideos = res.body.data + expect(blacklistedVideos).to.be.an('array') + expect(blacklistedVideos.length).to.equal(2) + + const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) + + expect(blacklistedVideos).to.deep.equal(result) + }) + + 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') + expect(res.body.total).to.equal(2) + + const blacklistedVideos = res.body.data + expect(blacklistedVideos).to.be.an('array') + expect(blacklistedVideos.length).to.equal(2) + + const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) + + expect(blacklistedVideos).to.deep.equal(result) + }) + + 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') + expect(res.body.total).to.equal(2) + + const blacklistedVideos = res.body.data + expect(blacklistedVideos).to.be.an('array') + expect(blacklistedVideos.length).to.equal(2) + + const result = orderBy(res.body.data, [ 'createdAt' ]) + + expect(blacklistedVideos).to.deep.equal(result) + }) }) - it('Should not have the video blacklisted in videos list on server 1', async function () { - const res = await getVideosList(servers[0].url) + describe('When updating blacklisted videos', 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 video = res.body.data.find(b => b.video.id === videoId) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + expect(video.reason).to.equal('my super reason updated') + }) }) - it('Should not have the video blacklisted in videos search on server 1', async function () { - const res = await searchVideo(servers[0].url, 'name') + describe('When listing my videos', function () { + it('Should display blacklisted videos', async function () { + await blacklistVideosOnServer(servers[1]) + + const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + expect(res.body.total).to.equal(2) + expect(res.body.data).to.have.lengthOf(2) + + for (const video of res.body.data) { + expect(video.blacklisted).to.be.true + expect(video.blacklistedReason).to.equal('super reason') + } + }) }) - it('Should have the blacklisted video in videos list on server 2', async function () { - const res = await getVideosList(servers[1].url) + describe('When removing a blacklisted video', function () { + let videoToRemove: VideoBlacklist + let blacklist = [] + + it('Should not have any video in videos list on server 1', async function () { + const res = await getVideosList(servers[0].url) + expect(res.body.total).to.equal(0) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(0) + }) + + 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') + videoToRemove = res.body.data[0] + blacklist = res.body.data.slice(1) + + // Remove it + await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id) + }) + + it('Should have the ex-blacklisted video in videos list on server 1', async function () { + const res = await getVideosList(servers[0].url) + expect(res.body.total).to.equal(1) + + const videos = res.body.data + expect(videos).to.be.an('array') + expect(videos.length).to.equal(1) + + expect(videos[0].name).to.equal(videoToRemove.video.name) + expect(videos[0].id).to.equal(videoToRemove.video.id) + }) + + 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') + expect(res.body.total).to.equal(1) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(1) + const videos = res.body.data + expect(videos).to.be.an('array') + expect(videos.length).to.equal(1) + expect(videos).to.deep.equal(blacklist) + }) }) - it('Should have the video blacklisted in videos search on server 2', async function () { - const res = await searchVideo(servers[1].url, 'name') + describe('When blacklisting local videos', function () { + let video3UUID: string + let video4UUID: string + + before(async function () { + this.timeout(10000) + + { + const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' }) + video3UUID = res.body.video.uuid + } + { + const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'Video 4' }) + video4UUID = res.body.video.uuid + } + + await waitJobs(servers) + }) + + it('Should blacklist video 3 and keep it federated', async function () { + this.timeout(10000) + + await addVideoToBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video3UUID, 'super reason', false) + + await waitJobs(servers) + + { + const res = await getVideosList(servers[ 0 ].url) + expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined + } + + { + const res = await getVideosList(servers[ 1 ].url) + expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined + } + }) + + it('Should unfederate the video', async function () { + this.timeout(10000) + + await addVideoToBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video4UUID, 'super reason', true) + + await waitJobs(servers) + + for (const server of servers) { + const res = await getVideosList(server.url) + expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined + } + }) + + it('Should have the video unfederated even after an Update AP message', async function () { + this.timeout(10000) + + await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, video4UUID, { description: 'super description' }) + + await waitJobs(servers) + + for (const server of servers) { + const res = await getVideosList(server.url) + expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined + } + }) + + it('Should have the correct video blacklist unfederate attribute', async function () { + const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') + + const blacklistedVideos: VideoBlacklist[] = res.body.data + const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) + const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID) + + expect(video3Blacklisted.unfederated).to.be.false + expect(video4Blacklisted.unfederated).to.be.true + }) + + it('Should remove the video from blacklist and refederate the video', async function () { + this.timeout(10000) + + await removeVideoFromBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video4UUID) + + await waitJobs(servers) + + for (const server of servers) { + const res = await getVideosList(server.url) + expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined + } + }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(1) }) after(async function () { -- cgit v1.2.3