From 2760b454a761f6af3138b2fb5f34340772ab0d1e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 27 Oct 2021 14:37:04 +0200 Subject: Deprecate filter video query Introduce include and isLocal instead --- server/tests/api/check-params/index.ts | 2 +- .../api/check-params/videos-common-filters.ts | 203 +++++++++++ server/tests/api/check-params/videos-filter.ts | 114 ------ server/tests/api/videos/index.ts | 2 +- server/tests/api/videos/multiple-servers.ts | 6 +- server/tests/api/videos/single-server.ts | 13 - server/tests/api/videos/videos-common-filters.ts | 403 +++++++++++++++++++++ server/tests/api/videos/videos-filter.ts | 122 ------- 8 files changed, 611 insertions(+), 254 deletions(-) create mode 100644 server/tests/api/check-params/videos-common-filters.ts delete mode 100644 server/tests/api/check-params/videos-filter.ts create mode 100644 server/tests/api/videos/videos-common-filters.ts delete mode 100644 server/tests/api/videos/videos-filter.ts (limited to 'server/tests') diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index a14e4d3e0..0882f8176 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts @@ -27,6 +27,6 @@ import './video-comments' import './video-imports' import './video-playlists' import './videos' -import './videos-filter' +import './videos-common-filters' import './videos-history' import './videos-overviews' diff --git a/server/tests/api/check-params/videos-common-filters.ts b/server/tests/api/check-params/videos-common-filters.ts new file mode 100644 index 000000000..afe42b0d5 --- /dev/null +++ b/server/tests/api/check-params/videos-common-filters.ts @@ -0,0 +1,203 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import 'mocha' +import { + cleanupTests, + createSingleServer, + makeGetRequest, + PeerTubeServer, + setAccessTokensToServers, + setDefaultVideoChannel +} from '@shared/extra-utils' +import { HttpStatusCode, UserRole, VideoInclude } from '@shared/models' + +describe('Test video filters validators', function () { + let server: PeerTubeServer + let userAccessToken: string + let moderatorAccessToken: string + + // --------------------------------------------------------------- + + before(async function () { + this.timeout(30000) + + server = await createSingleServer(1) + + await setAccessTokensToServers([ server ]) + await setDefaultVideoChannel([ server ]) + + const user = { username: 'user1', password: 'my super password' } + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) + + const moderator = { username: 'moderator', password: 'my super password' } + await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) + + moderatorAccessToken = await server.login.getAccessToken(moderator) + }) + + describe('When setting a deprecated video filter', function () { + + async function testEndpoints (token: string, filter: string, expectedStatus: HttpStatusCode) { + const paths = [ + '/api/v1/video-channels/root_channel/videos', + '/api/v1/accounts/root/videos', + '/api/v1/videos', + '/api/v1/search/videos' + ] + + for (const path of paths) { + await makeGetRequest({ + url: server.url, + path, + token, + query: { + filter + }, + expectedStatus + }) + } + } + + it('Should fail with a bad filter', async function () { + await testEndpoints(server.accessToken, 'bad-filter', HttpStatusCode.BAD_REQUEST_400) + }) + + it('Should succeed with a good filter', async function () { + await testEndpoints(server.accessToken, 'local', HttpStatusCode.OK_200) + }) + + it('Should fail to list all-local/all with a simple user', async function () { + await testEndpoints(userAccessToken, 'all-local', HttpStatusCode.UNAUTHORIZED_401) + await testEndpoints(userAccessToken, 'all', HttpStatusCode.UNAUTHORIZED_401) + }) + + it('Should succeed to list all-local/all with a moderator', async function () { + await testEndpoints(moderatorAccessToken, 'all-local', HttpStatusCode.OK_200) + await testEndpoints(moderatorAccessToken, 'all', HttpStatusCode.OK_200) + }) + + it('Should succeed to list all-local/all with an admin', async function () { + await testEndpoints(server.accessToken, 'all-local', HttpStatusCode.OK_200) + await testEndpoints(server.accessToken, 'all', HttpStatusCode.OK_200) + }) + + // Because we cannot authenticate the user on the RSS endpoint + it('Should fail on the feeds endpoint with the all-local/all filter', async function () { + for (const filter of [ 'all', 'all-local' ]) { + await makeGetRequest({ + url: server.url, + path: '/feeds/videos.json', + expectedStatus: HttpStatusCode.UNAUTHORIZED_401, + query: { + filter + } + }) + } + }) + + it('Should succeed on the feeds endpoint with the local filter', async function () { + await makeGetRequest({ + url: server.url, + path: '/feeds/videos.json', + expectedStatus: HttpStatusCode.OK_200, + query: { + filter: 'local' + } + }) + }) + }) + + describe('When setting video filters', function () { + + const validIncludes = [ + VideoInclude.NONE, + VideoInclude.HIDDEN_PRIVACY, + VideoInclude.NOT_PUBLISHED_STATE | VideoInclude.BLACKLISTED + ] + + async function testEndpoints (options: { + token?: string + isLocal?: boolean + include?: VideoInclude + expectedStatus: HttpStatusCode + }) { + const paths = [ + '/api/v1/video-channels/root_channel/videos', + '/api/v1/accounts/root/videos', + '/api/v1/videos', + '/api/v1/search/videos' + ] + + for (const path of paths) { + await makeGetRequest({ + url: server.url, + path, + token: options.token || server.accessToken, + query: { + isLocal: options.isLocal, + include: options.include + }, + expectedStatus: options.expectedStatus + }) + } + } + + it('Should fail with a bad include', async function () { + await testEndpoints({ include: 'toto' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + }) + + it('Should succeed with a good include', async function () { + for (const include of validIncludes) { + await testEndpoints({ include, expectedStatus: HttpStatusCode.OK_200 }) + } + }) + + it('Should fail to include more videos with a simple user', async function () { + for (const include of validIncludes) { + await testEndpoints({ token: userAccessToken, include, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + } + }) + + it('Should succeed to list all local/all with a moderator', async function () { + for (const include of validIncludes) { + await testEndpoints({ token: moderatorAccessToken, include, expectedStatus: HttpStatusCode.OK_200 }) + } + }) + + it('Should succeed to list all local/all with an admin', async function () { + for (const include of validIncludes) { + await testEndpoints({ token: server.accessToken, include, expectedStatus: HttpStatusCode.OK_200 }) + } + }) + + // Because we cannot authenticate the user on the RSS endpoint + it('Should fail on the feeds endpoint with the all filter', async function () { + for (const include of [ VideoInclude.NOT_PUBLISHED_STATE ]) { + await makeGetRequest({ + url: server.url, + path: '/feeds/videos.json', + expectedStatus: HttpStatusCode.UNAUTHORIZED_401, + query: { + include + } + }) + } + }) + + it('Should succeed on the feeds endpoint with the local filter', async function () { + await makeGetRequest({ + url: server.url, + path: '/feeds/videos.json', + expectedStatus: HttpStatusCode.OK_200, + query: { + isLocal: true + } + }) + }) + }) + + after(async function () { + await cleanupTests([ server ]) + }) +}) diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts deleted file mode 100644 index d08570bbe..000000000 --- a/server/tests/api/check-params/videos-filter.ts +++ /dev/null @@ -1,114 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import 'mocha' -import { - cleanupTests, - createSingleServer, - makeGetRequest, - PeerTubeServer, - setAccessTokensToServers, - setDefaultVideoChannel -} from '@shared/extra-utils' -import { HttpStatusCode, UserRole } from '@shared/models' - -async function testEndpoints (server: PeerTubeServer, token: string, filter: string, expectedStatus: HttpStatusCode) { - const paths = [ - '/api/v1/video-channels/root_channel/videos', - '/api/v1/accounts/root/videos', - '/api/v1/videos', - '/api/v1/search/videos' - ] - - for (const path of paths) { - await makeGetRequest({ - url: server.url, - path, - token, - query: { - filter - }, - expectedStatus - }) - } -} - -describe('Test video filters validators', function () { - let server: PeerTubeServer - let userAccessToken: string - let moderatorAccessToken: string - - // --------------------------------------------------------------- - - before(async function () { - this.timeout(30000) - - server = await createSingleServer(1) - - await setAccessTokensToServers([ server ]) - await setDefaultVideoChannel([ server ]) - - const user = { username: 'user1', password: 'my super password' } - await server.users.create({ username: user.username, password: user.password }) - userAccessToken = await server.login.getAccessToken(user) - - const moderator = { username: 'moderator', password: 'my super password' } - await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) - - moderatorAccessToken = await server.login.getAccessToken(moderator) - }) - - describe('When setting a video filter', function () { - - it('Should fail with a bad filter', async function () { - await testEndpoints(server, server.accessToken, 'bad-filter', HttpStatusCode.BAD_REQUEST_400) - }) - - it('Should succeed with a good filter', async function () { - await testEndpoints(server, server.accessToken, 'local', HttpStatusCode.OK_200) - }) - - it('Should fail to list all-local/all with a simple user', async function () { - await testEndpoints(server, userAccessToken, 'all-local', HttpStatusCode.UNAUTHORIZED_401) - await testEndpoints(server, userAccessToken, 'all', HttpStatusCode.UNAUTHORIZED_401) - }) - - it('Should succeed to list all-local/all with a moderator', async function () { - await testEndpoints(server, moderatorAccessToken, 'all-local', HttpStatusCode.OK_200) - await testEndpoints(server, moderatorAccessToken, 'all', HttpStatusCode.OK_200) - }) - - it('Should succeed to list all-local/all with an admin', async function () { - await testEndpoints(server, server.accessToken, 'all-local', HttpStatusCode.OK_200) - await testEndpoints(server, server.accessToken, 'all', HttpStatusCode.OK_200) - }) - - // Because we cannot authenticate the user on the RSS endpoint - it('Should fail on the feeds endpoint with the all-local/all filter', async function () { - for (const filter of [ 'all', 'all-local' ]) { - await makeGetRequest({ - url: server.url, - path: '/feeds/videos.json', - expectedStatus: HttpStatusCode.UNAUTHORIZED_401, - query: { - filter - } - }) - } - }) - - it('Should succeed on the feeds endpoint with the local filter', async function () { - await makeGetRequest({ - url: server.url, - path: '/feeds/videos.json', - expectedStatus: HttpStatusCode.OK_200, - query: { - filter: 'local' - } - }) - }) - }) - - after(async function () { - await cleanupTests([ server ]) - }) -}) diff --git a/server/tests/api/videos/index.ts b/server/tests/api/videos/index.ts index 5c07f8926..c9c678e9d 100644 --- a/server/tests/api/videos/index.ts +++ b/server/tests/api/videos/index.ts @@ -15,7 +15,7 @@ import './video-playlist-thumbnails' import './video-privacy' import './video-schedule-update' import './video-transcoder' -import './videos-filter' +import './videos-common-filters' import './videos-history' import './videos-overview' import './videos-views-cleaner' diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index df9deb1e1..9c255c1c5 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -349,7 +349,7 @@ describe('Test multiple servers', function () { describe('It should list local videos', function () { it('Should list only local videos on server 1', async function () { - const { data, total } = await servers[0].videos.list({ filter: 'local' }) + const { data, total } = await servers[0].videos.list({ isLocal: true }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -358,7 +358,7 @@ describe('Test multiple servers', function () { }) it('Should list only local videos on server 2', async function () { - const { data, total } = await servers[1].videos.list({ filter: 'local' }) + const { data, total } = await servers[1].videos.list({ isLocal: true }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -367,7 +367,7 @@ describe('Test multiple servers', function () { }) it('Should list only local videos on server 3', async function () { - const { data, total } = await servers[2].videos.list({ filter: 'local' }) + const { data, total } = await servers[2].videos.list({ isLocal: true }) expect(total).to.equal(2) expect(data).to.be.an('array') diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index 29dac6ec1..a0e4a156c 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -354,19 +354,6 @@ describe('Test a single server', function () { await server.videos.update({ id: videoId, attributes }) }) - it('Should filter by tags and category', async function () { - { - const { data, total } = await server.videos.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] }) - expect(total).to.equal(1) - expect(data[0].name).to.equal('my super video updated') - } - - { - const { total } = await server.videos.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] }) - expect(total).to.equal(0) - } - }) - it('Should have the video updated', async function () { this.timeout(60000) diff --git a/server/tests/api/videos/videos-common-filters.ts b/server/tests/api/videos/videos-common-filters.ts new file mode 100644 index 000000000..eb2d2ab50 --- /dev/null +++ b/server/tests/api/videos/videos-common-filters.ts @@ -0,0 +1,403 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import 'mocha' +import { expect } from 'chai' +import { pick } from '@shared/core-utils' +import { + cleanupTests, + createMultipleServers, + doubleFollow, + makeGetRequest, + PeerTubeServer, + setAccessTokensToServers, + setDefaultVideoChannel, + waitJobs +} from '@shared/extra-utils' +import { HttpStatusCode, UserRole, Video, VideoInclude, VideoPrivacy } from '@shared/models' + +describe('Test videos filter', function () { + let servers: PeerTubeServer[] + let paths: string[] + let remotePaths: string[] + + // --------------------------------------------------------------- + + before(async function () { + this.timeout(160000) + + servers = await createMultipleServers(2) + + await setAccessTokensToServers(servers) + await setDefaultVideoChannel(servers) + + for (const server of servers) { + const moderator = { username: 'moderator', password: 'my super password' } + await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) + server['moderatorAccessToken'] = await server.login.getAccessToken(moderator) + + await server.videos.upload({ attributes: { name: 'public ' + server.serverNumber } }) + + { + const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED } + await server.videos.upload({ attributes }) + } + + { + const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE } + await server.videos.upload({ attributes }) + } + } + + await doubleFollow(servers[0], servers[1]) + + paths = [ + `/api/v1/video-channels/root_channel/videos`, + `/api/v1/accounts/root/videos`, + '/api/v1/videos', + '/api/v1/search/videos' + ] + + remotePaths = [ + `/api/v1/video-channels/root_channel@${servers[1].host}/videos`, + `/api/v1/accounts/root@${servers[1].host}/videos`, + '/api/v1/videos', + '/api/v1/search/videos' + ] + }) + + describe('Check deprecated videos filter', function () { + + async function getVideosNames (server: PeerTubeServer, token: string, filter: string, expectedStatus = HttpStatusCode.OK_200) { + const videosResults: Video[][] = [] + + for (const path of paths) { + const res = await makeGetRequest({ + url: server.url, + path, + token, + query: { + sort: 'createdAt', + filter + }, + expectedStatus + }) + + videosResults.push(res.body.data.map(v => v.name)) + } + + return videosResults + } + + it('Should display local videos', async function () { + for (const server of servers) { + const namesResults = await getVideosNames(server, server.accessToken, 'local') + for (const names of namesResults) { + expect(names).to.have.lengthOf(1) + expect(names[0]).to.equal('public ' + server.serverNumber) + } + } + }) + + it('Should display all local videos by the admin or the moderator', async function () { + for (const server of servers) { + for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { + + const namesResults = await getVideosNames(server, token, 'all-local') + for (const names of namesResults) { + expect(names).to.have.lengthOf(3) + + expect(names[0]).to.equal('public ' + server.serverNumber) + expect(names[1]).to.equal('unlisted ' + server.serverNumber) + expect(names[2]).to.equal('private ' + server.serverNumber) + } + } + } + }) + + it('Should display all videos by the admin or the moderator', async function () { + for (const server of servers) { + for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { + + const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames(server, token, 'all') + expect(channelVideos).to.have.lengthOf(3) + expect(accountVideos).to.have.lengthOf(3) + + expect(videos).to.have.lengthOf(5) + expect(searchVideos).to.have.lengthOf(5) + } + } + }) + }) + + describe('Check videos filters', function () { + + async function listVideos (options: { + server: PeerTubeServer + path: string + isLocal?: boolean + include?: VideoInclude + category?: number + tagsAllOf?: string[] + token?: string + expectedStatus?: HttpStatusCode + }) { + const res = await makeGetRequest({ + url: options.server.url, + path: options.path, + token: options.token ?? options.server.accessToken, + query: { + ...pick(options, [ 'isLocal', 'include', 'category', 'tagsAllOf' ]), + + sort: 'createdAt' + }, + expectedStatus: options.expectedStatus ?? HttpStatusCode.OK_200 + }) + + return res.body.data as Video[] + } + + async function getVideosNames (options: { + server: PeerTubeServer + isLocal?: boolean + include?: VideoInclude + token?: string + expectedStatus?: HttpStatusCode + }) { + const videosResults: string[][] = [] + + for (const path of paths) { + const videos = await listVideos({ ...options, path }) + + videosResults.push(videos.map(v => v.name)) + } + + return videosResults + } + + it('Should display local videos', async function () { + for (const server of servers) { + const namesResults = await getVideosNames({ server, isLocal: true }) + + for (const names of namesResults) { + expect(names).to.have.lengthOf(1) + expect(names[0]).to.equal('public ' + server.serverNumber) + } + } + }) + + it('Should display local videos with hidden privacy by the admin or the moderator', async function () { + for (const server of servers) { + for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { + + const namesResults = await getVideosNames({ + server, + token, + isLocal: true, + include: VideoInclude.HIDDEN_PRIVACY + }) + + for (const names of namesResults) { + expect(names).to.have.lengthOf(3) + + expect(names[0]).to.equal('public ' + server.serverNumber) + expect(names[1]).to.equal('unlisted ' + server.serverNumber) + expect(names[2]).to.equal('private ' + server.serverNumber) + } + } + } + }) + + it('Should display all videos by the admin or the moderator', async function () { + for (const server of servers) { + for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { + + const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames({ + server, + token, + include: VideoInclude.HIDDEN_PRIVACY + }) + + expect(channelVideos).to.have.lengthOf(3) + expect(accountVideos).to.have.lengthOf(3) + + expect(videos).to.have.lengthOf(5) + expect(searchVideos).to.have.lengthOf(5) + } + } + }) + + it('Should display only remote videos', async function () { + this.timeout(40000) + + await servers[1].videos.upload({ attributes: { name: 'remote video' } }) + + await waitJobs(servers) + + const finder = (videos: Video[]) => videos.find(v => v.name === 'remote video') + + for (const path of remotePaths) { + { + const videos = await listVideos({ server: servers[0], path }) + const video = finder(videos) + expect(video).to.exist + } + + { + const videos = await listVideos({ server: servers[0], path, isLocal: false }) + const video = finder(videos) + expect(video).to.exist + } + + { + const videos = await listVideos({ server: servers[0], path, isLocal: true }) + const video = finder(videos) + expect(video).to.not.exist + } + } + }) + + it('Should include not published videos', async function () { + await servers[0].config.enableLive({ allowReplay: false, transcoding: false }) + await servers[0].live.create({ fields: { name: 'live video', channelId: servers[0].store.channel.id, privacy: VideoPrivacy.PUBLIC } }) + + const finder = (videos: Video[]) => videos.find(v => v.name === 'live video') + + for (const path of paths) { + { + const videos = await listVideos({ server: servers[0], path }) + const video = finder(videos) + expect(video).to.not.exist + expect(videos[0].state).to.not.exist + expect(videos[0].waitTranscoding).to.not.exist + } + + { + const videos = await listVideos({ server: servers[0], path, include: VideoInclude.NOT_PUBLISHED_STATE }) + const video = finder(videos) + expect(video).to.exist + expect(video.state).to.exist + } + } + }) + + it('Should include blacklisted videos', async function () { + const { id } = await servers[0].videos.upload({ attributes: { name: 'blacklisted' } }) + + await servers[0].blacklist.add({ videoId: id }) + + const finder = (videos: Video[]) => videos.find(v => v.name === 'blacklisted') + + for (const path of paths) { + { + const videos = await listVideos({ server: servers[0], path }) + const video = finder(videos) + expect(video).to.not.exist + expect(videos[0].blacklisted).to.not.exist + } + + { + const videos = await listVideos({ server: servers[0], path, include: VideoInclude.BLACKLISTED }) + const video = finder(videos) + expect(video).to.exist + expect(video.blacklisted).to.be.true + } + } + }) + + it('Should include videos from muted account', async function () { + const finder = (videos: Video[]) => videos.find(v => v.name === 'remote video') + + await servers[0].blocklist.addToServerBlocklist({ account: 'root@' + servers[1].host }) + + for (const path of remotePaths) { + { + const videos = await listVideos({ server: servers[0], path }) + const video = finder(videos) + expect(video).to.not.exist + + // Some paths won't have videos + if (videos[0]) { + expect(videos[0].blockedOwner).to.not.exist + expect(videos[0].blockedServer).to.not.exist + } + } + + { + const videos = await listVideos({ server: servers[0], path, include: VideoInclude.BLOCKED_OWNER }) + + const video = finder(videos) + expect(video).to.exist + expect(video.blockedServer).to.be.false + expect(video.blockedOwner).to.be.true + } + } + + await servers[0].blocklist.removeFromServerBlocklist({ account: 'root@' + servers[1].host }) + }) + + it('Should include videos from muted server', async function () { + const finder = (videos: Video[]) => videos.find(v => v.name === 'remote video') + + await servers[0].blocklist.addToServerBlocklist({ server: servers[1].host }) + + for (const path of remotePaths) { + { + const videos = await listVideos({ server: servers[0], path }) + const video = finder(videos) + expect(video).to.not.exist + + // Some paths won't have videos + if (videos[0]) { + expect(videos[0].blockedOwner).to.not.exist + expect(videos[0].blockedServer).to.not.exist + } + } + + { + const videos = await listVideos({ server: servers[0], path, include: VideoInclude.BLOCKED_OWNER }) + const video = finder(videos) + expect(video).to.exist + expect(video.blockedServer).to.be.true + expect(video.blockedOwner).to.be.false + } + } + + await servers[0].blocklist.removeFromServerBlocklist({ server: servers[1].host }) + }) + + it('Should filter by tags and category', async function () { + await servers[0].videos.upload({ attributes: { name: 'tag filter', tags: [ 'tag1', 'tag2' ] } }) + await servers[0].videos.upload({ attributes: { name: 'tag filter with category', tags: [ 'tag3' ], category: 4 } }) + + for (const path of paths) { + { + + const videos = await listVideos({ server: servers[0], path, tagsAllOf: [ 'tag1', 'tag2' ] }) + expect(videos).to.have.lengthOf(1) + expect(videos[0].name).to.equal('tag filter') + + } + + { + const videos = await listVideos({ server: servers[0], path, tagsAllOf: [ 'tag1', 'tag3' ] }) + expect(videos).to.have.lengthOf(0) + } + + { + const { data, total } = await servers[0].videos.list({ tagsAllOf: [ 'tag3' ], categoryOneOf: [ 4 ] }) + expect(total).to.equal(1) + expect(data[0].name).to.equal('tag filter with category') + } + + { + const { total } = await servers[0].videos.list({ tagsAllOf: [ 'tag4' ], categoryOneOf: [ 4 ] }) + expect(total).to.equal(0) + } + } + }) + }) + + after(async function () { + await cleanupTests(servers) + }) +}) diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts deleted file mode 100644 index 2306807bf..000000000 --- a/server/tests/api/videos/videos-filter.ts +++ /dev/null @@ -1,122 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import 'mocha' -import { expect } from 'chai' -import { - cleanupTests, - createMultipleServers, - doubleFollow, - makeGetRequest, - PeerTubeServer, - setAccessTokensToServers -} from '@shared/extra-utils' -import { HttpStatusCode, UserRole, Video, VideoPrivacy } from '@shared/models' - -async function getVideosNames (server: PeerTubeServer, token: string, filter: string, expectedStatus = HttpStatusCode.OK_200) { - const paths = [ - '/api/v1/video-channels/root_channel/videos', - '/api/v1/accounts/root/videos', - '/api/v1/videos', - '/api/v1/search/videos' - ] - - const videosResults: Video[][] = [] - - for (const path of paths) { - const res = await makeGetRequest({ - url: server.url, - path, - token, - query: { - sort: 'createdAt', - filter - }, - expectedStatus - }) - - videosResults.push(res.body.data.map(v => v.name)) - } - - return videosResults -} - -describe('Test videos filter', function () { - let servers: PeerTubeServer[] - - // --------------------------------------------------------------- - - before(async function () { - this.timeout(160000) - - servers = await createMultipleServers(2) - - await setAccessTokensToServers(servers) - - for (const server of servers) { - const moderator = { username: 'moderator', password: 'my super password' } - await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) - server['moderatorAccessToken'] = await server.login.getAccessToken(moderator) - - await server.videos.upload({ attributes: { name: 'public ' + server.serverNumber } }) - - { - const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED } - await server.videos.upload({ attributes }) - } - - { - const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE } - await server.videos.upload({ attributes }) - } - } - - await doubleFollow(servers[0], servers[1]) - }) - - describe('Check videos filter', function () { - - it('Should display local videos', async function () { - for (const server of servers) { - const namesResults = await getVideosNames(server, server.accessToken, 'local') - for (const names of namesResults) { - expect(names).to.have.lengthOf(1) - expect(names[0]).to.equal('public ' + server.serverNumber) - } - } - }) - - it('Should display all local videos by the admin or the moderator', async function () { - for (const server of servers) { - for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { - - const namesResults = await getVideosNames(server, token, 'all-local') - for (const names of namesResults) { - expect(names).to.have.lengthOf(3) - - expect(names[0]).to.equal('public ' + server.serverNumber) - expect(names[1]).to.equal('unlisted ' + server.serverNumber) - expect(names[2]).to.equal('private ' + server.serverNumber) - } - } - } - }) - - it('Should display all videos by the admin or the moderator', async function () { - for (const server of servers) { - for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { - - const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames(server, token, 'all') - expect(channelVideos).to.have.lengthOf(3) - expect(accountVideos).to.have.lengthOf(3) - - expect(videos).to.have.lengthOf(5) - expect(searchVideos).to.have.lengthOf(5) - } - } - }) - }) - - after(async function () { - await cleanupTests(servers) - }) -}) -- cgit v1.2.3