From 370240824e2fb28b314255f6c23f5ea7d6b08625 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 19 Jan 2021 13:43:33 +0100 Subject: Allow users/visitors to search through an account's videos (#3589) * WIP: account search * add search to account view * add tests for account search --- server/controllers/api/accounts.ts | 3 ++- server/middlewares/validators/videos/videos.ts | 4 ++++ server/tests/api/users/users-multiple-servers.ts | 27 ++++++++++++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) (limited to 'server') diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index e807b4f44..e31924a94 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts @@ -175,7 +175,8 @@ async function listAccountVideos (req: express.Request, res: express.Response) { withFiles: false, accountId: account.id, user: res.locals.oauth ? res.locals.oauth.token.User : undefined, - countVideos + countVideos, + search: req.query.search }, 'filter:api.accounts.videos.list.params') const resultList = await Hooks.wrapPromiseFun( diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 8bc37b0ab..84e309bec 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -6,6 +6,7 @@ import { MVideoFullLight } from '@server/types/models' import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model' import { + exists, isBooleanValid, isDateValid, isFileFieldValid, @@ -444,6 +445,9 @@ const commonVideosFiltersValidator = [ .optional() .customSanitizer(toBooleanOrNull) .custom(isBooleanValid).withMessage('Should have a valid skip count boolean'), + query('search') + .optional() + .custom(exists).withMessage('Should have a valid search'), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking commons video filters query', { parameters: req.query }) diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 591ce4959..dcd03879b 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -34,7 +34,7 @@ describe('Test users with multiple servers', function () { let userAvatarFilename: string before(async function () { - this.timeout(120000) + this.timeout(120_000) servers = await flushAndRunMultipleServers(3) @@ -92,7 +92,7 @@ describe('Test users with multiple servers', function () { }) it('Should be able to update my description', async function () { - this.timeout(10000) + this.timeout(10_000) await updateMyUser({ url: servers[0].url, @@ -109,7 +109,7 @@ describe('Test users with multiple servers', function () { }) it('Should be able to update my avatar', async function () { - this.timeout(10000) + this.timeout(10_000) const fixture = 'avatar2.png' @@ -164,8 +164,27 @@ describe('Test users with multiple servers', function () { } }) + it('Should search through account videos', async function () { + this.timeout(10_000) + + const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' }) + + await waitJobs(servers) + + for (const server of servers) { + const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, { + search: 'Kami' + }) + + 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].uuid).to.equal(resVideo.body.video.uuid) + } + }) + it('Should remove the user', async function () { - this.timeout(10000) + this.timeout(10_000) for (const server of servers) { const resAccounts = await getAccountsList(server.url, '-createdAt') -- cgit v1.2.3