From af971e06c620bd46a5aa64c8833364e7022b5e3d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 15:22:51 +0200 Subject: Introduce search command --- server/tests/api/moderation/video-blacklist.ts | 31 ++- .../search/search-activitypub-video-channels.ts | 83 ++++---- .../search/search-activitypub-video-playlists.ts | 84 ++++---- .../tests/api/search/search-activitypub-videos.ts | 81 ++++---- server/tests/api/search/search-channels.ts | 29 +-- server/tests/api/search/search-index.ts | 129 +++++++------ server/tests/api/search/search-playlists.ts | 36 ++-- server/tests/api/search/search-videos.ts | 211 ++++++++++++--------- server/tests/api/videos/video-nsfw.ts | 14 +- server/tests/api/videos/videos-history.ts | 15 +- server/tests/plugins/filter-hooks.ts | 62 +++--- 11 files changed, 409 insertions(+), 366 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 52cac20d9..4a4930c98 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -7,6 +7,7 @@ import { addVideoToBlacklist, cleanupTests, createUser, + doubleFollow, flushAndRunMultipleServers, getBlacklistedVideosList, getMyUserInformation, @@ -15,20 +16,16 @@ import { killallServers, removeVideoFromBlacklist, reRunServer, - searchVideo, ServerInfo, setAccessTokensToServers, updateVideo, updateVideoBlacklist, uploadVideo, - userLogin -} from '../../../../shared/extra-utils/index' -import { doubleFollow } from '../../../../shared/extra-utils/server/follows' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { getGoodVideoUrl, getMagnetURI, importVideo } from '../../../../shared/extra-utils/videos/video-imports' -import { User, UserRole } from '../../../../shared/models/users' -import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' -import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' + userLogin, + waitJobs +} from '@shared/extra-utils' +import { getGoodVideoUrl, getMagnetURI, importVideo } from '@shared/extra-utils/videos/video-imports' +import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' const expect = chai.expect @@ -80,11 +77,11 @@ describe('Test video blacklist', function () { } { - const res = await searchVideo(servers[0].url, 'name') + const body = await servers[0].searchCommand.searchVideos({ search: 'name' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) } }) @@ -98,11 +95,11 @@ describe('Test video blacklist', function () { } { - const res = await searchVideo(servers[1].url, 'video') + const body = await servers[1].searchCommand.searchVideos({ search: 'name' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(2) + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(2) } }) }) diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index e83eb7171..cf5158b66 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { addVideoChannel, cleanupTests, @@ -10,6 +10,7 @@ import { flushAndRunMultipleServers, getVideoChannelsList, getVideoChannelVideos, + SearchCommand, ServerInfo, setAccessTokensToServers, updateMyUser, @@ -17,11 +18,10 @@ import { updateVideoChannel, uploadVideo, userLogin, - wait -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { VideoChannel } from '../../../../shared/models/videos' -import { searchVideoChannel } from '../../../../shared/extra-utils/search/video-channels' + wait, + waitJobs +} from '@shared/extra-utils' +import { VideoChannel } from '@shared/models' const expect = chai.expect @@ -30,6 +30,7 @@ describe('Test ActivityPub video channels search', function () { let userServer2Token: string let videoServer2UUID: string let channelIdServer2: number + let command: SearchCommand before(async function () { this.timeout(120000) @@ -64,6 +65,8 @@ describe('Test ActivityPub video channels search', function () { } await waitJobs(servers) + + command = servers[0].searchCommand }) it('Should not find a remote video channel', async function () { @@ -71,21 +74,21 @@ describe('Test ActivityPub video channels search', function () { { const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3' - const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) + const body = await command.searchChannels({ search, token: servers[0].accessToken }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { // Without token const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' - const res = await searchVideoChannel(servers[0].url, search) + const body = await command.searchChannels({ search }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } }) @@ -96,13 +99,13 @@ describe('Test ActivityPub video channels search', function () { ] for (const search of searches) { - const res = await searchVideoChannel(servers[0].url, search) + const body = await command.searchChannels({ search }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('channel1_server1') - expect(res.body.data[0].displayName).to.equal('Channel 1 server 1') + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('channel1_server1') + expect(body.data[0].displayName).to.equal('Channel 1 server 1') } }) @@ -110,13 +113,13 @@ describe('Test ActivityPub video channels search', function () { const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1' for (const token of [ undefined, servers[0].accessToken ]) { - const res = await searchVideoChannel(servers[0].url, search, token) + const body = await command.searchChannels({ search, token }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('channel1_server1') - expect(res.body.data[0].displayName).to.equal('Channel 1 server 1') + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('channel1_server1') + expect(body.data[0].displayName).to.equal('Channel 1 server 1') } }) @@ -129,13 +132,13 @@ describe('Test ActivityPub video channels search', function () { ] for (const search of searches) { - const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) + const body = await command.searchChannels({ search, token: servers[0].accessToken }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('channel1_server2') - expect(res.body.data[0].displayName).to.equal('Channel 1 server 2') + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('channel1_server2') + expect(body.data[0].displayName).to.equal('Channel 1 server 2') } }) @@ -176,11 +179,11 @@ describe('Test ActivityPub video channels search', function () { await wait(10000) const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' - const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await command.searchChannels({ search, token: servers[0].accessToken }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const videoChannel: VideoChannel = res.body.data[0] + const videoChannel: VideoChannel = body.data[0] expect(videoChannel.displayName).to.equal('channel updated') // We don't return the owner account for now @@ -199,7 +202,7 @@ describe('Test ActivityPub video channels search', function () { await wait(10000) const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' - await searchVideoChannel(servers[0].url, search, servers[0].accessToken) + await command.searchChannels({ search, token: servers[0].accessToken }) await waitJobs(servers) @@ -221,9 +224,9 @@ describe('Test ActivityPub video channels search', function () { await wait(10000) const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' - const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await command.searchChannels({ search, token: servers[0].accessToken }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) after(async function () { diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts index 4c08e9548..1df18173a 100644 --- a/server/tests/api/search/search-activitypub-video-playlists.ts +++ b/server/tests/api/search/search-activitypub-video-playlists.ts @@ -9,15 +9,15 @@ import { deleteVideoPlaylist, flushAndRunMultipleServers, getVideoPlaylistsList, - searchVideoPlaylists, + SearchCommand, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, uploadVideoAndGetId, - wait -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { VideoPlaylist, VideoPlaylistPrivacy } from '../../../../shared/models/videos' + wait, + waitJobs +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect @@ -27,6 +27,8 @@ describe('Test ActivityPub playlists search', function () { let playlistServer2UUID: string let video2Server2: string + let command: SearchCommand + before(async function () { this.timeout(120000) @@ -78,38 +80,40 @@ describe('Test ActivityPub playlists search', function () { } await waitJobs(servers) + + command = servers[0].searchCommand }) it('Should not find a remote playlist', async function () { { const search = 'http://localhost:' + servers[1].port + '/video-playlists/43' - const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) + const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { // Without token const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID - const res = await searchVideoPlaylists(servers[0].url, search) + const body = await command.searchPlaylists({ search }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } }) it('Should search a local playlist', async function () { const search = 'http://localhost:' + servers[0].port + '/video-playlists/' + playlistServer1UUID - const res = await searchVideoPlaylists(servers[0].url, search) + const body = await command.searchPlaylists({ search }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1') - expect(res.body.data[0].videosLength).to.equal(2) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].displayName).to.equal('playlist 1 on server 1') + expect(body.data[0].videosLength).to.equal(2) }) it('Should search a local playlist with an alternative URL', async function () { @@ -120,13 +124,13 @@ describe('Test ActivityPub playlists search', function () { for (const search of searches) { for (const token of [ undefined, servers[0].accessToken ]) { - const res = await searchVideoPlaylists(servers[0].url, search, token) + const body = await command.searchPlaylists({ search, token }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1') - expect(res.body.data[0].videosLength).to.equal(2) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].displayName).to.equal('playlist 1 on server 1') + expect(body.data[0].videosLength).to.equal(2) } } }) @@ -139,13 +143,13 @@ describe('Test ActivityPub playlists search', function () { ] for (const search of searches) { - const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) + const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].displayName).to.equal('playlist 1 on server 2') - expect(res.body.data[0].videosLength).to.equal(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].displayName).to.equal('playlist 1 on server 2') + expect(body.data[0].videosLength).to.equal(1) } }) @@ -172,16 +176,16 @@ describe('Test ActivityPub playlists search', function () { // Will run refresh async const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID - await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) + await command.searchPlaylists({ search, token: servers[0].accessToken }) // Wait refresh await wait(5000) - const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const playlist: VideoPlaylist = res.body.data[0] + const playlist = body.data[0] expect(playlist.videosLength).to.equal(2) }) @@ -196,14 +200,14 @@ describe('Test ActivityPub playlists search', function () { // Will run refresh async const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID - await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) + await command.searchPlaylists({ search, token: servers[0].accessToken }) // Wait refresh await wait(5000) - const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) after(async function () { diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index e9b4978da..1a5130ce9 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -1,15 +1,14 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { addVideoChannel, cleanupTests, flushAndRunMultipleServers, getVideosList, removeVideo, - searchVideo, - searchVideoWithToken, + SearchCommand, ServerInfo, setAccessTokensToServers, updateVideo, @@ -17,7 +16,7 @@ import { wait } from '../../../../shared/extra-utils' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { Video, VideoPrivacy } from '../../../../shared/models/videos' +import { VideoPrivacy } from '../../../../shared/models/videos' const expect = chai.expect @@ -26,6 +25,8 @@ describe('Test ActivityPub videos search', function () { let videoServer1UUID: string let videoServer2UUID: string + let command: SearchCommand + before(async function () { this.timeout(120000) @@ -44,49 +45,51 @@ describe('Test ActivityPub videos search', function () { } await waitJobs(servers) + + command = servers[0].searchCommand }) it('Should not find a remote video', async function () { { const search = 'http://localhost:' + servers[1].port + '/videos/watch/43' - const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) + const body = await command.searchVideos({ search, token: servers[0].accessToken }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { // Without token const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID - const res = await searchVideo(servers[0].url, search) + const body = await command.searchVideos({ search }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } }) it('Should search a local video', async function () { const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID - const res = await searchVideo(servers[0].url, search) + const body = await command.searchVideos({ search }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('video 1 on server 1') + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('video 1 on server 1') }) it('Should search a local video with an alternative URL', async function () { const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID - const res1 = await searchVideo(servers[0].url, search) - const res2 = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) - - for (const res of [ res1, res2 ]) { - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('video 1 on server 1') + const body1 = await command.searchVideos({ search }) + const body2 = await command.searchVideos({ search, token: servers[0].accessToken }) + + for (const body of [ body1, body2 ]) { + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('video 1 on server 1') } }) @@ -97,12 +100,12 @@ describe('Test ActivityPub videos search', function () { ] for (const search of searches) { - const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) + const body = await command.searchVideos({ search, token: servers[0].accessToken }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('video 1 on server 2') + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('video 1 on server 2') } }) @@ -137,16 +140,16 @@ describe('Test ActivityPub videos search', function () { // Will run refresh async const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID - await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) + await command.searchVideos({ search, token: servers[0].accessToken }) // Wait refresh await wait(5000) - const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await command.searchVideos({ search, token: servers[0].accessToken }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const video: Video = res.body.data[0] + const video = body.data[0] expect(video.name).to.equal('updated') expect(video.channel.name).to.equal('super_channel') expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) @@ -163,14 +166,14 @@ describe('Test ActivityPub videos search', function () { // Will run refresh async const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID - await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) + await command.searchVideos({ search, token: servers[0].accessToken }) // Wait refresh await wait(5000) - const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await command.searchVideos({ search, token: servers[0].accessToken }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) after(async function () { diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts index daca2aebe..307bc063d 100644 --- a/server/tests/api/search/search-channels.ts +++ b/server/tests/api/search/search-channels.ts @@ -2,21 +2,22 @@ import 'mocha' import * as chai from 'chai' -import { searchVideoChannel, advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels' import { addVideoChannel, cleanupTests, createUser, flushAndRunServer, + SearchCommand, ServerInfo, setAccessTokensToServers -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' import { VideoChannel } from '@shared/models' const expect = chai.expect describe('Test channels search', function () { let server: ServerInfo = null + let command: SearchCommand before(async function () { this.timeout(30000) @@ -33,13 +34,15 @@ describe('Test channels search', function () { } await addVideoChannel(server.url, server.accessToken, channel) } + + command = server.searchCommand }) it('Should make a simple search and not have results', async function () { - const res = await searchVideoChannel(server.url, 'abc') + const body = await command.searchChannels({ search: 'abc' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should make a search and have results', async function () { @@ -49,11 +52,11 @@ describe('Test channels search', function () { start: 0, count: 1 } - const res = await advancedVideoChannelSearch(server.url, search) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await command.advancedChannelSearch({ search }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const channel: VideoChannel = res.body.data[0] + const channel: VideoChannel = body.data[0] expect(channel.name).to.equal('squall_channel') expect(channel.displayName).to.equal('Squall channel') } @@ -65,11 +68,9 @@ describe('Test channels search', function () { count: 1 } - const res = await advancedVideoChannelSearch(server.url, search) - - expect(res.body.total).to.equal(1) - - expect(res.body.data).to.have.lengthOf(0) + const body = await command.advancedChannelSearch({ search }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(0) } }) diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index 00f79232a..b2c0857a7 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts @@ -2,28 +2,26 @@ import 'mocha' import * as chai from 'chai' -import { advancedVideoChannelSearch, searchVideoChannel } from '@shared/extra-utils/search/video-channels' -import { Video, VideoChannel, VideoPlaylist, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' import { - advancedVideoPlaylistSearch, - advancedVideosSearch, cleanupTests, flushAndRunServer, immutableAssign, - searchVideo, - searchVideoPlaylists, + SearchCommand, ServerInfo, setAccessTokensToServers, updateCustomSubConfig, uploadVideo -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' const expect = chai.expect describe('Test videos search', function () { - let server: ServerInfo = null const localVideoName = 'local video' + new Date().toISOString() + let server: ServerInfo = null + let command: SearchCommand + before(async function () { this.timeout(30000) @@ -32,6 +30,8 @@ describe('Test videos search', function () { await setAccessTokensToServers([ server ]) await uploadVideo(server.url, server.accessToken, { name: localVideoName }) + + command = server.searchCommand }) describe('Default search', async function () { @@ -49,18 +49,18 @@ describe('Test videos search', function () { } }) - const res = await searchVideo(server.url, 'local video') + const body = await command.searchVideos({ search: 'local video' }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal(localVideoName) + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal(localVideoName) }) it('Should make a local channels search by default', async function () { - const res = await searchVideoChannel(server.url, 'root') + const body = await command.searchChannels({ search: 'root' }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('root_channel') - expect(res.body.data[0].host).to.equal('localhost:' + server.port) + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('root_channel') + expect(body.data[0].host).to.equal('localhost:' + server.port) }) it('Should make an index videos search by default', async function () { @@ -74,13 +74,13 @@ describe('Test videos search', function () { } }) - const res = await searchVideo(server.url, 'local video') - expect(res.body.total).to.be.greaterThan(2) + const body = await command.searchVideos({ search: 'local video' }) + expect(body.total).to.be.greaterThan(2) }) it('Should make an index channels search by default', async function () { - const res = await searchVideoChannel(server.url, 'root') - expect(res.body.total).to.be.greaterThan(2) + const body = await command.searchChannels({ search: 'root' }) + expect(body.total).to.be.greaterThan(2) }) it('Should make an index videos search if local search is disabled', async function () { @@ -94,46 +94,46 @@ describe('Test videos search', function () { } }) - const res = await searchVideo(server.url, 'local video') - expect(res.body.total).to.be.greaterThan(2) + const body = await command.searchVideos({ search: 'local video' }) + expect(body.total).to.be.greaterThan(2) }) it('Should make an index channels search if local search is disabled', async function () { - const res = await searchVideoChannel(server.url, 'root') - expect(res.body.total).to.be.greaterThan(2) + const body = await command.searchChannels({ search: 'root' }) + expect(body.total).to.be.greaterThan(2) }) }) describe('Videos search', async function () { it('Should make a simple search and not have results', async function () { - const res = await searchVideo(server.url, 'djidane'.repeat(50)) + const body = await command.searchVideos({ search: 'djidane'.repeat(50) }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should make a simple search and have results', async function () { - const res = await searchVideo(server.url, 'What is PeerTube') + const body = await command.searchVideos({ search: 'What is PeerTube' }) - expect(res.body.total).to.be.greaterThan(1) + expect(body.total).to.be.greaterThan(1) }) it('Should make a complex search', async function () { async function check (search: VideosSearchQuery, exists = true) { - const res = await advancedVideosSearch(server.url, search) + const body = await command.advancedVideoSearch({ search }) if (exists === false) { - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) return } - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const video: Video = res.body.data[0] + const video = body.data[0] expect(video.name).to.equal('What is PeerTube?') expect(video.category.label).to.equal('Science & Technology') @@ -206,10 +206,10 @@ describe('Test videos search', function () { count: 5 } - const res = await advancedVideosSearch(server.url, search) + const body = await command.advancedVideoSearch({ search }) - expect(res.body.total).to.be.greaterThan(5) - expect(res.body.data).to.have.lengthOf(5) + expect(body.total).to.be.greaterThan(5) + expect(body.data).to.have.lengthOf(5) }) it('Should use the nsfw instance policy as default', async function () { @@ -218,10 +218,10 @@ describe('Test videos search', function () { { await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'display' } }) - const res = await searchVideo(server.url, 'NSFW search index', '-match') - const video = res.body.data[0] as Video + const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' }) + expect(body.data).to.have.length.greaterThan(0) - expect(res.body.data).to.have.length.greaterThan(0) + const video = body.data[0] expect(video.nsfw).to.be.true nsfwUUID = video.uuid @@ -230,13 +230,12 @@ describe('Test videos search', function () { { await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'do_not_list' } }) - const res = await searchVideo(server.url, 'NSFW search index', '-match') + const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' }) try { - expect(res.body.data).to.have.lengthOf(0) - } catch (err) { - // - const video = res.body.data[0] as Video + expect(body.data).to.have.lengthOf(0) + } catch { + const video = body.data[0] expect(video.uuid).not.equal(nsfwUUID) } @@ -247,19 +246,19 @@ describe('Test videos search', function () { describe('Channels search', async function () { it('Should make a simple search and not have results', async function () { - const res = await searchVideoChannel(server.url, 'a'.repeat(500)) + const body = await command.searchChannels({ search: 'a'.repeat(500) }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should make a search and have results', async function () { - const res = await advancedVideoChannelSearch(server.url, { search: 'Framasoft', sort: 'createdAt' }) + const body = await command.advancedChannelSearch({ search: { search: 'Framasoft', sort: 'createdAt' } }) - expect(res.body.total).to.be.greaterThan(0) - expect(res.body.data).to.have.length.greaterThan(0) + expect(body.total).to.be.greaterThan(0) + expect(body.data).to.have.length.greaterThan(0) - const videoChannel: VideoChannel = res.body.data[0] + const videoChannel = body.data[0] expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') expect(videoChannel.host).to.equal('framatube.org') expect(videoChannel.avatar).to.exist @@ -272,29 +271,29 @@ describe('Test videos search', function () { }) it('Should have a correct pagination', async function () { - const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) + const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } }) - expect(res.body.total).to.be.greaterThan(2) - expect(res.body.data).to.have.lengthOf(2) + expect(body.total).to.be.greaterThan(2) + expect(body.data).to.have.lengthOf(2) }) }) describe('Playlists search', async function () { it('Should make a simple search and not have results', async function () { - const res = await searchVideoPlaylists(server.url, 'a'.repeat(500)) + const body = await command.searchPlaylists({ search: 'a'.repeat(500) }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should make a search and have results', async function () { - const res = await advancedVideoPlaylistSearch(server.url, { search: 'E2E playlist', sort: '-match' }) + const body = await command.advancedPlaylistSearch({ search: { search: 'E2E playlist', sort: '-match' } }) - expect(res.body.total).to.be.greaterThan(0) - expect(res.body.data).to.have.length.greaterThan(0) + expect(body.total).to.be.greaterThan(0) + expect(body.data).to.have.length.greaterThan(0) - const videoPlaylist: VideoPlaylist = res.body.data[0] + const videoPlaylist = body.data[0] expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') expect(videoPlaylist.thumbnailUrl).to.exist @@ -322,10 +321,10 @@ describe('Test videos search', function () { }) it('Should have a correct pagination', async function () { - const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) + const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } }) - expect(res.body.total).to.be.greaterThan(2) - expect(res.body.data).to.have.lengthOf(2) + expect(body.total).to.be.greaterThan(2) + expect(body.data).to.have.lengthOf(2) }) }) diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts index ab17d55e9..1862ecd31 100644 --- a/server/tests/api/search/search-playlists.ts +++ b/server/tests/api/search/search-playlists.ts @@ -2,14 +2,13 @@ import 'mocha' import * as chai from 'chai' -import { VideoPlaylist, VideoPlaylistPrivacy } from '@shared/models' +import { VideoPlaylistPrivacy } from '@shared/models' import { addVideoInPlaylist, - advancedVideoPlaylistSearch, cleanupTests, createVideoPlaylist, flushAndRunServer, - searchVideoPlaylists, + SearchCommand, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -20,6 +19,7 @@ const expect = chai.expect describe('Test playlists search', function () { let server: ServerInfo = null + let command: SearchCommand before(async function () { this.timeout(30000) @@ -71,13 +71,15 @@ describe('Test playlists search', function () { } await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) } + + command = server.searchCommand }) it('Should make a simple search and not have results', async function () { - const res = await searchVideoPlaylists(server.url, 'abc') + const body = await command.searchPlaylists({ search: 'abc' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should make a search and have results', async function () { @@ -87,11 +89,11 @@ describe('Test playlists search', function () { start: 0, count: 1 } - const res = await advancedVideoPlaylistSearch(server.url, search) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await command.advancedPlaylistSearch({ search }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const playlist: VideoPlaylist = res.body.data[0] + const playlist = body.data[0] expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos') expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid) } @@ -102,11 +104,11 @@ describe('Test playlists search', function () { start: 0, count: 1 } - const res = await advancedVideoPlaylistSearch(server.url, search) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await command.advancedPlaylistSearch({ search }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const playlist: VideoPlaylist = res.body.data[0] + const playlist = body.data[0] expect(playlist.displayName).to.equal('Johan & Anna Libert musics') } }) @@ -117,9 +119,9 @@ describe('Test playlists search', function () { start: 0, count: 1 } - const res = await advancedVideoPlaylistSearch(server.url, search) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await command.advancedPlaylistSearch({ search }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) after(async function () { diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 5b8907961..f0482c7e0 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -4,12 +4,11 @@ import 'mocha' import * as chai from 'chai' import { VideoPrivacy } from '@shared/models' import { - advancedVideosSearch, cleanupTests, createLive, flushAndRunServer, immutableAssign, - searchVideo, + SearchCommand, sendRTMPStreamInVideo, ServerInfo, setAccessTokensToServers, @@ -29,6 +28,8 @@ describe('Test videos search', function () { let startDate: string let videoUUID: string + let command: SearchCommand + before(async function () { this.timeout(60000) @@ -144,21 +145,23 @@ describe('Test videos search', function () { await uploadVideo(server.url, server.accessToken, attributes1) await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) } + + command = server.searchCommand }) it('Should make a simple search and not have results', async function () { - const res = await searchVideo(server.url, 'abc') + const body = await command.searchVideos({ search: 'abc' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should make a simple search and have results', async function () { - const res = await searchVideo(server.url, '4444 5555 duplicate') + const body = await command.searchVideos({ search: '4444 5555 duplicate' }) - expect(res.body.total).to.equal(2) + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) // bestmatch @@ -167,15 +170,15 @@ describe('Test videos search', function () { }) it('Should make a search on tags too, and have results', async function () { - const query = { + const search = { search: 'aaaa', categoryOneOf: [ 1 ] } - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search }) - expect(res.body.total).to.equal(2) + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) // bestmatch @@ -184,14 +187,14 @@ describe('Test videos search', function () { }) it('Should filter on tags without a search', async function () { - const query = { + const search = { tagsAllOf: [ 'bbbb' ] } - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search }) - expect(res.body.total).to.equal(2) + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) expect(videos[0].name).to.equal('9999') @@ -199,14 +202,14 @@ describe('Test videos search', function () { }) it('Should filter on category without a search', async function () { - const query = { + const search = { categoryOneOf: [ 3 ] } - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: search }) - expect(res.body.total).to.equal(1) + expect(body.total).to.equal(1) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(1) expect(videos[0].name).to.equal('6666 7777 8888') @@ -218,11 +221,16 @@ describe('Test videos search', function () { categoryOneOf: [ 1 ], tagsOneOf: [ 'aAaa', 'ffff' ] } - const res1 = await advancedVideosSearch(server.url, query) - expect(res1.body.total).to.equal(2) - const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] })) - expect(res2.body.total).to.equal(0) + { + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(2) + } + + { + const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } }) + expect(body.total).to.equal(0) + } }) it('Should search by tags (all of)', async function () { @@ -231,14 +239,21 @@ describe('Test videos search', function () { categoryOneOf: [ 1 ], tagsAllOf: [ 'CCcc' ] } - const res1 = await advancedVideosSearch(server.url, query) - expect(res1.body.total).to.equal(2) - const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blAbla' ] })) - expect(res2.body.total).to.equal(0) + { + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(2) + } - const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'CCCC' ] })) - expect(res3.body.total).to.equal(1) + { + const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } }) + expect(body.total).to.equal(0) + } + + { + const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } }) + expect(body.total).to.equal(1) + } }) it('Should search by category', async function () { @@ -246,12 +261,17 @@ describe('Test videos search', function () { search: '6666', categoryOneOf: [ 3 ] } - const res1 = await advancedVideosSearch(server.url, query) - expect(res1.body.total).to.equal(1) - expect(res1.body.data[0].name).to.equal('6666 7777 8888') - const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] })) - expect(res2.body.total).to.equal(0) + { + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('6666 7777 8888') + } + + { + const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } }) + expect(body.total).to.equal(0) + } }) it('Should search by licence', async function () { @@ -259,13 +279,18 @@ describe('Test videos search', function () { search: '4444 5555', licenceOneOf: [ 2 ] } - const res1 = await advancedVideosSearch(server.url, query) - expect(res1.body.total).to.equal(2) - expect(res1.body.data[0].name).to.equal('3333 4444 5555') - expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate') - const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] })) - expect(res2.body.total).to.equal(0) + { + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(2) + expect(body.data[0].name).to.equal('3333 4444 5555') + expect(body.data[1].name).to.equal('3333 4444 5555 duplicate') + } + + { + const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } }) + expect(body.total).to.equal(0) + } }) it('Should search by languages', async function () { @@ -275,23 +300,23 @@ describe('Test videos search', function () { } { - const res = await advancedVideosSearch(server.url, query) - expect(res.body.total).to.equal(2) - expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') - expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4') + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(2) + expect(body.data[0].name).to.equal('1111 2222 3333 - 3') + expect(body.data[1].name).to.equal('1111 2222 3333 - 4') } { - const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'pl', 'en', '_unknown' ] })) - expect(res.body.total).to.equal(3) - expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') - expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4') - expect(res.body.data[2].name).to.equal('1111 2222 3333 - 5') + const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } }) + expect(body.total).to.equal(3) + expect(body.data[0].name).to.equal('1111 2222 3333 - 3') + expect(body.data[1].name).to.equal('1111 2222 3333 - 4') + expect(body.data[2].name).to.equal('1111 2222 3333 - 5') } { - const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] })) - expect(res.body.total).to.equal(0) + const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } }) + expect(body.total).to.equal(0) } }) @@ -301,10 +326,10 @@ describe('Test videos search', function () { startDate } - const res = await advancedVideosSearch(server.url, query) - expect(res.body.total).to.equal(4) + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(4) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('1111 2222 3333 - 5') expect(videos[1].name).to.equal('1111 2222 3333 - 6') expect(videos[2].name).to.equal('1111 2222 3333 - 7') @@ -320,10 +345,10 @@ describe('Test videos search', function () { licenceOneOf: [ 1, 4 ] } - const res = await advancedVideosSearch(server.url, query) - expect(res.body.total).to.equal(4) + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(4) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('1111 2222 3333') expect(videos[1].name).to.equal('1111 2222 3333 - 6') expect(videos[2].name).to.equal('1111 2222 3333 - 7') @@ -340,10 +365,10 @@ describe('Test videos search', function () { sort: '-name' } - const res = await advancedVideosSearch(server.url, query) - expect(res.body.total).to.equal(4) + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(4) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('1111 2222 3333 - 8') expect(videos[1].name).to.equal('1111 2222 3333 - 7') expect(videos[2].name).to.equal('1111 2222 3333 - 6') @@ -362,10 +387,10 @@ describe('Test videos search', function () { count: 1 } - const res = await advancedVideosSearch(server.url, query) - expect(res.body.total).to.equal(4) + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(4) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('1111 2222 3333 - 8') }) @@ -381,10 +406,10 @@ describe('Test videos search', function () { count: 1 } - const res = await advancedVideosSearch(server.url, query) - expect(res.body.total).to.equal(4) + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(4) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('1111 2222 3333') }) @@ -399,32 +424,32 @@ describe('Test videos search', function () { { const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }) - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: query }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('1111 2222 3333 - 7') } { const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }) - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: query }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('1111 2222 3333 - 7') } { const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }) - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: query }) - expect(res.body.total).to.equal(0) + expect(body.total).to.equal(0) } { const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }) - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: query }) - expect(res.body.total).to.equal(0) + expect(body.total).to.equal(0) } { @@ -432,9 +457,9 @@ describe('Test videos search', function () { originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', originallyPublishedEndDate: '2019-01-10T09:58:08.286Z' }) - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: query }) - expect(res.body.total).to.equal(0) + expect(body.total).to.equal(0) } { @@ -442,19 +467,19 @@ describe('Test videos search', function () { originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', originallyPublishedEndDate: '2019-04-11T09:58:08.286Z' }) - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: query }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('1111 2222 3333 - 7') } }) it('Should search by UUID', async function () { const search = videoUUID - const res = await advancedVideosSearch(server.url, { search }) + const body = await command.advancedVideoSearch({ search: { search } }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('1111 2222 3333 - 3') }) it('Should search by live', async function () { @@ -471,10 +496,10 @@ describe('Test videos search', function () { } { - const res = await advancedVideosSearch(server.url, { isLive: true }) + const body = await command.advancedVideoSearch({ search: { isLive: true } }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } { @@ -482,15 +507,15 @@ describe('Test videos search', function () { const resLive = await createLive(server.url, server.accessToken, liveOptions) const liveVideoId = resLive.body.video.uuid - const command = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId) + const ffmpegCommand = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId) await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) - const res = await advancedVideosSearch(server.url, { isLive: true }) + const body = await command.advancedVideoSearch({ search: { isLive: true } }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('live') + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('live') - await stopFfmpeg(command) + await stopFfmpeg(ffmpegCommand) } }) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 6c98c9f12..24a4c6152 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -14,8 +14,6 @@ import { getVideoChannelVideos, getVideosList, getVideosListWithToken, - searchVideo, - searchVideoWithToken, ServerInfo, setAccessTokensToServers, updateCustomConfig, @@ -23,7 +21,7 @@ import { uploadVideo, userLogin } from '@shared/extra-utils' -import { CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' +import { BooleanBothQuery, CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' const expect = chai.expect @@ -37,7 +35,7 @@ describe('Test video NSFW policy', function () { let userAccessToken: string let customConfig: CustomConfig - function getVideosFunctions (token?: string, query = {}) { + function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { return getMyUserInformation(server.url, server.accessToken) .then(res => { const user: User = res.body @@ -49,7 +47,7 @@ describe('Test video NSFW policy', function () { if (token) { promises = [ getVideosListWithToken(server.url, token, query), - searchVideoWithToken(server.url, 'n', token, query), + server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...query } }), getAccountVideos(server.url, token, accountName, 0, 5, undefined, query), getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query) ] @@ -66,7 +64,7 @@ describe('Test video NSFW policy', function () { promises = [ getVideosList(server.url), - searchVideo(server.url, 'n'), + server.searchCommand.searchVideos({ search: 'n' }), getAccountVideos(server.url, undefined, accountName, 0, 5), getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5) ] @@ -230,7 +228,7 @@ describe('Test video NSFW policy', function () { }) it('Should display NSFW videos when the nsfw param === true', async function () { - for (const res of await getVideosFunctions(server.accessToken, { nsfw: true })) { + for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) { expect(res.body.total).to.equal(1) const videos = res.body.data @@ -240,7 +238,7 @@ describe('Test video NSFW policy', function () { }) it('Should hide NSFW videos when the nsfw param === true', async function () { - for (const res of await getVideosFunctions(server.accessToken, { nsfw: false })) { + for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) { expect(res.body.total).to.equal(1) const videos = res.body.data diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index b25cff879..209b93014 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, createUser, @@ -10,17 +11,15 @@ import { getVideoWithToken, killallServers, reRunServer, - searchVideoWithToken, ServerInfo, setAccessTokensToServers, updateMyUser, uploadVideo, userLogin, wait -} from '../../../../shared/extra-utils' -import { Video, VideoDetails } from '../../../../shared/models/videos' -import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/extra-utils/videos/video-history' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '@shared/extra-utils/videos/video-history' +import { Video, VideoDetails } from '@shared/models' const expect = chai.expect @@ -89,8 +88,8 @@ describe('Test videos history', function () { } { - const res = await searchVideoWithToken(server.url, 'video', server.accessToken) - videosOfVideos.push(res.body.data) + const body = await server.searchCommand.searchVideos({ token: server.accessToken, search: 'video' }) + videosOfVideos.push(body.data) } for (const videos of videosOfVideos) { diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 644b41dea..e2ec5457b 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -2,17 +2,15 @@ import 'mocha' import * as chai from 'chai' -import { advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels' -import { ServerConfig } from '@shared/models' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { addVideoCommentReply, addVideoCommentThread, - advancedVideoPlaylistSearch, - advancedVideosSearch, + cleanupTests, createLive, createVideoPlaylist, doubleFollow, + flushAndRunMultipleServers, getAccountVideos, getConfig, getMyVideos, @@ -28,17 +26,19 @@ import { installPlugin, makeRawRequest, registerUser, + ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, updateCustomSubConfig, updateVideo, uploadVideo, uploadVideoAndGetId, - waitJobs -} from '../../../shared/extra-utils' -import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' -import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports' + waitJobs, + waitUntilLog +} from '@shared/extra-utils' +import { getGoodVideoUrl, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports' import { + ServerConfig, VideoCommentThreadTree, VideoDetails, VideoImport, @@ -46,7 +46,7 @@ import { VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy -} from '../../../shared/models/videos' +} from '@shared/models' const expect = chai.expect @@ -486,8 +486,10 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.search.videos.local.list.{params,result}', async function () { - await advancedVideosSearch(servers[0].url, { - search: 'Sun Quan' + await servers[0].searchCommand.advancedVideoSearch({ + search: { + search: 'Sun Quan' + } }) await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) @@ -495,9 +497,11 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.search.videos.index.list.{params,result}', async function () { - await advancedVideosSearch(servers[0].url, { - search: 'Sun Quan', - searchTarget: 'search-index' + await servers[0].searchCommand.advancedVideoSearch({ + search: { + search: 'Sun Quan', + searchTarget: 'search-index' + } }) await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) @@ -507,8 +511,10 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () { - await advancedVideoChannelSearch(servers[0].url, { - search: 'Sun Ce' + await servers[0].searchCommand.advancedChannelSearch({ + search: { + search: 'Sun Ce' + } }) await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) @@ -516,9 +522,11 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () { - await advancedVideoChannelSearch(servers[0].url, { - search: 'Sun Ce', - searchTarget: 'search-index' + await servers[0].searchCommand.advancedChannelSearch({ + search: { + search: 'Sun Ce', + searchTarget: 'search-index' + } }) await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) @@ -528,8 +536,10 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () { - await advancedVideoPlaylistSearch(servers[0].url, { - search: 'Sun Jian' + await servers[0].searchCommand.advancedPlaylistSearch({ + search: { + search: 'Sun Jian' + } }) await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) @@ -537,9 +547,11 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () { - await advancedVideoPlaylistSearch(servers[0].url, { - search: 'Sun Jian', - searchTarget: 'search-index' + await servers[0].searchCommand.advancedPlaylistSearch({ + search: { + search: 'Sun Jian', + searchTarget: 'search-index' + } }) await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) -- cgit v1.2.3