From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: Introduce videos command --- .../search/search-activitypub-video-channels.ts | 37 ++++++++++--------- .../search/search-activitypub-video-playlists.ts | 9 +++-- .../tests/api/search/search-activitypub-videos.ts | 32 ++++++++--------- server/tests/api/search/search-index.ts | 4 +-- server/tests/api/search/search-playlists.ts | 9 +++-- server/tests/api/search/search-videos.ts | 42 +++++++++++----------- 6 files changed, 64 insertions(+), 69 deletions(-) (limited to 'server/tests/api/search') diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index bcc21381c..75794402d 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -5,12 +5,9 @@ import * as chai from 'chai' import { cleanupTests, flushAndRunMultipleServers, - getVideoChannelVideos, SearchCommand, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, wait, waitJobs } from '@shared/extra-utils' @@ -53,8 +50,9 @@ describe('Test ActivityPub video channels search', function () { const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel }) channelIdServer2 = created.id - const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 }) - videoServer2UUID = res.body.video.uuid + const attributes = { name: 'video 1 server 2', channelId: channelIdServer2 } + const { uuid } = await servers[1].videosCommand.upload({ token: userServer2Token, attributes }) + videoServer2UUID = uuid } await waitJobs(servers) @@ -149,16 +147,21 @@ describe('Test ActivityPub video channels search', function () { await waitJobs(servers) - const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:' + servers[1].port, 0, 5) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const { total, data } = await servers[0].videosCommand.listByChannel({ + token: null, + videoChannelName: 'channel1_server2@localhost:' + servers[1].port + }) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) }) it('Should list video channel videos of server 2 with token', async function () { - const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:' + servers[1].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ + videoChannelName: 'channel1_server2@localhost:' + servers[1].port + }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('video 1 server 2') + expect(total).to.equal(1) + expect(data[0].name).to.equal('video 1 server 2') }) it('Should update video channel of server 2, and refresh it on server 1', async function () { @@ -190,8 +193,8 @@ describe('Test ActivityPub video channels search', function () { it('Should update and add a video on server 2, and update it on server 1 after a search', async function () { this.timeout(60000) - await updateVideo(servers[1].url, userServer2Token, videoServer2UUID, { name: 'video 1 updated' }) - await uploadVideo(servers[1].url, userServer2Token, { name: 'video 2 server 2', channelId: channelIdServer2 }) + await servers[1].videosCommand.update({ token: userServer2Token, id: videoServer2UUID, attributes: { name: 'video 1 updated' } }) + await servers[1].videosCommand.upload({ token: userServer2Token, attributes: { name: 'video 2 server 2', channelId: channelIdServer2 } }) await waitJobs(servers) @@ -204,11 +207,11 @@ describe('Test ActivityPub video channels search', function () { await waitJobs(servers) const videoChannelName = 'channel1_server2@localhost:' + servers[1].port - const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, videoChannelName, 0, 5, '-createdAt') + const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName, sort: '-createdAt' }) - expect(res.body.total).to.equal(2) - expect(res.body.data[0].name).to.equal('video 2 server 2') - expect(res.body.data[1].name).to.equal('video 1 updated') + expect(total).to.equal(2) + expect(data[0].name).to.equal('video 2 server 2') + expect(data[1].name).to.equal('video 1 updated') }) it('Should delete video channel of server 2, and delete it on server 1', 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 cb7582d29..46105c12c 100644 --- a/server/tests/api/search/search-activitypub-video-playlists.ts +++ b/server/tests/api/search/search-activitypub-video-playlists.ts @@ -9,7 +9,6 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideoAndGetId, wait, waitJobs } from '@shared/extra-utils' @@ -34,8 +33,8 @@ describe('Test ActivityPub playlists search', function () { await setDefaultVideoChannel(servers) { - const video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid - const video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid + const video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).uuid + const video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).uuid const attributes = { displayName: 'playlist 1 on server 1', @@ -51,8 +50,8 @@ describe('Test ActivityPub playlists search', function () { } { - const videoId = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 1' })).uuid - video2Server2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2' })).uuid + const videoId = (await servers[1].videosCommand.quickUpload({ name: 'video 1' })).uuid + video2Server2 = (await servers[1].videosCommand.quickUpload({ name: 'video 2' })).uuid const attributes = { displayName: 'playlist 1 on server 2', diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index 403c84010..19b4d5ed8 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -5,17 +5,13 @@ import * as chai from 'chai' import { cleanupTests, flushAndRunMultipleServers, - getVideosList, - removeVideo, SearchCommand, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, - wait -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { VideoPrivacy } from '../../../../shared/models/videos' + wait, + waitJobs +} from '@shared/extra-utils' +import { VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -34,13 +30,13 @@ describe('Test ActivityPub videos search', function () { await setAccessTokensToServers(servers) { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 on server 1' }) - videoServer1UUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1 on server 1' } }) + videoServer1UUID = uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 on server 2' }) - videoServer2UUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 on server 2' } }) + videoServer2UUID = uuid } await waitJobs(servers) @@ -109,10 +105,10 @@ describe('Test ActivityPub videos search', function () { }) it('Should not list this remote video', async function () { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('video 1 on server 1') + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('video 1 on server 1') }) it('Should update video of server 2, and refresh it on server 1', async function () { @@ -131,7 +127,7 @@ describe('Test ActivityPub videos search', function () { privacy: VideoPrivacy.UNLISTED, channelId: videoChannelId } - await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes) + await servers[1].videosCommand.update({ id: videoServer2UUID, attributes }) await waitJobs(servers) // Expire video @@ -157,7 +153,7 @@ describe('Test ActivityPub videos search', function () { it('Should delete video of server 2, and delete it on server 1', async function () { this.timeout(120000) - await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID) + await servers[1].videosCommand.remove({ id: videoServer2UUID }) await waitJobs(servers) // Expire video diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index 306f84c3a..d5dc40f60 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' const expect = chai.expect @@ -20,7 +20,7 @@ describe('Test videos search', function () { await setAccessTokensToServers([ server ]) - await uploadVideo(server.url, server.accessToken, { name: localVideoName }) + await server.videosCommand.upload({ attributes: { name: localVideoName } }) command = server.searchCommand }) diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts index 517884503..2e4773ed6 100644 --- a/server/tests/api/search/search-playlists.ts +++ b/server/tests/api/search/search-playlists.ts @@ -2,16 +2,15 @@ import 'mocha' import * as chai from 'chai' -import { VideoPlaylistPrivacy } from '@shared/models' import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - uploadVideoAndGetId -} from '../../../../shared/extra-utils' + setDefaultVideoChannel +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect @@ -27,7 +26,7 @@ describe('Test playlists search', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - const videoId = (await uploadVideoAndGetId({ server: server, videoName: 'video' })).uuid + const videoId = (await server.videosCommand.quickUpload({ name: 'video' })).uuid { const attributes = { diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 66f5f3182..148499d5f 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -10,7 +10,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - uploadVideo, wait } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' @@ -41,50 +40,49 @@ describe('Test videos search', function () { nsfw: false, language: 'fr' } - await uploadVideo(server.url, server.accessToken, attributes1) + await server.videosCommand.upload({ attributes: attributes1 }) const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' } - await uploadVideo(server.url, server.accessToken, attributes2) + await server.videosCommand.upload({ attributes: attributes2 }) { const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined } - const res = await uploadVideo(server.url, server.accessToken, attributes3) - const videoId = res.body.video.id - videoUUID = res.body.video.uuid + const { id, uuid } = await server.videosCommand.upload({ attributes: attributes3 }) + videoUUID = uuid await server.captionsCommand.createVideoCaption({ language: 'en', - videoId, + videoId: id, fixture: 'subtitle-good2.vtt', mimeType: 'application/octet-stream' }) await server.captionsCommand.createVideoCaption({ language: 'aa', - videoId, + videoId: id, fixture: 'subtitle-good2.vtt', mimeType: 'application/octet-stream' }) } const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true } - await uploadVideo(server.url, server.accessToken, attributes4) + await server.videosCommand.upload({ attributes: attributes4 }) await wait(1000) startDate = new Date().toISOString() const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined } - await uploadVideo(server.url, server.accessToken, attributes5) + await server.videosCommand.upload({ attributes: attributes5 }) const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] } - await uploadVideo(server.url, server.accessToken, attributes6) + await server.videosCommand.upload({ attributes: attributes6 }) const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' } - await uploadVideo(server.url, server.accessToken, attributes7) + await server.videosCommand.upload({ attributes: attributes7 }) const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 } - await uploadVideo(server.url, server.accessToken, attributes8) + await server.videosCommand.upload({ attributes: attributes8 }) } { @@ -95,9 +93,9 @@ describe('Test videos search', function () { licence: 2, language: 'en' } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes: attributes }) - await uploadVideo(server.url, server.accessToken, { ...attributes, name: attributes.name + ' duplicate' }) + await server.videosCommand.upload({ attributes: { ...attributes, name: attributes.name + ' duplicate' } }) } { @@ -108,7 +106,7 @@ describe('Test videos search', function () { licence: 3, language: 'pl' } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes: attributes }) } { @@ -117,11 +115,11 @@ describe('Test videos search', function () { tags: [ 'aaaa', 'bbbb', 'cccc' ], category: 1 } - await uploadVideo(server.url, server.accessToken, attributes1) - await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) + await server.videosCommand.upload({ attributes: attributes1 }) + await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } }) - await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'cccc', 'dddd' ] }) - await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'eeee', 'ffff' ] }) + await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'cccc', 'dddd' ] } }) + await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'eeee', 'ffff' ] } }) } { @@ -129,8 +127,8 @@ describe('Test videos search', function () { name: 'aaaa 2', category: 1 } - await uploadVideo(server.url, server.accessToken, attributes1) - await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) + await server.videosCommand.upload({ attributes: attributes1 }) + await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } }) } command = server.searchCommand -- cgit v1.2.3