From fa47956ecf51a6d5d10aeb25d2e4db3da90c7d58 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 28 Jul 2021 10:32:40 +0200 Subject: Filter host for channels and playlists search --- server/tests/api/search/search-channels.ts | 58 +++++++++++++++++++++++++++-- server/tests/api/search/search-playlists.ts | 58 +++++++++++++++++++++++------ 2 files changed, 101 insertions(+), 15 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts index 4da2d0ece..d3b0f4321 100644 --- a/server/tests/api/search/search-channels.ts +++ b/server/tests/api/search/search-channels.ts @@ -2,24 +2,33 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils' +import { + cleanupTests, + createSingleServer, + doubleFollow, + PeerTubeServer, + SearchCommand, + setAccessTokensToServers +} from '@shared/extra-utils' import { VideoChannel } from '@shared/models' const expect = chai.expect describe('Test channels search', function () { - let server: PeerTubeServer = null + let server: PeerTubeServer + let remoteServer: PeerTubeServer let command: SearchCommand before(async function () { this.timeout(30000) server = await createSingleServer(1) + remoteServer = await createSingleServer(2, { transcoding: { enabled: false } }) - await setAccessTokensToServers([ server ]) + await setAccessTokensToServers([ server, remoteServer ]) { - await server.users.create({ username: 'user1', password: 'password' }) + await server.users.create({ username: 'user1' }) const channel = { name: 'squall_channel', displayName: 'Squall channel' @@ -27,6 +36,19 @@ describe('Test channels search', function () { await server.channels.create({ attributes: channel }) } + { + await remoteServer.users.create({ username: 'user1' }) + const channel = { + name: 'zell_channel', + displayName: 'Zell channel' + } + const { id } = await remoteServer.channels.create({ attributes: channel }) + + await remoteServer.videos.upload({ attributes: { channelId: id } }) + } + + await doubleFollow(server, remoteServer) + command = server.search }) @@ -66,6 +88,34 @@ describe('Test channels search', function () { } }) + it('Should filter by host', async function () { + { + const search = { search: 'channel', host: remoteServer.host } + + const body = await command.advancedChannelSearch({ search }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].displayName).to.equal('Zell channel') + } + + { + const search = { search: 'Sq', host: server.host } + + const body = await command.advancedChannelSearch({ search }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].displayName).to.equal('Squall channel') + } + + { + const search = { search: 'Squall', host: 'example.com' } + + const body = await command.advancedChannelSearch({ search }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) + } + }) + after(async function () { await cleanupTests([ server ]) }) diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts index 22e9b8fca..c3b318f5b 100644 --- a/server/tests/api/search/search-playlists.ts +++ b/server/tests/api/search/search-playlists.ts @@ -5,6 +5,7 @@ import * as chai from 'chai' import { cleanupTests, createSingleServer, + doubleFollow, PeerTubeServer, SearchCommand, setAccessTokensToServers, @@ -15,20 +16,22 @@ import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect describe('Test playlists search', function () { - let server: PeerTubeServer = null + let server: PeerTubeServer + let remoteServer: PeerTubeServer let command: SearchCommand before(async function () { this.timeout(30000) server = await createSingleServer(1) + remoteServer = await createSingleServer(2, { transcoding: { enabled: false } }) - await setAccessTokensToServers([ server ]) - await setDefaultVideoChannel([ server ]) - - const videoId = (await server.videos.quickUpload({ name: 'video' })).uuid + await setAccessTokensToServers([ remoteServer, server ]) + await setDefaultVideoChannel([ remoteServer, server ]) { + const videoId = (await server.videos.upload()).uuid + const attributes = { displayName: 'Dr. Kenzo Tenma hospital videos', privacy: VideoPlaylistPrivacy.PUBLIC, @@ -40,14 +43,16 @@ describe('Test playlists search', function () { } { + const videoId = (await remoteServer.videos.upload()).uuid + const attributes = { - displayName: 'Johan & Anna Libert musics', + displayName: 'Johan & Anna Libert music videos', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: server.store.channel.id + videoChannelId: remoteServer.store.channel.id } - const created = await server.playlists.create({ attributes }) + const created = await remoteServer.playlists.create({ attributes }) - await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } }) + await remoteServer.playlists.addElement({ playlistId: created.id, attributes: { videoId } }) } { @@ -59,6 +64,8 @@ describe('Test playlists search', function () { await server.playlists.create({ attributes }) } + await doubleFollow(server, remoteServer) + command = server.search }) @@ -87,7 +94,7 @@ describe('Test playlists search', function () { { const search = { - search: 'Anna Livert', + search: 'Anna Livert music', start: 0, count: 1 } @@ -96,7 +103,36 @@ describe('Test playlists search', function () { expect(body.data).to.have.lengthOf(1) const playlist = body.data[0] - expect(playlist.displayName).to.equal('Johan & Anna Libert musics') + expect(playlist.displayName).to.equal('Johan & Anna Libert music videos') + } + }) + + it('Should filter by host', async function () { + { + const search = { search: 'tenma', host: server.host } + const body = await command.advancedPlaylistSearch({ search }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) + + const playlist = body.data[0] + expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos') + } + + { + const search = { search: 'Anna', host: 'example.com' } + const body = await command.advancedPlaylistSearch({ search }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) + } + + { + const search = { search: 'video', host: remoteServer.host } + const body = await command.advancedPlaylistSearch({ search }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) + + const playlist = body.data[0] + expect(playlist.displayName).to.equal('Johan & Anna Libert music videos') } }) -- cgit v1.2.3